├── .babelrc ├── .eslintrc ├── .gitignore ├── .npmignore ├── History.txt ├── README.md ├── circle.yml ├── package.json ├── samples ├── node │ └── sample.js └── webmidi │ ├── README.md │ ├── dist │ └── .gitkeep │ ├── index.html │ └── src │ └── main.js ├── src ├── device.es6 ├── devices │ ├── nanoKONTROL.es6 │ └── nanoKONTROL2.es6 ├── korg-nano-kontrol.es6 └── util.es6 └── test ├── test_helper.es6 └── test_korg-nano-kontrol.es6 /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ "es2015" ] 3 | } -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint:recommended", 3 | "parser": "babel-eslint", 4 | "env":{ 5 | "node": true, 6 | "browser": true 7 | }, 8 | "plugins": [ 9 | "if-in-test" 10 | ], 11 | "rules":{ 12 | "strict": [2, "global"], 13 | "new-cap": 0, 14 | "comma-spacing": [2, {"before": false, "after": true}], 15 | "no-unused-vars": [1, {"args": "none"}], 16 | "no-constant-condition": 0, 17 | "no-shadow": 0, 18 | "no-loop-func": 0, 19 | "curly": 0, 20 | "no-constant-condition": 1, 21 | "no-console": 1, 22 | "if-in-test/if": [1, {"directory": "test"}] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *#* 3 | .DS_Store 4 | node_modules 5 | *.log 6 | tmp 7 | lib 8 | samples/webmidi/dist/bundle.js -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src/ 2 | samples/ 3 | .babelrc 4 | .eslintrc 5 | circle.yml 6 | -------------------------------------------------------------------------------- /History.txt: -------------------------------------------------------------------------------- 1 | === 0.2.9 2016-01-26 2 | 3 | * bugfixed connecting from multiple devices #10 4 | * thank you for contributing @sashimizakana 5 | 6 | === 0.2.8 2016-01-25 7 | 8 | * use module.exports to provide "connect" function, instead of ES6 export 9 | 10 | === 0.2.7 2016-01-25 11 | 12 | * specify version devDependencies #8 13 | 14 | === 0.2.6 2015-06-26 15 | 16 | * use iterator in webmidi 17 | * module.exports -> export default 18 | 19 | === 0.2.5 2015-06-23 20 | 21 | * fixed WebMIDI init sequence, and sample code 22 | 23 | === 0.2.4 2015-06-21 24 | 25 | * WebMIDI: convert Uint8Array -> Array 26 | * fixed webmidi sample 27 | * use spread operator instead of Array.concat 28 | 29 | === 0.2.3 2015-06-20 30 | 31 | * added constructor "globalMidiChannel" option #6 32 | 33 | === 0.2.2 2015-06-14 34 | 35 | * bugfix for Node.js 0.10 36 | 37 | === 0.2.1 2015-06-13 38 | 39 | * bugfix device detection 40 | 41 | === 0.2.0 2015-06-13 42 | 43 | * rewrite coffee-script with ES6/babel 44 | 45 | === 0.1.2 2015-06-12 46 | 47 | * bugfix nanoKONTROL1 on browser 48 | 49 | === 0.1.1 2015-06-12 50 | 51 | * update package.json 52 | 53 | === 0.1.0 2015-06-11 54 | 55 | * support WebMIDI API #2 56 | 57 | === 0.0.3 2015-06-11 58 | 59 | * specify device name by "device.connect(name)" #1 60 | 61 | === 0.0.2 2015-06-11 62 | 63 | * add method device.close() #3 64 | 65 | === 0.0.1 2015-06-11 66 | 67 | * first release 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # korg-nano-kontrol 2 | Node.js/Browser library for KORG [nanoKONTROL](http://www.amazon.co.jp/dp/B001H2P294/shokai-22) and [nanoKONTROL2](http://www.amazon.co.jp/dp/B004M8UZS8/shokai-22). 3 | 4 | - https://github.com/shokai/korg-nano-kontrol 5 | - https://npmjs.com/package/korg-nano-kontrol 6 | 7 | [![Circle CI](https://circleci.com/gh/shokai/korg-nano-kontrol.svg?style=svg)](https://circleci.com/gh/shokai/korg-nano-kontrol) 8 | 9 | 10 | ## Install 11 | 12 | % npm install korg-nano-kontrol -save 13 | 14 | - On Node.js, This library depends on [midi npm](https://www.npmjs.com/package/midi) to handle MIDI messages. Please install ALSA libs after run npm install. 15 | - On Browser, require [WebMIDI API](http://www.w3.org/TR/webmidi/) support. 16 | 17 | ## Samples 18 | - [Node.js](https://github.com/shokai/korg-nano-kontrol/tree/master/samples/node) 19 | - [WebMIDI](https://github.com/shokai/korg-nano-kontrol/tree/master/samples/webmidi) 20 | - [Hue controller](https://github.com/shokai/hue-korg-control) 21 | 22 | ## Usage 23 | 24 | ### Connect 25 | 26 | find `nanoKONTROL` or `nanoKONTROL2` 27 | ```javascript 28 | var nanoKONTROL = require('korg-nano-kontrol'); 29 | 30 | nanoKONTROL.connect() 31 | .then(function(device){ 32 | console.log('connected!' + device.name); 33 | // do something 34 | }) 35 | .catch(function(err){ 36 | console.error(err); 37 | }); 38 | ``` 39 | 40 | specify device name 41 | ```javascript 42 | nanoKONTROL.connect('nanoKONTROL2').then( function(device){ } ); 43 | ``` 44 | 45 | ### Register Events 46 | 47 | ```javascript 48 | // register specific slider/knob/button events 49 | device.on('slider:0', function(value){ 50 | console.log("slider:0 >>> "+value); 51 | }); 52 | 53 | device.on('knob:1', function(value){ 54 | console.log("knob:1 >>> "+value); 55 | }); 56 | 57 | device.on('button:play', function(value){ 58 | console.log("button:play >>> "+value); 59 | }); 60 | 61 | 62 | // catch all slider/knob/button events 63 | device.on('slider:*', function(value){ 64 | console.log(this.event+' => '+value); 65 | }); 66 | 67 | device.on('knob:*', function(value){ 68 | console.log(this.event+' => '+value); 69 | }); 70 | 71 | device.on('button:**', function(value){ 72 | console.log(this.event+' => '+value); 73 | }); 74 | ``` 75 | 76 | ### Close 77 | ```javascript 78 | device.close(); 79 | ``` 80 | 81 | ### Scene 82 | nanoKONTROL has a `scene` button 83 | 84 | ```javascript 85 | console.log(device.scene); // => return 1~4 86 | 87 | device.on('button:scene', function(scene){ 88 | console.log(scene); 89 | }); 90 | ``` 91 | 92 | ## Debug 93 | 94 | enable [debug npm](https://www.npmjs.com/package/debug) 95 | 96 | for node.js 97 | 98 | % export DEBUG="korg-nano-kontrol:*" 99 | 100 | for browser 101 | 102 | localStorage.debug = "korg-nano-kontrol:*"; 103 | 104 | ## Build 105 | 106 | % npm run build 107 | % npm run buildSample 108 | 109 | % npm run watch 110 | 111 | ## Test 112 | 113 | % npm install 114 | 115 | % npm test 116 | # or 117 | % npm run watch 118 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | node: 3 | version: 5.4 4 | test: 5 | override: 6 | - npm run test 7 | - npm run build 8 | - npm run buildSample 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "korg-nano-kontrol", 3 | "version": "0.2.9", 4 | "description": "Node.js/Browser library for KORG nanoKONTROL and nanoKONTROL2", 5 | "main": "lib/korg-nano-kontrol.js", 6 | "scripts": { 7 | "mocha": "mocha test/test_*.es6 --compilers js:babel-register", 8 | "eslint": "eslint src/*.es6 src/*/*.es6 test/*.es6", 9 | "test": "npm run eslint && npm run mocha", 10 | "build": "babel src/ --out-dir lib/ --source-maps inline", 11 | "watch": "parallelshell 'npm run build -- --watch' 'chokidar \"(src|test)/*.es6\" -c \"npm run eslint\"'", 12 | "buildSample": "browserify --debug samples/webmidi/src/main.js -o samples/webmidi/dist/bundle.js" 13 | }, 14 | "keywords": [ 15 | "midi", 16 | "korg", 17 | "nanoKONTROL" 18 | ], 19 | "author": "Sho Hashimoto ", 20 | "license": "MIT", 21 | "devDependencies": { 22 | "babel": "^6.3.26", 23 | "babel-cli": "^6.4.5", 24 | "babel-eslint": "^4.1.6", 25 | "babel-preset-es2015": "^6.3.13", 26 | "browserify": "^13.0.0", 27 | "chai": "^3.4.1", 28 | "chokidar-cli": "^1.2.0", 29 | "eslint": "^1.10.3", 30 | "eslint-plugin-if-in-test": "^0.1.2", 31 | "jquery": "*", 32 | "mocha": "^2.3.4", 33 | "parallelshell": "^2.0.0" 34 | }, 35 | "dependencies": { 36 | "debug": "*", 37 | "es6-promise": "*", 38 | "eventemitter2": "*", 39 | "lodash": "^4.0.0", 40 | "midi": "*" 41 | }, 42 | "repository": { 43 | "type": "git", 44 | "url": "git+https://github.com/shokai/korg-nano-kontrol.git" 45 | }, 46 | "bugs": { 47 | "url": "https://github.com/shokai/korg-nano-kontrol/issues" 48 | }, 49 | "homepage": "https://github.com/shokai/korg-nano-kontrol#readme" 50 | } 51 | -------------------------------------------------------------------------------- /samples/node/sample.js: -------------------------------------------------------------------------------- 1 | var nanoKONTROL = require("../../"); 2 | // var nanoKONTROL = require('korg-nano-kontrol'); 3 | 4 | nanoKONTROL.connect() 5 | .then(function(device){ 6 | console.log('connected! ' + device.name); 7 | 8 | // register specific slider/knob/button event 9 | device.on('slider:0', function(value){ 10 | console.log("slider:0 >>> "+value); 11 | }); 12 | 13 | device.on('knob:1', function(value){ 14 | console.log("knob:1 >>> "+value); 15 | }); 16 | 17 | device.on('button:play', function(value){ 18 | console.log("button:play >>> "+value); 19 | }); 20 | 21 | device.on('button:stop', function(value){ 22 | console.log("button:stop >>> "+value); 23 | if(value === false){ 24 | console.log('exit!!'); 25 | device.close(); 26 | } 27 | }); 28 | 29 | 30 | // catch all slider/knob/button event 31 | device.on('slider:*', function(value){ 32 | console.log(this.event+' => '+value); 33 | }); 34 | 35 | device.on('knob:*', function(value){ 36 | console.log(this.event+' => '+value); 37 | }); 38 | 39 | device.on('button:**', function(value){ 40 | console.log(this.event+' => '+value); 41 | }); 42 | 43 | }) 44 | .catch(function(err){ 45 | console.error(err); 46 | }); 47 | -------------------------------------------------------------------------------- /samples/webmidi/README.md: -------------------------------------------------------------------------------- 1 | # build js 2 | 3 | % npm run buildSample 4 | 5 | # open 6 | 7 | open `index.html` with Chrome 8 | -------------------------------------------------------------------------------- /samples/webmidi/dist/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shokai/korg-nano-kontrol/8b4eda265088bb7eb6880cd550b0837a2db81e8b/samples/webmidi/dist/.gitkeep -------------------------------------------------------------------------------- /samples/webmidi/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | korg-nano-kontrol 4 | 5 | 6 |

korg-nano-kontrol

7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /samples/webmidi/src/main.js: -------------------------------------------------------------------------------- 1 | localStorage.debug = 'korg-nano-kontrol*'; 2 | 3 | // var nanoKONTROL = require('korg-nano-kontrol'); 4 | var nanoKONTROL = require('../../../'); 5 | var $ = require('jquery'); 6 | 7 | nanoKONTROL.connect() 8 | .then(function(device){ 9 | print('connect! ' + device.name); 10 | 11 | device.on('slider:*', function(value){ 12 | print(this.event + ' => ' + value); 13 | }); 14 | 15 | device.on('knob:*', function(value){ 16 | print(this.event + ' => ' + value); 17 | }); 18 | 19 | device.on('button:**', function(value){ 20 | print(this.event + ' => ' + value); 21 | }); 22 | }) 23 | .catch(function(err){ 24 | console.error(err); 25 | alert(err); 26 | }); 27 | 28 | var print = function(msg){ 29 | $('#log').prepend($('
  • ').text(msg)); 30 | }; 31 | -------------------------------------------------------------------------------- /src/device.es6: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | import {EventEmitter2} from "eventemitter2"; 4 | import {getEnv} from "./util"; 5 | 6 | export default class Device extends EventEmitter2 { 7 | 8 | constructor(input, name, opts = {globalMidiChannel: false}){ 9 | super({ 10 | wildcard: true, 11 | delimiter: ":" 12 | }); 13 | this.input = input; 14 | this.name = name; 15 | this.opts = opts; 16 | 17 | this.codes = {}; 18 | this.default = { 19 | type: "analog" 20 | }; 21 | 22 | switch(getEnv()){ 23 | case "browser": 24 | this.input.onmidimessage = (msg) => { 25 | this.emit("midi:message", Array.prototype.slice.call(msg.data)); 26 | }; 27 | break; 28 | case "nodejs": 29 | this.input.on("message", (deltaTime, msg) => { 30 | this.emit("midi:message", msg); 31 | }); 32 | break; 33 | } 34 | 35 | this.on("midi:message", (msg) => { 36 | this.debug(msg); 37 | const e = this.codes[opts.globalMidiChannel ? `${msg[0]},${msg[1]}` : msg[1]]; 38 | if(!e){ return; } 39 | if(e.type === "digital"){ 40 | this.emit(e.name, msg[2] > 0); 41 | } 42 | else{ 43 | this.emit(e.name, msg[2]); 44 | } 45 | }); 46 | } 47 | 48 | close(){ 49 | this.debug("closePort"); 50 | this.input.closePort(); 51 | } 52 | 53 | register(code, opts){ 54 | Object.keys(this.default).forEach(key => { 55 | if(!opts.hasOwnProperty(key)){ 56 | opts[key] = this.default[key]; 57 | } 58 | }); 59 | if(code instanceof Array){ 60 | code = code.join(","); 61 | } 62 | this.codes[code] = opts; 63 | } 64 | 65 | button(code, name){ 66 | const opts = { 67 | name: `button:${name}`, 68 | type: "digital" 69 | }; 70 | this.register(code, opts); 71 | } 72 | 73 | knob(code, name){ 74 | const opts = {name: `knob:${name}`}; 75 | this.register(code, opts); 76 | } 77 | 78 | slider(code, name){ 79 | const opts = {name: `slider:${name}`}; 80 | this.register(code, opts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/devices/nanoKONTROL.es6: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | import _ from "lodash"; 4 | 5 | import Debug from "debug"; 6 | import Device from "../device"; 7 | import {eachWithIndex, getEnv} from "../util"; 8 | 9 | export default class NanoKONTROL extends Device { 10 | 11 | static get deviceName(){ 12 | return "nanoKONTROL"; 13 | } 14 | static detect(name){ 15 | return /^nanoKONTROL\s/i.test(name); 16 | } 17 | 18 | constructor(input, name){ 19 | super(input, name, {globalMidiChannel: true}); 20 | this.debug = Debug("korg-nano-kontrol:nanoKONTROL"); 21 | this.debug("created"); 22 | 23 | if(getEnv() === "nodejs"){ 24 | this.input.ignoreTypes(false, false, true); 25 | } 26 | this.setScene(1); 27 | 28 | this.on("midi:message", msg => { 29 | if(msg.length === 11 && 30 | msg[0] === 240 && 31 | msg[10] === 247){ 32 | this.setScene(msg[9] + 1); 33 | this.emit("button:scene", msg[9] + 1); 34 | } 35 | }); 36 | 37 | this.button([176, 44], "rec"); 38 | this.button([176, 45], "play"); 39 | this.button([176, 46], "stop"); 40 | this.button([176, 47], "prev"); 41 | this.button([176, 48], "next"); 42 | this.button([176, 49], "loop"); 43 | } 44 | 45 | setScene(scene){ 46 | this.scene = scene; 47 | switch(scene){ 48 | case 1: 49 | eachWithIndex( 50 | [..._.range(2, 7), 8, 9, 12, 13] 51 | , (index, code) => { 52 | this.slider([176, code], index); 53 | } 54 | ); 55 | eachWithIndex( 56 | _.range(14, 23) 57 | , (index, code) => { 58 | this.knob([176, code], index); 59 | } 60 | ); 61 | eachWithIndex( 62 | _.range(23, 32) 63 | , (index, code) => { 64 | this.button([176, code], `a:${index}`); 65 | } 66 | ); 67 | eachWithIndex( 68 | _.range(33, 42) 69 | , (index, code) => { 70 | this.button([176, code], `b:${index}`); 71 | } 72 | ); 73 | break; 74 | case 2: 75 | eachWithIndex( 76 | [42, 43, ..._.range(50, 57)] 77 | , (index, code) => { 78 | this.slider([176, code], index); 79 | } 80 | ); 81 | eachWithIndex( 82 | [..._.range(57, 64), 65, 66] 83 | , (index, code) => { 84 | this.knob([176, code], index); 85 | } 86 | ); 87 | eachWithIndex( 88 | _.range(67, 76) 89 | , (index, code) => { 90 | this.button([176, code], `a:${index}`); 91 | } 92 | ); 93 | eachWithIndex( 94 | _.range(76, 85) 95 | , (index, code) => { 96 | this.button([176, code], `b:${index}`); 97 | } 98 | ); 99 | break; 100 | case 3: 101 | eachWithIndex( 102 | _.range(85, 94) 103 | , (index, code) => { 104 | this.slider([176, code], index); 105 | } 106 | ); 107 | eachWithIndex( 108 | [..._.range(94, 98), ..._.range(102, 107)] 109 | , (index, code) => { 110 | this.knob([176, code], index); 111 | } 112 | ); 113 | eachWithIndex( 114 | _.range(107, 116) 115 | , (index, code) => { 116 | this.button([176, code], `a:${index}`); 117 | } 118 | ); 119 | eachWithIndex( 120 | _.range(116, 125) 121 | , (index, code) => { 122 | this.button([176, code], `b:${index}`); 123 | } 124 | ); 125 | break; 126 | case 4: 127 | eachWithIndex( 128 | _.range(176, 185) 129 | , (index, code) => { 130 | this.slider([code, 7], index); 131 | } 132 | ); 133 | eachWithIndex( 134 | _.range(176, 185) 135 | , (index, code) => { 136 | this.knob([code, 10], index); 137 | } 138 | ); 139 | eachWithIndex( 140 | _.range(176, 185) 141 | , (index, code) => { 142 | this.button([code, 16], `a:${index}`); 143 | } 144 | ); 145 | eachWithIndex( 146 | _.range(176, 185) 147 | , (index, code) => { 148 | this.button([code, 17], `b:${index}`); 149 | } 150 | ); 151 | break; 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/devices/nanoKONTROL2.es6: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | import _ from "lodash"; 4 | 5 | import Debug from "debug"; 6 | import Device from "../device"; 7 | import {eachWithIndex} from "../util"; 8 | 9 | export default class NanoKONTROL2 extends Device { 10 | 11 | static get deviceName(){ 12 | return "nanoKONTROL2"; 13 | } 14 | static detect(name){ 15 | return /^nanoKONTROL2\s/i.test(name); 16 | } 17 | 18 | constructor(input, name){ 19 | super(input, name); 20 | this.debug = Debug("korg-nano-kontrol:nanoKONTROL2"); 21 | this.debug("created"); 22 | 23 | eachWithIndex(_.range(0, 8), (index, code) => { 24 | this.slider(code, index); 25 | }); 26 | 27 | eachWithIndex(_.range(16, 24), (index, code) => { 28 | this.knob(code, index); 29 | }); 30 | 31 | eachWithIndex(_.range(32, 40), (index, code) => { 32 | this.button(code, `s:${index}`); 33 | }); 34 | 35 | eachWithIndex(_.range(48, 56), (index, code) => { 36 | this.button(code, `m:${index}`); 37 | }); 38 | 39 | eachWithIndex(_.range(64, 72), (index, code) => { 40 | this.button(code, `r:${index}`); 41 | }); 42 | 43 | this.button(41, "play"); 44 | this.button(42, "stop"); 45 | this.button(43, "prev"); 46 | this.button(44, "next"); 47 | this.button(45, "rec"); 48 | this.button(46, "cycle"); 49 | this.button(60, "marker:set"); 50 | this.button(61, "marker:prev"); 51 | this.button(62, "marker:next"); 52 | this.button(58, "track:prev"); 53 | this.button(59, "track:next"); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/korg-nano-kontrol.es6: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | import {Promise} from "es6-promise"; 4 | const debug = require("debug")("korg-nano-kontrol"); 5 | 6 | import {getEnv} from "./util"; 7 | 8 | import nanoKONTROL from "./devices/nanoKONTROL"; 9 | import nanoKONTROL2 from "./devices/nanoKONTROL2"; 10 | 11 | const Devices = [ 12 | nanoKONTROL, 13 | nanoKONTROL2 14 | ]; 15 | 16 | module.exports.connect = function(deviceName){ 17 | switch(getEnv()){ 18 | case "browser": 19 | return connectWebMidi(deviceName); 20 | case "nodejs": 21 | return connectNodeMidi(deviceName); 22 | } 23 | } 24 | 25 | function connectWebMidi(deviceName){ 26 | debug(`connectWebMidi(${deviceName})`); 27 | return new Promise((resolve, reject) => { 28 | if(navigator && typeof navigator.requestMIDIAccess !== "function"){ 29 | return reject(new Error("Web MIDI API is not supported")); 30 | } 31 | const devices = Devices.filter((i) => { 32 | return !deviceName || i.deviceName === deviceName; 33 | }); 34 | navigator.requestMIDIAccess() 35 | .then(webMidi => { 36 | for(let input of webMidi.inputs.values()){ 37 | for(let Device of devices){ 38 | if(Device.detect(input.name)){ 39 | debug(`detect ${Device.name}`); 40 | return resolve(new Device(input, input.name)); 41 | } 42 | } 43 | } 44 | return reject("device not found"); 45 | }); 46 | }); 47 | } 48 | 49 | function connectNodeMidi(deviceName){ 50 | const midi = require("midi"); 51 | debug(`connectNodeMidi(${deviceName})`); 52 | return new Promise((resolve, reject) => { 53 | const input = new midi.input(); 54 | const devices = Devices.filter(function(device){ 55 | return !deviceName || device.deviceName === deviceName; 56 | }); 57 | 58 | for(let i = 0; i < input.getPortCount(); i++){ 59 | let name = input.getPortName(i); 60 | debug(`found device [${i}] "${name}"`); 61 | 62 | for(let Device of devices){ 63 | if(Device.detect(name)){ 64 | debug(`detect "${Device.name}"`); 65 | debug(`openPort ${i}`); 66 | input.openPort(i); 67 | return resolve(new Device(input, name)); 68 | } 69 | } 70 | } 71 | return reject("device not found"); 72 | }); 73 | } 74 | -------------------------------------------------------------------------------- /src/util.es6: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | export function toArray(obj){ 4 | return Array.prototype.splice.call(obj, 0); 5 | } 6 | 7 | export function getEnv(){ 8 | if(typeof window === "object"){ 9 | return "browser"; 10 | } 11 | else{ 12 | return "nodejs"; 13 | } 14 | } 15 | 16 | export function eachWithIndex(arr, iter){ 17 | if(!(arr instanceof Array)){ return; } 18 | if(typeof iter !== "function"){ return; } 19 | for(let i = 0; i < arr.length; i++){ 20 | iter(i, arr[i]); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/test_helper.es6: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | process.env.NODE_ENV = "test"; 4 | -------------------------------------------------------------------------------- /test/test_korg-nano-kontrol.es6: -------------------------------------------------------------------------------- 1 | /* global describe it */ 2 | "use strict"; 3 | 4 | import "./test_helper"; 5 | import {assert} from "chai"; 6 | import nanoKONTROL from "../src/korg-nano-kontrol"; 7 | 8 | describe("korg-nano-kontrol", function(){ 9 | 10 | it("should have method \"connect\"", function(){ 11 | assert.isFunction(nanoKONTROL.connect); 12 | }) 13 | 14 | }); 15 | --------------------------------------------------------------------------------