Skip to content

Commit

Permalink
play a harpsichord sound on wrong notes
Browse files Browse the repository at this point in the history
  • Loading branch information
hall committed Apr 12, 2023
1 parent a2ae9a9 commit 678fe90
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/app/services/midi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand Down

0 comments on commit 678fe90

Please sign in to comment.