Adding show scale method to interact with lighted keyboards

This commit is contained in:
2023-10-12 01:23:16 +03:00
parent 6b8d1b4608
commit 9c0f231bdc
5 changed files with 142 additions and 7 deletions

View File

@ -31,7 +31,7 @@ export class MidiConnection {
private settings: AppSettings;
private midiAccess: MIDIAccess | null = null;
public midiOutputs: MIDIOutput[] = [];
private currentOutputIndex: number = 0;
public currentOutputIndex: number = 0;
private scheduledNotes: { [noteNumber: number]: number } = {}; // { noteNumber: timeoutId }
/* Midi input */
@ -625,6 +625,64 @@ export class MidiConnection {
}
}
public sendMidiOn(note: number, channel: number, velocity: number, port: number | string = this.currentOutputIndex) {
/**
* Sending Midi Note on message
*/
if(typeof port === "string") port = this.getMidiOutputIndex(port);
const output = this.midiOutputs[port];
note = Math.min(Math.max(note, 0), 127);
if (output) {
const noteOnMessage = [0x90 + channel, note, velocity];
output.send(noteOnMessage);
} else {
console.error("MIDI output not available.");
}
}
sendMidiOff(note: number, channel: number, port: number | string = this.currentOutputIndex) {
/**
* Sending Midi Note off message
*/
if(typeof port === "string") port = this.getMidiOutputIndex(port);
const output = this.midiOutputs[port];
note = Math.min(Math.max(note, 0), 127);
if (output) {
const noteOffMessage = [0x80 + channel, note, 0];
output.send(noteOffMessage);
} else {
console.error("MIDI output not available.");
}
}
sendAllNotesOff(channel: number, port: number | string = this.currentOutputIndex) {
/**
* Sending Midi Note off message
*/
if(typeof port === "string") port = this.getMidiOutputIndex(port);
const output = this.midiOutputs[port];
if (output) {
const noteOffMessage = [0xb0 + channel, 123, 0];
output.send(noteOffMessage);
} else {
console.error("MIDI output not available.");
}
}
sendAllSoundOff(channel: number, port: number | string = this.currentOutputIndex) {
/**
* Sending all sound off
*/
if(typeof port === "string") port = this.getMidiOutputIndex(port);
const output = this.midiOutputs[port];
if (output) {
const noteOffMessage = [0xb0 + channel, 120, 0];
output.send(noteOffMessage);
} else {
console.error("MIDI output not available.");
}
}
public sendSysExMessage(message: number[]): void {
/**
* Sends a SysEx message to the currently selected MIDI output.