瀏覽代碼

refactor: add bpm check in bpmChanged, inform if invalid bpm set

sschmidTU 3 年之前
父節點
當前提交
8adc80b8f3
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      src/Playback/PlaybackManager.ts

+ 7 - 2
src/Playback/PlaybackManager.ts

@@ -615,8 +615,7 @@ export class PlaybackManager implements IPlaybackParametersListener {
 
 
                         const currentMeasureBPM: number = this.currentMeasure.TempoInBPM;
                         const currentMeasureBPM: number = this.currentMeasure.TempoInBPM;
                         if (currentMeasureBPM !== this.currentBPM && currentMeasureBPM > 0) {
                         if (currentMeasureBPM !== this.currentBPM && currentMeasureBPM > 0) {
-                            // only accept valid bpm (> 0)
-                            //   TODO one sample has bpm 0 for measure 5: love again - dua lipa
+                            // TODO the default value for measure.TempoInBPM is 0, probably not a good default setup. But we also catch it in bpmChanged().
                             this.bpmChanged(currentMeasureBPM); // update playback speed/bpm
                             this.bpmChanged(currentMeasureBPM); // update playback speed/bpm
                         }
                         }
 
 
@@ -1227,6 +1226,12 @@ export class PlaybackManager implements IPlaybackParametersListener {
     }
     }
 
 
     public bpmChanged(newBpm: number): void {
     public bpmChanged(newBpm: number): void {
+        if (!(newBpm > 0)) {
+            // only accept valid bpm (> 0)
+            //   TODO one sample has bpm 0 for measure 5: love again - dua lipa
+            log.info("invalid bpm set: " + newBpm + ". Ignoring.");
+            return;
+        }
         this.currentBPM = newBpm;
         this.currentBPM = newBpm;
         this.timingSource.setBpm(newBpm);
         this.timingSource.setBpm(newBpm);
     }
     }