|
@@ -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 = {}; // e.g. set { from: 'server.com/soundfonts/' } for soundfont fetching url
|
|
|
+ public SoundfontInstrumentOptions = {
|
|
|
+ from: undefined,
|
|
|
+ nameToUrl: undefined // will be overwritten in constructor
|
|
|
+ }; // e.g. set { from: "server.com/soundfonts/" } for soundfont fetching url, and set nameToUrl to undefined.
|
|
|
+
|
|
|
/** Multiplicator for gain (volume output). 1 represents the maximum volume in OSMD (100%),
|
|
|
* 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;
|
|
|
}
|
|
|
|
|
|
+ /** Returns the url for the instrument name's soundfont to be loaded. */
|
|
|
+ public nameToSoundfontUrl(name: string, font: string, format: string): string {
|
|
|
+ // nameToUrl function from soundfont-player.js / lib/index.js
|
|
|
+ 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";
|
|
|
+ // end soundfont-player nameToUrl function. The following fixes bad links.
|
|
|
+
|
|
|
+ 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;
|
|
|
}
|