Skip to content

Commit 4e1ab07

Browse files
committed
fix ts issues
1 parent 48e3227 commit 4e1ab07

File tree

1 file changed

+10
-12
lines changed
  • packages/courses/src/piano/utility

1 file changed

+10
-12
lines changed

packages/courses/src/piano/utility/midi.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class Syllable {
159159
isCorrect: boolean;
160160
isMissing: boolean;
161161
})[];
162-
isCorrect: boolean;
162+
isCorrect: boolean | undefined;
163163

164164
get timestamp(): number {
165165
let timestamp = 0;
@@ -293,16 +293,16 @@ class SkMidi {
293293
public recording: NoteEvent[] = [];
294294

295295
private webmidi: WebMidi = webmidi;
296-
private input: Input;
297-
private output: Output;
296+
private input: Input | undefined;
297+
private output: Output | undefined;
298298
private _noteonListeners: ((e: InputEventNoteon) => void)[] = [];
299299
private _noteoffListeners: ((e: InputEventNoteoff) => void)[] = [];
300300

301301
private static _initializedWithUserConfig = false;
302302

303-
private midiAccess: WebMidi.MIDIAccess;
303+
private midiAccess: WebMidi.MIDIAccess | undefined;
304304

305-
private _state: 'nodevice' | 'notsupported' | 'ready';
305+
private _state: 'nodevice' | 'notsupported' | 'ready' | 'initializing' = 'initializing';
306306
public get state() {
307307
return this._state;
308308
}
@@ -417,8 +417,6 @@ class SkMidi {
417417
}
418418
}
419419

420-
private _stateChangeListener: () => void;
421-
422420
public setStateChangeListener(f: () => void) {
423421
if (!this.midiAccess) {
424422
try {
@@ -456,10 +454,10 @@ class SkMidi {
456454
private attachListeners() {
457455
if (this.input) {
458456
this._noteonListeners.forEach((f) => {
459-
this.input.on('noteon', 'all', f);
457+
this.input?.on('noteon', 'all', f);
460458
});
461459
this._noteoffListeners.forEach((f) => {
462-
this.input.on('noteoff', 'all', f);
460+
this.input?.on('noteoff', 'all', f);
463461
});
464462
}
465463
}
@@ -481,7 +479,7 @@ class SkMidi {
481479
}
482480

483481
public stopRecording() {
484-
this.input.removeListener();
482+
this.input?.removeListener();
485483
}
486484

487485
public record() {
@@ -547,13 +545,13 @@ class SkMidi {
547545

548546
playbackData.forEach((e) => {
549547
if (e.type === 'noteon') {
550-
this.output.playNote(e.note.name + e.note.octave, 1, {
548+
this.output?.playNote(e.note.name + e.note.octave, 1, {
551549
velocity: e.velocity,
552550
time: `+${e.timestamp}`,
553551
rawVelocity: false,
554552
});
555553
} else {
556-
this.output.stopNote(e.note.name + e.note.octave, 1, {
554+
this.output?.stopNote(e.note.name + e.note.octave, 1, {
557555
velocity: e.velocity,
558556
time: `+${e.timestamp}`,
559557
rawVelocity: false,

0 commit comments

Comments
 (0)