smplr 0.16.2 → 0.16.4

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
@@ -589,11 +589,20 @@ function loadAudioBuffer(context, url, storage) {
589
589
  }
590
590
  });
591
591
  }
592
+ function isSafari() {
593
+ if (typeof navigator === "undefined") return false;
594
+ const ua = navigator.userAgent;
595
+ return ua.includes("Safari") && !ua.includes("Chrome") && !ua.includes("Chromium");
596
+ }
592
597
  function findFirstSupportedFormat(formats) {
593
598
  if (typeof document === "undefined") return null;
599
+ const skipOgg = isSafari();
594
600
  const audio = document.createElement("audio");
595
601
  for (let i = 0; i < formats.length; i++) {
596
602
  const format = formats[i];
603
+ if (skipOgg && format === "ogg") {
604
+ continue;
605
+ }
597
606
  const canPlay = audio.canPlayType(`audio/${format}`);
598
607
  if (canPlay === "probably" || canPlay === "maybe") {
599
608
  return format;
@@ -1800,6 +1809,7 @@ var Smolken = class {
1800
1809
  function gleitzKitUrl(name, kit) {
1801
1810
  var _a;
1802
1811
  const format = (_a = findFirstSupportedFormat(["ogg", "mp3"])) != null ? _a : "mp3";
1812
+ console.debug(`Soundfont: using ${format} format for ${name}`);
1803
1813
  return `https://gleitz.github.io/midi-js-soundfonts/${kit}/${name}-${format}.js`;
1804
1814
  }
1805
1815
  function soundfontInstrumentLoader(url, buffers, group) {
@@ -1811,15 +1821,22 @@ function soundfontInstrumentLoader(url, buffers, group) {
1811
1821
  noteNames.map((noteName) => __async(this, null, function* () {
1812
1822
  const midi = toMidi(noteName);
1813
1823
  if (!midi) return;
1814
- const audioData = base64ToArrayBuffer(
1815
- removeBase64Prefix(json[noteName])
1816
- );
1817
- const buffer = yield context.decodeAudioData(audioData);
1818
- buffers[noteName] = buffer;
1819
- group.regions.push({
1820
- sampleName: noteName,
1821
- midiPitch: midi
1822
- });
1824
+ try {
1825
+ const audioData = base64ToArrayBuffer(
1826
+ removeBase64Prefix(json[noteName])
1827
+ );
1828
+ const buffer = yield context.decodeAudioData(audioData);
1829
+ buffers[noteName] = buffer;
1830
+ group.regions.push({
1831
+ sampleName: noteName,
1832
+ midiPitch: midi
1833
+ });
1834
+ } catch (error) {
1835
+ console.warn(
1836
+ `Soundfont: failed to decode note ${noteName}`,
1837
+ error instanceof Error ? error.message : error
1838
+ );
1839
+ }
1823
1840
  }))
1824
1841
  );
1825
1842
  spreadRegions(group.regions);
@@ -1845,6 +1862,7 @@ function base64ToArrayBuffer(base64) {
1845
1862
  return bytes.buffer;
1846
1863
  }
1847
1864
  var SOUNDFONT_KITS = ["MusyngKite", "FluidR3_GM"];
1865
+ var DEFAULT_SOUNDFONT_KIT = SOUNDFONT_KITS[0];
1848
1866
  var SOUNDFONT_INSTRUMENTS = [
1849
1867
  "accordion",
1850
1868
  "acoustic_bass",
@@ -2084,19 +2102,19 @@ function soundfontLoader(url, loopsUrl, buffers, group) {
2084
2102
  });
2085
2103
  }
2086
2104
  function getSoundfontConfig(options) {
2087
- var _a, _b, _c, _d;
2105
+ var _a, _b, _c, _d, _e;
2088
2106
  if (!options.instrument && !options.instrumentUrl) {
2089
2107
  throw Error("Soundfont: instrument or instrumentUrl is required");
2090
2108
  }
2091
2109
  const config = {
2092
- kit: "MusyngKite",
2110
+ kit: (_a = options.kit) != null ? _a : DEFAULT_SOUNDFONT_KIT,
2093
2111
  instrument: options.instrument,
2094
- storage: (_a = options.storage) != null ? _a : HttpStorage,
2112
+ storage: (_b = options.storage) != null ? _b : HttpStorage,
2095
2113
  // This is to compensate the low volume of the original samples
2096
- extraGain: (_b = options.extraGain) != null ? _b : 5,
2097
- loadLoopData: (_c = options.loadLoopData) != null ? _c : false,
2114
+ extraGain: (_c = options.extraGain) != null ? _c : 5,
2115
+ loadLoopData: (_d = options.loadLoopData) != null ? _d : false,
2098
2116
  loopDataUrl: options.loopDataUrl,
2099
- instrumentUrl: (_d = options.instrumentUrl) != null ? _d : ""
2117
+ instrumentUrl: (_e = options.instrumentUrl) != null ? _e : ""
2100
2118
  };
2101
2119
  if (config.instrument && config.instrument.startsWith("http")) {
2102
2120
  console.warn(
@@ -2114,7 +2132,7 @@ function getSoundfontConfig(options) {
2114
2132
  );
2115
2133
  }
2116
2134
  } else {
2117
- if (config.kit || config.instrument) {
2135
+ if (config.kit !== DEFAULT_SOUNDFONT_KIT || config.instrument) {
2118
2136
  console.warn(
2119
2137
  "Soundfont: 'kit' and 'instrument' config parameters are ignored because 'instrumentUrl' is explicitly set."
2120
2138
  );