From 678fe90e66e3b00f3f0760dd6ad41af5072426a1 Mon Sep 17 00:00:00 2001 From: Bryton Hall Date: Tue, 11 Apr 2023 22:44:51 -0400 Subject: [PATCH] play a harpsichord sound on wrong notes --- src/app/services/midi.service.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/app/services/midi.service.ts b/src/app/services/midi.service.ts index af9e005..690f15e 100644 --- a/src/app/services/midi.service.ts +++ b/src/app/services/midi.service.ts @@ -77,6 +77,12 @@ export class MidiService { // wrong key pressed if (this.cursor.running && !this.notes.keys[name].required) { // this.feedback.addText('❌', 0, 20); + + // switch to different bank for audio feedback + this.output?.send([0xc0, 6]); + // play the same note + // TODO: replace input note instead of adding a new note + this.output?.send([0x90, pitch, velocity]); } this.onChange.emit(); @@ -85,8 +91,14 @@ export class MidiService { // input note released noteOff(time: number, pitch: number): void { - this.notes.release(pitch - MIDIOffset); + const name = pitch - MIDIOffset; + this.notes.release(name); this.onChange.emit(); + + // if this is an injected wrong note, release it + if (this.cursor.running && !this.notes.keys[name].required) { + this.output?.send([0x80, pitch, 0x40]); + } } pressNote(pitch: number, velocity: number): void {