Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
// Make sure we are in MCU protocol mode
midi.outputs[output].sendChannelMode(
127,
WebMidi.enable(function (err: any) {
if (err) {
alert("WebMidi could not be enabled.");
}
const output = WebMidi.outputs[0];
const input = WebMidi.inputs[0];
input.addListener('noteon', "all",
function (e: any) {
console.log("Received 'noteon' message (" + e.note.name + e.note.octave + ").");
output.playNote(`${e.note.name}${e.note.octave}`, 'all', { velocity: 1 });
synth.triggerAttack(`${e.note.name}${e.note.octave}`);
}
);
input.addListener('noteoff', "all",
function (e: any) {
console.log("Received 'noteoff' message (" + e.note.name + e.note.octave + ").");
output.playNote(`${e.note.name}${e.note.octave}`, 'all', { velocity: 0 });
synth.triggerRelease();
}
);
});
WebMidi.enable(function(err) {
if (err) { warning("WebMidi couldn't be enabled: " + err) }
else {
out("WedMidi enabled")
//out(WebMidi.inputs)
//out(WebMidi.outputs)
inspect({"WebMidi.inputs": WebMidi.inputs,
"WebMidi.outputs": WebMidi.outputs})
}
})
//eval_and_play_button_id.style.display = "inline-block"
WebMidi.enable((err) => {
if (!err){
this._isEnabled = true
this._magenta.instances().forEach((instance) => {
this._magenta.updatePort(WebMidi.getOutputByName(instance.portName()))
})
if (WebMidi.inputs){
WebMidi.inputs.forEach((input) => this._bindInput(input))
}
WebMidi.addListener('connected', (device) => {
if (device.input) {
this._bindInput(device.input)
}
if (device.output) {
this._magenta.updatePort(device.output)
}
})
}
})
}
WebMidi.enable((err) => {
if (!err){
this._isEnabled = true
if (WebMidi.inputs){
WebMidi.inputs.forEach((input) => this._bindInput(input))
}
WebMidi.addListener('connected', (device) => {
if (device.input){
this._bindInput(device.input)
}
})
}
})
}
WebMidi.enable((err) => {
if (!err){
this._isEnabled = true
if (WebMidi.inputs){
WebMidi.inputs.forEach((input) => this._bindInput(input))
}
WebMidi.addListener('connected', (device) => {
if (device.input){
this._bindInput(device.input)
}
})
}
})
}
const handleMidiDeviceChange = useCallback(() => {
setInputMidis(webMidi.inputs);
if (!webMidi.inputs.length) {
onMidiDeviceChange(null);
}
}, [webMidi]);
WebMidi.enable((err) => {
if (!err){
this._isEnabled = true
if (WebMidi.inputs){
WebMidi.inputs.forEach((input) => this._bindInput(input))
}
WebMidi.addListener('connected', (device) => {
if (device.input){
this._bindInput(device.input)
}
})
}
})
}
WebMidi.enable((err) => {
if (!err){
this._isEnabled = true
if (WebMidi.inputs){
WebMidi.inputs.forEach((input) => this._bindInput(input))
}
WebMidi.addListener('connected', (device) => {
if (device.input){
this._bindInput(device.input)
}
})
}
})
}
initialize(attributes: any, options: any) {
super.initialize(attributes, options);
if (!midi.enabled) {
throw new Error('WebMidi library not enabled');
}
const values = {...this.defaults(), ...attributes};
const input = midi.inputs[values._controller_input];
const output = midi.outputs[values._controller_output];
this._fader = new Fader({input, output}, values._control, {
min: values.min,
max: values.max,
value: values.value
});
this._fader.stateChanged.connect((sender, args) => {
switch (args.name) {
case 'value':
case 'min':
case 'max':
this.set(args.name, args.newValue);
break;
}
this.save_changes();
});