Bläddra i källkod

fix drums playback - load correct soundfont, use correct channels and pitches. add PlaybackManager.IgnoreFixedInstrumentKeysForPercussion option

previously, woodblock was used as the instrument (115), not sure why.
also, the subinstrument.fixedKey seems to be wrong for drums, it seems to be always one higher than is correct.
also, the percussion channel is 10 for general midi according to wikipedia, not 9.
sschmidTU 2 år sedan
förälder
incheckning
5380f37f1c
2 ändrade filer med 10 tillägg och 4 borttagningar
  1. 6 1
      src/Playback/BasicAudioPlayer.ts
  2. 4 3
      src/Playback/PlaybackManager.ts

+ 6 - 1
src/Playback/BasicAudioPlayer.ts

@@ -86,9 +86,14 @@ export class BasicAudioPlayer implements IAudioPlayer<SoundfontPlayer.Player> {
       return this.memoryLoadedSoundFonts.get(soundId);
     }
 
+    let nameOrUrl: any = midiNames[soundId].toLowerCase();
+    if (soundId === MidiInstrument.Percussion) {
+      // percussion unfortunately doesn't exist in the original soundfonts
+      nameOrUrl = "https://paulrosen.github.io/midi-js-soundfonts/FluidR3_GM/percussion-mp3.js";
+    }
     const player: SoundfontPlayer.Player = await SoundfontPlayer.instrument(
       this.ac as unknown as AudioContext,
-      midiNames[soundId].toLowerCase() as any,
+      nameOrUrl,
       this.SoundfontInstrumentOptions
     );
     this.memoryLoadedSoundFonts.set(soundId, player);

+ 4 - 3
src/Playback/PlaybackManager.ts

@@ -46,7 +46,7 @@ export class PlaybackManager implements IPlaybackParametersListener {
     public addListener(listener: IPlaybackListener): void {
         this.listeners.push(listener);
     }
-    private readonly percussionChannel: number = 9; // this is a definition of the midi interface (cannot be changed)
+    private readonly percussionChannel: number = 10; // this is a definition of the midi interface (cannot be changed)
     private messageViewer: IMessageViewer;
     private audioMetronomePlayer: IAudioMetronomePlayer;
     private audioPlayer: IAudioPlayer<any>;
@@ -115,6 +115,7 @@ export class PlaybackManager implements IPlaybackParametersListener {
     public MoveCursorDuringPrecount: boolean = true;
     private fermataActive: boolean;
     private doPreCount: boolean = true;
+    public IgnoreFixedInstrumentKeysForPercussion: boolean = true;
 
     constructor (timingSource: ITimingSource, audioMetronomePlayer: IAudioMetronomePlayer, audioPlayer: IAudioPlayer<any>, messageViewer: IMessageViewer) {
         const metronomeLabel: string = TextTranslation.translateText("Playback/LabelMetronome", "Metronome");
@@ -282,7 +283,7 @@ export class PlaybackManager implements IPlaybackParametersListener {
 
                 this.audioPlayer.open(uniqueMidiInstruments, 16);
                 // set drums:
-                this.audioPlayer.setSound(this.percussionChannel, 115);
+                this.audioPlayer.setSound(this.percussionChannel, MidiInstrument.Percussion);
             }
 
             this.currentReferenceBPM = this.sheetStartBPM = musicSheet.getExpressionsStartTempoInBPM();
@@ -746,7 +747,7 @@ export class PlaybackManager implements IPlaybackParametersListener {
                                     const notePlaybackInstrument: SubInstrument =
                                         instrument.getSubInstrument(note.ParentNote.PlaybackInstrumentId);
                                     if (notePlaybackInstrument !== undefined) {
-                                        if (notePlaybackInstrument.fixedKey >= 0) {
+                                        if (notePlaybackInstrument.fixedKey >= 0 && !(isPercussion && this.IgnoreFixedInstrumentKeysForPercussion)) {
                                             key = notePlaybackInstrument.fixedKey;
                                         }
                                     }