new MidiController(options:Object)
Connects a midicontroller with a range of listeners. Can also send commands Back
Midi Example on codepen:
codepen
The Midi class searches and Connects to a midicontroller with a range of listeners.
You can also send commands back. This is especially handy when you can control
lights or automatic faders on your MIDI Controller.
Here is a demo on Codepen, which was tested with 2 AKAI midicontrollers
The original implementation is on GitHub in a Gist.
Parameters:
Name | Type | Description |
---|---|---|
options:Object |
- Implements:
- Source:
Example
var midi1 = new MidiController();
midi1.addEventListener( 0, function(_arr) { console.log( " Midi received", _arr ) } ) ;
// button 0, returns [ 144, 0, 1 ]
// use debug for more information
midi.debug = true;
Methods
addEventListener(_target, _callback)
addEventListener, expect an array of three values, representing the state and value of your controller
Parameters:
Name | Type | Description |
---|---|---|
_target |
integer | the number of controller being pressed |
_callback |
function | the callback to be executed |
- Source:
Example
function doSomething(_arr ) {
console.log('pressed1', arr) // [ 144, 0, 1 ]
}
midicontroller.addEventListener(1, function() )
clear()
clears all the buttons (sets them to 0)
- Source:
Example
midi.clear()
removeEventListener(_target)
removeEventListener
Parameters:
Name | Type | Description |
---|---|---|
_target |
integer | the number of controller being pressed |
- Source:
Example
midi.removeEventListener(1)
send(commands)
send midi data back to the controller. To switch a light on, or to make it
change color. Theorettically you should be able to control motorized faders
too, but I haven't tested that. Lights is nice though.
try to send evertything in one blob and try not to do all kinds of little
updates, it'll crash your midi controller (it crashed mine)
Parameters:
Name | Type | Description |
---|---|---|
commands |
array | the sequence that needs execution |
- Source:
Example
// make button 0 yellow, if a video reports 'seeking'
testSource1.video.addEventListener('seeking', function() { midi1.send([ 0x90, 0, 6] );} )
// don't forget to switch it off again
testSource1.video.addEventListener('seeked', function() { midi1.send([ 0x90, 0, 5] );} )
// make button 8-11 and button 16-19 green (tested with an Akai APC Mini)
midi1.send([ 0x90, 8, 1, 0x90, 9, 1, 0x90, 10, 1, 0x90, 11, 1, 0x90, 16, 1, 0x90, 17, 1, 0x90, 18, 1, 0x90, 19, 1])