Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async function enableMIDI() {
if (midi.enabled) {
return;
}
const midiEnabled = new PromiseDelegate();
midi.enable(function(err) {
if (err) {
midiEnabled.reject(err);
} else {
midiEnabled.resolve(undefined);
}
});
await midiEnabled.promise;
// if (!(midi.inputs[1] && midi.outputs[1])) {
// throw new Error("Could not find MIDI device");
// }
}
start(seconds_per_beat=1){
if (!WebMidi.enabled) {
Midi.init()
let the_note = this
setTimeout(function() { the_note.start(seconds_per_beat) }, 1000)
}
else if (WebMidi.outputs.length == 0) {
dde_error("There are no WebMidi outputs to play a Note on. <a href="#">Help</a>")
}
else if (this.is_rest()) { return this } //skip playing the "Rest" as it would error
else {
var extra_args = {duration: Math.round(this.dur * seconds_per_beat * 1000),
time: "+" + Math.round(this.time * seconds_per_beat * 1000),
velocity: this.velocity}
const pitch = this.pitch
const chan = this.channel
WebMidi.outputs[0].playNote(pitch, chan, extra_args)
return this
initialize(attributes: any, options: any) {
super.initialize(attributes, options);
if (!midi.enabled) {
throw new Error('WebMidi library not enabled');
}
const input = midi.inputs.findIndex(x => x.manufacturer === "Behringer" && x.name.startsWith("X-TOUCH MINI"));
if (input === -1) {
throw new Error("Could not find Behringer X-TOUCH MINI input");
}
const output = midi.outputs.findIndex(x => x.manufacturer === "Behringer" && x.name.startsWith("X-TOUCH MINI"));
if (output === -1) {
throw new Error("Could not find Behringer X-TOUCH MINI output");
}
this.set('_controller_input', input);
this.set('_controller_output', output);
webMidi.enable(err => {
setWebMidiEnabled(!err && webMidi.enabled);
});
}, []);