소스 검색

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 년 전
부모
커밋
5380f37f1c
2개의 변경된 파일10개의 추가작업 그리고 4개의 파일을 삭제
  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;
                                         }
                                     }