OnscreenKeyboard
Provides access to controllers managed by Cantabile's on-screen keyboard device
Access this object via the onscreenKeyboard property.
Table of Contents
Methods
close
()
Closes the end point and stops listening for events.
This method no longer needs to be explicitly called as end points are now automatically closed when the last event listener is removed.
injectMidi
-
data
Inject MIDI from the on-screen keyboard device
Parameters:
-
data
ObjectAn array of bytes or a MidiControllerEvent
Example:
Using a callback function:
// Send a note on event
C.onscreenKeyboard.inject([0x90, 64, 64]);
Using the MidiControllerEvent
// Send Midi CC 23 = 127
let watcher = C.onscreenKeyboard.inject({
channel: 0,
kind: "controller",
controller: 23,
value: 127,
});
open
()
Opens this end point and starts listening for events.
This method no longer needs to be explicitly called as end points are now automatically opened when the first event listener is attached.
Use this method to keep the end point open even when no event listeners are attached.
queryController
-
channel
-
kind
-
controller
Queries the on-screen keyboard for the current value of a controller
Parameters:
-
channel
NumberThe MIDI channel number of the controller
-
kind
StringThe MIDI controller kind
-
controller
NumberThe number of the controller
Returns:
A promise to provide the controller value
Example:
// Get the value of cc 64 on channel 1
let C = new CantabileApi();
console.log(await C.onscreenKeyboard.queryController(1, "controller", 64));
let C = new CantabileApi();
C.onscreenKeyboard.queryController(1, "controller", 64).then(r => console.log(r)));
untilOpen
()
Promise
Returns a promise that will be resolved when this end point is opened
Returns:
Example:
let C = new CantabileApi();
C.application.open();
await C.application.untilOpen();
Starts watching a controller for changes
Parameters:
-
channel
NumberThe MIDI channel number of the controller
-
kind
StringThe MIDI controller kind
-
controller
NumberThe number of the controller
-
[callback]
Function optionalOptional callback function to be called when the controller value changes.
The callback function has the form function(value, source) where value is the controller value and source is the ControllerWatcher instance.
Returns:
Example:
Using a callback function:
let C = new CantabileApi();
// Watch a controller using a callback function
C.onscreenKeyboard.watchController(1, "controller", 64, function(value) {
console.log(value);
})
// The "onscreenKeyboard" end point must be opened before callbacks will happen
C.onscreenKeyboard.open();
Using the ControllerWatcher class and events:
let C = new CantabileApi();
let watcher = C.onscreenKeyboard.watchController(1, "controller", 64);
watcher.on('changed', function(value) {
console.log(value);
});
// The "onscreenKeyboard" end point must be opened before callbacks will happen
C.onscreenKeyboard.open();
/// later, stop listening
watcher.unwatch();