Explorar o código

fix(PlaybackManager): Fix error when PlaybackInstrument undefined, add workaround (#42)

found in samples from #42, though that doesn't seem to be the main problem in the issue
sschmidTU %!s(int64=3) %!d(string=hai) anos
pai
achega
7152ac2ed6
Modificáronse 1 ficheiros con 3 adicións e 1 borrados
  1. 3 1
      src/Playback/PlaybackManager.ts

+ 3 - 1
src/Playback/PlaybackManager.ts

@@ -737,7 +737,9 @@ export class PlaybackManager implements IPlaybackParametersListener {
                                     }
 
                                     // recalculate Volume for this instrument:
-                                    volume = notePlaybackInstrument.volume * staff.Volume * voiceEntry.ParentVoice.Volume;
+                                    const instrumentVolume: number = notePlaybackInstrument?.volume ?? 1;
+                                    // TODO notePlaybackInstrument can be undefined, e.g. issue 42
+                                    volume = instrumentVolume * staff.Volume * voiceEntry.ParentVoice.Volume;
 
                                     // attenuate if in Solo mode an this voice is not soloed:
                                     if (soloAttenuate) {