From a62f3006efeaa8ecb203fa08ac26c74c748129b7 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sat, 5 Aug 2023 21:30:30 +0200 Subject: [PATCH] Adding MIDI Program Change --- src/API.ts | 10 ++++++++++ src/IO/MidiConnection.ts | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/API.ts b/src/API.ts index f40765b..8a0d20c 100644 --- a/src/API.ts +++ b/src/API.ts @@ -231,6 +231,16 @@ export class UserAPI { this.MidiConnection.sendSysExMessage(data) } + public program_change(program: number, channel: number): void { + /** + * Sends a MIDI program change to the current MIDI output. + * + * @param program - The MIDI program to send + * @param channel - The MIDI channel to send the program change on + */ + this.MidiConnection.sendProgramChange(program, channel) + } + public midi_clock(): void { /** * Sends a MIDI clock to the current MIDI output. diff --git a/src/IO/MidiConnection.ts b/src/IO/MidiConnection.ts index d6c70dc..5109a3b 100644 --- a/src/IO/MidiConnection.ts +++ b/src/IO/MidiConnection.ts @@ -137,6 +137,27 @@ export class MidiConnection{ console.error('MIDI output not available.'); } } + + public sendProgramChange(programNumber: number, channel: number): void { + /** + * Sends a MIDI Program Change message to the currently selected MIDI output. + * + * @param programNumber MIDI program number (0-127) + * @param channel MIDI channel (0-15) + * + * @example + * // Send a Program Change message to select program 1 on channel 1 + * sendProgramChange(0, 0); + */ + const output = this.midiOutputs[this.currentOutputIndex]; + if (output) { + output.send([0xC0 + channel, programNumber]); // Program Change + } else { + console.error('MIDI output not available.'); + } + } + + public sendMidiControlChange(controlNumber: number, value: number): void { /**