ソースを参照

fix(Playback): Fix a large number of notes being played when starting playback from the last note in the score (#28)

fix #28

basic idea by @Conde2, modified by sschmidTU
sschmidTU 3 年 前
コミット
e87e2e2dd2

+ 9 - 1
src/MusicalScore/Playback/VoicePlaybackData.ts

@@ -48,20 +48,27 @@ export class VoicePlaybackData {
         this.dueEntries.clear();
 
         if (!this.ParentVoice.Audible) {
+            this.playbackIndex = 0;
             return undefined;
         }
 
+        let entryFound: boolean = false;
         for (let i: number = this.playbackIndex; i < this.playbackEntries.length; i++) {
             const entry: { enrolledTimestamp: Fraction, playbackEntry: PlaybackEntry } = this.playbackEntries[i];
 
             if (entry.playbackEntry.ParentVoiceEntry.ParentSourceStaffEntry.AbsoluteTimestamp.RealValue > absoluteTimestamp.RealValue) {
                 this.nextEntryTimestamp = entry.enrolledTimestamp;
                 this.playbackIndex = Math.max(0, i - 1);
-
+                entryFound = true;
                 break;
             }
         }
 
+        // fix for starting from last note playing all notes (#28 osmd-extended):
+        if (!entryFound && this.playbackEntries.length > 0) {
+            this.playbackIndex = this.playbackEntries.length - 1;
+        }
+
         return this.nextEntryTimestamp;
     }
 
@@ -72,6 +79,7 @@ export class VoicePlaybackData {
             return undefined;
         }
 
+        // TODO if playback is paused and the cursor set to the last note in Beethoven - Geliebte, there are 5 playback entries.
         for (let i: number = this.playbackIndex; i < this.playbackEntries.length; i++) {
             const entry: { enrolledTimestamp: Fraction, playbackEntry: PlaybackEntry } = this.playbackEntries[i];
 

+ 2 - 1
src/Playback/BasicAudioPlayer.ts

@@ -66,7 +66,8 @@ export class BasicAudioPlayer implements IAudioPlayer<SoundfontPlayer.Player> {
   }
 
   public stopSound(instrumentChannel: number, volume: number): void {
-      //console.warn("BasicAudioPlayer stopSound not implemented");
+    //this.memoryLoadedSoundFonts.get(this.channelToSoundFont.get(instrumentChannel))?.stop(); // abrupt
+    //console.warn("BasicAudioPlayer stopSound not implemented");
   }
 
   public async setSound(