From c9a576aa33016c09335ed810a7587a3ea4471e25 Mon Sep 17 00:00:00 2001 From: Bryton Hall Date: Fri, 31 Mar 2023 03:16:56 -0400 Subject: [PATCH] combine note statu update and cursor movement into midi event --- src/app/home/home.component.ts | 17 ++++++++++------- src/app/services/midi.service.ts | 13 ++----------- src/app/services/notes.service.ts | 2 +- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 3e38ffb..c43e80c 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -33,7 +33,10 @@ export class HomePageComponent implements OnInit { private osmdService: OsmdService, public changeRef: ChangeDetectorRef ) { - midi.onChange.subscribe(this.osmdCursorPlayMoveNext()); + midi.onChange.subscribe(() => { + if (this.pianoKeyboard) this.notes.updateNotesStatus(); + if (this.notes.checkRequired()) this.osmdCursorPlayMoveNext(); + }); } ngOnInit(): void { @@ -235,13 +238,13 @@ export class HomePageComponent implements OnInit { if (index != 0) cursor.show(); cursor.reset(); }); - // // Additional tasks in case of new start, not required in repetition + // TODO: Additional tasks in case of new start, not required in repetition // if (this.settings.repeat == this.settings.repeatCfg) { - // this.notes.clear(); - // // free auto pressed notes - // for (const [key] of this.midi.mapNotesAutoPressed) { - // this.midi.releaseNote(parseInt(key) + 12); - // } + this.notes.clear(); + // free auto pressed notes + for (const [key] of this.midi.mapNotesAutoPressed) { + this.midi.releaseNote(parseInt(key) + 12); + } // } this.osmdService.hideFeedback(); diff --git a/src/app/services/midi.service.ts b/src/app/services/midi.service.ts index 03a1b1b..43fd8ff 100644 --- a/src/app/services/midi.service.ts +++ b/src/app/services/midi.service.ts @@ -83,7 +83,6 @@ export class MidiService { this.initDev(access); } - // Press note on Ouput MIDI Device pressNote(pitch: number, velocity: number): void { this.mapNotesAutoPressed.set((pitch - 12).toFixed(), 1); const iter = this.outputs.values(); @@ -123,11 +122,7 @@ export class MidiService { this.osmd.textFeedback('❌', 0, 20); } - // TODO: if (this.homePageComponent.pianoKeyboard) - this.notes.updateNotesStatus(); - if (this.notes.checkRequired()) - // HomePageComponent.osmdCursorPlayMoveNext(); - this.onChange.emit({}); + this.onChange.emit(); } // Midi input note released @@ -136,11 +131,7 @@ export class MidiService { const name = halbTone.toFixed(); this.notes.release(name); - // TODO: if (this.homePageComponent.pianoKeyboard) - this.notes.updateNotesStatus(); - if (this.notes.checkRequired()) - // HomePageComponent.osmdCursorPlayMoveNext(); - this.onChange.emit({}); + this.onChange.emit(); } // Refresh wakelock for two minutes diff --git a/src/app/services/notes.service.ts b/src/app/services/notes.service.ts index e24931a..362ac19 100644 --- a/src/app/services/notes.service.ts +++ b/src/app/services/notes.service.ts @@ -17,7 +17,7 @@ export type NoteObject = { }) export class NotesService { mapPressed: Map = new Map(); - // Initialize maps of notes comming from Music Sheet + // Initialize maps of notes coming from Music Sheet mapRequired = new Map(); mapPrevRequired = new Map();