Skip to content

Commit

Permalink
combine note statu update and cursor movement into midi event
Browse files Browse the repository at this point in the history
  • Loading branch information
hall committed Mar 31, 2023
1 parent 126fa3f commit c9a576a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
17 changes: 10 additions & 7 deletions src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 2 additions & 11 deletions src/app/services/midi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/notes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type NoteObject = {
})
export class NotesService {
mapPressed: Map<string, number> = new Map();
// Initialize maps of notes comming from Music Sheet
// Initialize maps of notes coming from Music Sheet
mapRequired = new Map<string, NoteObject>();
mapPrevRequired = new Map<string, NoteObject>();

Expand Down

0 comments on commit c9a576a

Please sign in to comment.