midi-audio-player 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7,8 +7,8 @@
7
7
  ██║ ╚═╝ ██║██║██████╔╝██║██║ ██║╚██████╔╝██████╔╝██║╚██████╔╝██║ ███████╗██║ ██║ ██║ ███████╗██║ ██║
8
8
  ╚═╝ ╚═╝╚═╝╚═════╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
9
9
 
10
- Version: 2.0.1
11
- Build: 2026-05-31 02:44:14
10
+ Version: 2.0.2
11
+ Build: 2026-06-02 12:19:59
12
12
  Author: Maxime Larrivée-Roy <mlarriveeroy@gmail.com>
13
13
  Github: https://github.com/webaudiofonts/midi-audio-player/
14
14
  Website: https://webaudiofonts.com/midiaudioplayer/
@@ -1252,9 +1252,10 @@ var WebAudioFontPlayer = class _WebAudioFontPlayer {
1252
1252
  const player = new _WebAudioFontPlayer(preset, audioCtx, compressor, () => resolve(player));
1253
1253
  });
1254
1254
  }
1255
- async setPreset(preset) {
1255
+ async setPreset(preset, nonblocking = false) {
1256
1256
  this.#preset = preset;
1257
- await Promise.all(this.#preset.zones.map((zone) => this.#adjustZone(zone)));
1257
+ if (nonblocking) this.#preset.zones.map((zone) => this.#adjustZone(zone));
1258
+ else await Promise.all(this.#preset.zones.map((zone) => this.#adjustZone(zone)));
1258
1259
  }
1259
1260
  close() {
1260
1261
  const now = this.#audioCtx.currentTime;
@@ -1959,13 +1960,16 @@ var MidiAudioPlayer = class _MidiAudioPlayer extends index.Player {
1959
1960
  throw new Error("Invalid preset: ".concat(id));
1960
1961
  }
1961
1962
  }
1962
- async loadPreset(presetId, channel) {
1963
+ async loadPreset(presetId, channel, nonblocking = false) {
1963
1964
  const presetInfo = await this.findPreset(presetId);
1964
1965
  if (!presetInfo) throw new Error("Invalid preset: ".concat(presetId));
1965
1966
  this.#presetMap[presetInfo.program] = presetInfo;
1966
1967
  const preset = await this.getPreset(presetId);
1967
- await this.#players[channel].setPreset(preset);
1968
- this.#setupChange();
1968
+ if (nonblocking) this.#players[channel].setPreset(preset, nonblocking).then(() => this.#setupChange());
1969
+ else {
1970
+ await this.#players[channel].setPreset(preset, nonblocking);
1971
+ this.#setupChange();
1972
+ }
1969
1973
  }
1970
1974
  async load(content, setup) {
1971
1975
  if (typeof content === "string") {
@@ -1993,6 +1997,15 @@ var MidiAudioPlayer = class _MidiAudioPlayer extends index.Player {
1993
1997
  } catch (e) {
1994
1998
  await this.loadArrayBuffer(await this.#repairMidi(content));
1995
1999
  }
2000
+ if (this.#opts.karaoke) {
2001
+ this.#log("Generating karaoke frames...");
2002
+ this.#lyrics = null;
2003
+ await this.#generateKaraokeFrames();
2004
+ if (this.#title) this.#sendKaraokeFrame("title", this.#title);
2005
+ }
2006
+ this.#log("Trim midi events...");
2007
+ this.#trimMidiEvents();
2008
+ queueMicrotask(() => this.triggerPlayerEvent("computed"));
1996
2009
  this.#log("Loading instruments...");
1997
2010
  this.#channels = await this.#getInstruments();
1998
2011
  this.#channelStates = Object.keys(this.#channels).reduce((acc, key) => ({ ...acc, [key]: false }), {});
@@ -2003,8 +2016,8 @@ var MidiAudioPlayer = class _MidiAudioPlayer extends index.Player {
2003
2016
  this.#channelVolumes[channel] = setup.volumes[channel];
2004
2017
  }));
2005
2018
  }
2006
- const setupPrograms = /* @__PURE__ */ new Set();
2007
2019
  const setupPresets = {};
2020
+ const setupPrograms = /* @__PURE__ */ new Set();
2008
2021
  if (setup?.presets !== void 0) {
2009
2022
  await Promise.all(Object.keys(setup.presets).map(async (channel) => {
2010
2023
  const presetInfo = await this.findPreset(setup.presets[channel]);
@@ -2015,7 +2028,7 @@ var MidiAudioPlayer = class _MidiAudioPlayer extends index.Player {
2015
2028
  }
2016
2029
  const uniqueInstruments = await this.#getUniqueInstruments();
2017
2030
  if (!Object.values(this.#channels).length) this.#log("Error: no instrument found");
2018
- const presets = Promise.all([...uniqueInstruments].map(async (program) => {
2031
+ await Promise.all([...uniqueInstruments].map(async (program) => {
2019
2032
  if (setupPrograms.has(program)) return;
2020
2033
  let preset = null;
2021
2034
  if (this.#presetMap[program] !== void 0) preset = await this.getPreset(this.#presetMap[program].id);
@@ -2023,16 +2036,6 @@ var MidiAudioPlayer = class _MidiAudioPlayer extends index.Player {
2023
2036
  else preset = await this.#getAutoPreset(program);
2024
2037
  this.#instruments[program] = preset;
2025
2038
  }));
2026
- if (this.#opts.karaoke) {
2027
- this.#log("Generating karaoke frames...");
2028
- this.#lyrics = null;
2029
- await this.#generateKaraokeFrames();
2030
- if (this.#title) this.#sendKaraokeFrame("title", this.#title);
2031
- }
2032
- this.#log("Trim midi events...");
2033
- this.#trimMidiEvents();
2034
- queueMicrotask(() => this.triggerPlayerEvent("computed"));
2035
- await presets;
2036
2039
  await Promise.all(Object.keys(this.#channels).map(async (channel) => {
2037
2040
  if (this.#players[channel]) this.#players[channel].close();
2038
2041
  if (setupPresets[channel] !== void 0) this.#players[channel] = await this.#createPlayer(setupPresets[channel]);
@@ -2487,8 +2490,8 @@ var MidiAudioPlayer = class _MidiAudioPlayer extends index.Player {
2487
2490
  this.#presetMap[program] = preset;
2488
2491
  return await this.getPreset(preset.id);
2489
2492
  }
2490
- async #createPlayer(preset) {
2491
- return new index_default(preset, this.#audioCtx, this.#compressor);
2493
+ #createPlayer(preset) {
2494
+ return index_default.load(preset, this.#audioCtx, this.#compressor);
2492
2495
  }
2493
2496
  async #handleMidiPipeline(event) {
2494
2497
  if (!this.isPlaying()) return;