浏览代码

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 3 年之前
父节点
当前提交
7152ac2ed6
共有 1 个文件被更改,包括 3 次插入1 次删除
  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) {