|
@@ -17,12 +17,20 @@ export class BasicAudioPlayer implements IAudioPlayer<SoundfontPlayer.Player> {
|
|
|
protected memoryLoadedSoundFonts: Map<MidiInstrument, SoundfontPlayer.Player> = new Map();
|
|
|
protected channelToSoundFont: Map<number, number> = new Map();
|
|
|
|
|
|
- public SoundfontInstrumentOptions = {};
|
|
|
+ public SoundfontInstrumentOptions = {
|
|
|
+ from: undefined,
|
|
|
+ nameToUrl: undefined
|
|
|
+ };
|
|
|
+
|
|
|
|
|
|
* but it looks like soundfont-player is louder with volumes > 1.
|
|
|
* E.g. set osmd.PlaybackManager.audioPlayer.GainMultiplier to 3 if you think the player is too quiet. */
|
|
|
public GainMultiplier: number = 1;
|
|
|
|
|
|
+ constructor() {
|
|
|
+ this.SoundfontInstrumentOptions.nameToUrl = this.nameToSoundfontUrl;
|
|
|
+ }
|
|
|
+
|
|
|
public async open(uniqueInstruments: number[], numberOfinstruments: number = 16): Promise<void> {
|
|
|
if (this.piano === undefined) {
|
|
|
this.piano = await SoundfontPlayer.instrument(
|
|
@@ -83,7 +91,6 @@ export class BasicAudioPlayer implements IAudioPlayer<SoundfontPlayer.Player> {
|
|
|
}
|
|
|
|
|
|
public async loadSoundFont(soundId: MidiInstrument): Promise<SoundfontPlayer.Player> {
|
|
|
-
|
|
|
if (this.memoryLoadedSoundFonts.get(soundId) !== undefined) {
|
|
|
return this.memoryLoadedSoundFonts.get(soundId);
|
|
|
}
|
|
@@ -102,6 +109,25 @@ export class BasicAudioPlayer implements IAudioPlayer<SoundfontPlayer.Player> {
|
|
|
return player;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public nameToSoundfontUrl(name: string, font: string, format: string): string {
|
|
|
+
|
|
|
+ format = format === "ogg" ? format : "mp3";
|
|
|
+ font = font === "FluidR3_GM" ? font : "MusyngKite";
|
|
|
+ let url: string = "https://gleitz.github.io/midi-js-soundfonts/" + font + "/" + name + "-" + format + ".js";
|
|
|
+
|
|
|
+
|
|
|
+ const urlReplacements: Object = {
|
|
|
+ "honky_tonk_piano-mp3.js": "honkytonk_piano-mp3.js",
|
|
|
+ "synth_voice-mp3.js": "synth_choir-mp3.js",
|
|
|
+ "lead_8_bass_lead-mp3.js": "lead_8_bass__lead-mp3.js",
|
|
|
+ };
|
|
|
+ for (const key of Object.keys(urlReplacements)) {
|
|
|
+ url = url.replace(key, urlReplacements[key]);
|
|
|
+ }
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+
|
|
|
public setVolume(instrumentChannel: number, volume: number): void {
|
|
|
this.channelVolumes[instrumentChannel] = volume;
|
|
|
}
|