smplr 0.15.1 → 0.16.0

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,6 +7,9 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __typeError = (msg) => {
11
+ throw TypeError(msg);
12
+ };
10
13
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
14
  var __spreadValues = (a, b) => {
12
15
  for (var prop in b || (b = {}))
@@ -33,28 +36,11 @@ var __copyProps = (to, from, except, desc) => {
33
36
  return to;
34
37
  };
35
38
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
- var __accessCheck = (obj, member, msg) => {
37
- if (!member.has(obj))
38
- throw TypeError("Cannot " + msg);
39
- };
40
- var __privateGet = (obj, member, getter) => {
41
- __accessCheck(obj, member, "read from private field");
42
- return getter ? getter.call(obj) : member.get(obj);
43
- };
44
- var __privateAdd = (obj, member, value) => {
45
- if (member.has(obj))
46
- throw TypeError("Cannot add the same private member more than once");
47
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
48
- };
49
- var __privateSet = (obj, member, value, setter) => {
50
- __accessCheck(obj, member, "write to private field");
51
- setter ? setter.call(obj, value) : member.set(obj, value);
52
- return value;
53
- };
54
- var __privateMethod = (obj, member, method) => {
55
- __accessCheck(obj, member, "access private method");
56
- return method;
57
- };
39
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
40
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
41
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
42
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
43
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
58
44
  var __async = (__this, __arguments, generator) => {
59
45
  return new Promise((resolve, reject) => {
60
46
  var fulfilled = (value) => {
@@ -161,8 +147,7 @@ function createTrigger() {
161
147
  function unsubscribeAll(unsubscribe) {
162
148
  let done = false;
163
149
  return () => {
164
- if (done)
165
- return;
150
+ if (done) return;
166
151
  done = true;
167
152
  unsubscribe.forEach((cb) => cb == null ? void 0 : cb());
168
153
  };
@@ -181,12 +166,12 @@ var _volume, _sends, _inserts, _disconnect, _unsubscribe, _config, _disconnected
181
166
  var Channel = class {
182
167
  constructor(context, options) {
183
168
  this.context = context;
184
- __privateAdd(this, _volume, void 0);
185
- __privateAdd(this, _sends, void 0);
186
- __privateAdd(this, _inserts, void 0);
187
- __privateAdd(this, _disconnect, void 0);
188
- __privateAdd(this, _unsubscribe, void 0);
189
- __privateAdd(this, _config, void 0);
169
+ __privateAdd(this, _volume);
170
+ __privateAdd(this, _sends);
171
+ __privateAdd(this, _inserts);
172
+ __privateAdd(this, _disconnect);
173
+ __privateAdd(this, _unsubscribe);
174
+ __privateAdd(this, _config);
190
175
  __privateAdd(this, _disconnected, false);
191
176
  var _a, _b, _c;
192
177
  __privateSet(this, _config, {
@@ -248,8 +233,7 @@ var Channel = class {
248
233
  }
249
234
  disconnect() {
250
235
  var _a;
251
- if (__privateGet(this, _disconnected))
252
- return;
236
+ if (__privateGet(this, _disconnected)) return;
253
237
  __privateSet(this, _disconnected, true);
254
238
  __privateGet(this, _disconnect).call(this);
255
239
  __privateGet(this, _unsubscribe).call(this);
@@ -338,9 +322,9 @@ function getConfig(options) {
338
322
  var _config2, _queue, _intervalId;
339
323
  var QueuedPlayer = class {
340
324
  constructor(player, options = {}) {
341
- __privateAdd(this, _config2, void 0);
342
- __privateAdd(this, _queue, void 0);
343
- __privateAdd(this, _intervalId, void 0);
325
+ __privateAdd(this, _config2);
326
+ __privateAdd(this, _queue);
327
+ __privateAdd(this, _intervalId);
344
328
  __privateSet(this, _config2, getConfig(options));
345
329
  __privateSet(this, _queue, new SortedQueue(
346
330
  (a, b) => a.time - b.time
@@ -430,9 +414,9 @@ var SamplePlayer = class {
430
414
  constructor(context, options) {
431
415
  this.context = context;
432
416
  this.options = options;
433
- __privateAdd(this, _config3, void 0);
417
+ __privateAdd(this, _config3);
434
418
  __privateAdd(this, _disconnected2, false);
435
- __privateAdd(this, _stop, void 0);
419
+ __privateAdd(this, _stop);
436
420
  var _a, _b;
437
421
  __privateSet(this, _config3, {
438
422
  velocityToGain: (_a = options.velocityToGain) != null ? _a : midiVelToGain,
@@ -525,8 +509,7 @@ var SamplePlayer = class {
525
509
  __privateGet(this, _stop).trigger(sample);
526
510
  }
527
511
  disconnect() {
528
- if (__privateGet(this, _disconnected2))
529
- return;
512
+ if (__privateGet(this, _disconnected2)) return;
530
513
  __privateSet(this, _disconnected2, true);
531
514
  this.stop();
532
515
  Object.keys(this.buffers).forEach((key) => {
@@ -545,8 +528,7 @@ function createDecayEnvelope(context, envelopeTime = 0.2) {
545
528
  const envelope = context.createGain();
546
529
  envelope.gain.value = 1;
547
530
  function start(time) {
548
- if (stopAt)
549
- return stopAt;
531
+ if (stopAt) return stopAt;
550
532
  envelope.gain.cancelScheduledValues(time);
551
533
  const envelopeAt = time || context.currentTime;
552
534
  stopAt = envelopeAt + envelopeTime;
@@ -608,8 +590,7 @@ function loadAudioBuffer(context, url, storage) {
608
590
  });
609
591
  }
610
592
  function findFirstSupportedFormat(formats) {
611
- if (typeof document === "undefined")
612
- return null;
593
+ if (typeof document === "undefined") return null;
613
594
  const audio = document.createElement("audio");
614
595
  for (let i = 0; i < formats.length; i++) {
615
596
  const format = formats[i];
@@ -638,12 +619,11 @@ var HttpStorage = {
638
619
  return fetch(url);
639
620
  }
640
621
  };
641
- var _cache, _tryFromCache, tryFromCache_fn, _saveResponse, saveResponse_fn;
622
+ var _cache, _CacheStorage_instances, tryFromCache_fn, saveResponse_fn;
642
623
  var CacheStorage = class {
643
624
  constructor(name = "smplr") {
644
- __privateAdd(this, _tryFromCache);
645
- __privateAdd(this, _saveResponse);
646
- __privateAdd(this, _cache, void 0);
625
+ __privateAdd(this, _CacheStorage_instances);
626
+ __privateAdd(this, _cache);
647
627
  if (typeof window === "undefined" || !("caches" in window)) {
648
628
  __privateSet(this, _cache, Promise.reject("CacheStorage not supported"));
649
629
  } else {
@@ -654,28 +634,25 @@ var CacheStorage = class {
654
634
  return __async(this, null, function* () {
655
635
  const request = new Request(url);
656
636
  try {
657
- return yield __privateMethod(this, _tryFromCache, tryFromCache_fn).call(this, request);
637
+ return yield __privateMethod(this, _CacheStorage_instances, tryFromCache_fn).call(this, request);
658
638
  } catch (err) {
659
639
  const response = yield fetch(request);
660
- yield __privateMethod(this, _saveResponse, saveResponse_fn).call(this, request, response);
640
+ yield __privateMethod(this, _CacheStorage_instances, saveResponse_fn).call(this, request, response);
661
641
  return response;
662
642
  }
663
643
  });
664
644
  }
665
645
  };
666
646
  _cache = new WeakMap();
667
- _tryFromCache = new WeakSet();
647
+ _CacheStorage_instances = new WeakSet();
668
648
  tryFromCache_fn = function(request) {
669
649
  return __async(this, null, function* () {
670
650
  const cache = yield __privateGet(this, _cache);
671
651
  const response = yield cache.match(request);
672
- if (response)
673
- return response;
674
- else
675
- throw Error("Not found");
652
+ if (response) return response;
653
+ else throw Error("Not found");
676
654
  });
677
655
  };
678
- _saveResponse = new WeakSet();
679
656
  saveResponse_fn = function(request, response) {
680
657
  return __async(this, null, function* () {
681
658
  try {
@@ -688,15 +665,15 @@ saveResponse_fn = function(request, response) {
688
665
 
689
666
  // src/drum-machine/dm-instrument.ts
690
667
  function isDrumMachineInstrument(instrument) {
691
- return typeof instrument === "object" && typeof instrument.baseUrl === "string" && typeof instrument.name === "string" && Array.isArray(instrument.samples) && Array.isArray(instrument.sampleNames) && typeof instrument.nameToSample === "object" && typeof instrument.sampleNameVariations === "object";
668
+ return typeof instrument === "object" && typeof instrument.baseUrl === "string" && typeof instrument.name === "string" && Array.isArray(instrument.samples) && Array.isArray(instrument.groupNames) && typeof instrument.nameToSampleName === "object" && typeof instrument.sampleGroupVariations === "object";
692
669
  }
693
670
  var EMPTY_INSTRUMENT = {
694
671
  baseUrl: "",
695
672
  name: "",
696
673
  samples: [],
697
- sampleNames: [],
698
- nameToSample: {},
699
- sampleNameVariations: {}
674
+ groupNames: [],
675
+ nameToSampleName: {},
676
+ sampleGroupVariations: {}
700
677
  };
701
678
  function fetchDrumMachineInstrument(url, storage) {
702
679
  return __async(this, null, function* () {
@@ -704,20 +681,20 @@ function fetchDrumMachineInstrument(url, storage) {
704
681
  const res = yield storage.fetch(url);
705
682
  const json = yield res.json();
706
683
  json.baseUrl = url.replace("/dm.json", "");
707
- json.sampleNames = [];
708
- json.nameToSample = {};
709
- json.sampleNameVariations = {};
710
- for (const sampleSrc of json.samples) {
711
- const sample = sampleSrc.indexOf("/") !== -1 ? sampleSrc : sampleSrc.replace("-", "/");
712
- json.nameToSample[sample] = sample;
713
- const [base, variation] = sample.split("/");
714
- if (!json.sampleNames.includes(base)) {
715
- json.sampleNames.push(base);
684
+ json.groupNames = [];
685
+ json.nameToSampleName = {};
686
+ json.sampleGroupVariations = {};
687
+ for (const sample of json.samples) {
688
+ json.nameToSampleName[sample] = sample;
689
+ const separator = sample.indexOf("/") !== -1 ? "/" : "-";
690
+ const [base, variation] = sample.split(separator);
691
+ if (!json.groupNames.includes(base)) {
692
+ json.groupNames.push(base);
716
693
  }
717
- (_b = (_a = json.nameToSample)[base]) != null ? _b : _a[base] = sample;
718
- (_d = (_c = json.sampleNameVariations)[base]) != null ? _d : _c[base] = [];
694
+ (_b = (_a = json.nameToSampleName)[base]) != null ? _b : _a[base] = sample;
695
+ (_d = (_c = json.sampleGroupVariations)[base]) != null ? _d : _c[base] = [];
719
696
  if (variation) {
720
- json.sampleNameVariations[base].push(`${base}/${variation}`);
697
+ json.sampleGroupVariations[base].push(`${base}${separator}${variation}`);
721
698
  }
722
699
  }
723
700
  return json;
@@ -769,22 +746,19 @@ var DrumMachine = class {
769
746
  __privateSet(this, _instrument, instrument2);
770
747
  });
771
748
  }
772
- loaded() {
773
- return __async(this, null, function* () {
774
- console.warn("deprecated: use load instead");
775
- return this.load;
776
- });
749
+ getSampleNames() {
750
+ return __privateGet(this, _instrument).samples.slice();
777
751
  }
778
- get sampleNames() {
779
- return __privateGet(this, _instrument).sampleNames;
752
+ getGroupNames() {
753
+ return __privateGet(this, _instrument).groupNames.slice();
780
754
  }
781
- getVariations(name) {
755
+ getSampleNamesForGroup(groupName) {
782
756
  var _a;
783
- return (_a = __privateGet(this, _instrument).sampleNameVariations[name]) != null ? _a : [];
757
+ return (_a = __privateGet(this, _instrument).sampleGroupVariations[groupName]) != null ? _a : [];
784
758
  }
785
759
  start(sample) {
786
760
  var _a;
787
- const sampleName = __privateGet(this, _instrument).nameToSample[sample.note];
761
+ const sampleName = __privateGet(this, _instrument).nameToSampleName[sample.note];
788
762
  return this.player.start(__spreadProps(__spreadValues({}, sample), {
789
763
  note: sampleName ? sampleName : sample.note,
790
764
  stopId: (_a = sample.stopId) != null ? _a : sample.note
@@ -793,6 +767,24 @@ var DrumMachine = class {
793
767
  stop(sample) {
794
768
  return this.player.stop(sample);
795
769
  }
770
+ /** @deprecated */
771
+ loaded() {
772
+ return __async(this, null, function* () {
773
+ console.warn("deprecated: use load instead");
774
+ return this.load;
775
+ });
776
+ }
777
+ /** @deprecated */
778
+ get sampleNames() {
779
+ console.log("deprecated: Use getGroupNames instead");
780
+ return __privateGet(this, _instrument).groupNames.slice();
781
+ }
782
+ /** @deprecated */
783
+ getVariations(groupName) {
784
+ var _a;
785
+ console.warn("deprecated: use getSampleNamesForGroup");
786
+ return (_a = __privateGet(this, _instrument).sampleGroupVariations[groupName]) != null ? _a : [];
787
+ }
796
788
  };
797
789
  _instrument = new WeakMap();
798
790
  function drumMachineLoader(context, buffers, instrument, storage) {
@@ -800,12 +792,10 @@ function drumMachineLoader(context, buffers, instrument, storage) {
800
792
  const format = (_a = findFirstSupportedFormat(["ogg", "m4a"])) != null ? _a : "ogg";
801
793
  return instrument.then(
802
794
  (data) => Promise.all(
803
- data.samples.map((sample) => __async(this, null, function* () {
804
- const url = `${data.baseUrl}/${sample}.${format}`;
805
- const sampleName = sample.indexOf("/") !== -1 ? sample : sample.replace("-", "/");
795
+ data.samples.map((sampleName) => __async(this, null, function* () {
796
+ const url = `${data.baseUrl}/${sampleName}.${format}`;
806
797
  const buffer = yield loadAudioBuffer(context, url, storage);
807
- if (buffer)
808
- buffers[sampleName] = buffer;
798
+ if (buffer) buffers[sampleName] = buffer;
809
799
  }))
810
800
  )
811
801
  );
@@ -815,11 +805,9 @@ function drumMachineLoader(context, buffers, instrument, storage) {
815
805
  function noteNameToMidi(note) {
816
806
  const REGEX = /^([a-gA-G]?)(#{1,}|b{1,}|)(-?\d+)$/;
817
807
  const m = REGEX.exec(note);
818
- if (!m)
819
- return;
808
+ if (!m) return;
820
809
  const letter = m[1].toUpperCase();
821
- if (!letter)
822
- return;
810
+ if (!letter) return;
823
811
  const acc = m[2];
824
812
  const alt = acc[0] === "b" ? -acc.length : acc.length;
825
813
  const oct = m[3] ? +m[3] : 4;
@@ -851,12 +839,9 @@ function SfzInstrumentLoader(instrument, storage) {
851
839
  } else if (isSfzInstrument(instrument)) {
852
840
  const websfz = yield fetchWebSfz(instrument.websfzUrl, storage);
853
841
  (_a = websfz.meta) != null ? _a : websfz.meta = {};
854
- if (instrument.name)
855
- websfz.meta.name = instrument.name;
856
- if (instrument.baseUrl)
857
- websfz.meta.baseUrl = instrument.baseUrl;
858
- if (instrument.formats)
859
- websfz.meta.formats = instrument.formats;
842
+ if (instrument.name) websfz.meta.name = instrument.name;
843
+ if (instrument.baseUrl) websfz.meta.baseUrl = instrument.baseUrl;
844
+ if (instrument.formats) websfz.meta.formats = instrument.formats;
860
845
  return websfz;
861
846
  } else {
862
847
  throw new Error("Invalid instrument: " + JSON.stringify(instrument));
@@ -867,11 +852,9 @@ function loadAudioBuffers(context, buffers, urls, storage) {
867
852
  return __async(this, null, function* () {
868
853
  yield Promise.all(
869
854
  Object.keys(urls).map((sampleId) => __async(this, null, function* () {
870
- if (buffers[sampleId])
871
- return;
855
+ if (buffers[sampleId]) return;
872
856
  const buffer = yield loadAudioBuffer(context, urls[sampleId], storage);
873
- if (buffer)
874
- buffers[sampleId] = buffer;
857
+ if (buffer) buffers[sampleId] = buffer;
875
858
  return buffers;
876
859
  }))
877
860
  );
@@ -895,8 +878,7 @@ function getWebsfzGroupUrls(websfz, group) {
895
878
  const baseUrl = (_a = websfz.meta.baseUrl) != null ? _a : "";
896
879
  const format = (_c = findFirstSupportedFormat((_b = websfz.meta.formats) != null ? _b : [])) != null ? _c : "ogg";
897
880
  const prefix = (_d = websfz.global["default_path"]) != null ? _d : "";
898
- if (!group)
899
- return urls;
881
+ if (!group) return urls;
900
882
  return group.regions.reduce((urls2, region) => {
901
883
  if (region.sample) {
902
884
  urls2[region.sample] = `${baseUrl}/${prefix}${region.sample}.${format}`;
@@ -931,12 +913,12 @@ var EMPTY_WEBSFZ = Object.freeze({
931
913
  global: {},
932
914
  groups: []
933
915
  });
934
- var _websfz, _startLayers, startLayers_fn;
916
+ var _websfz, _SfzSampler_instances, startLayers_fn;
935
917
  var SfzSampler = class {
936
918
  constructor(context, options) {
937
919
  this.context = context;
938
- __privateAdd(this, _startLayers);
939
- __privateAdd(this, _websfz, void 0);
920
+ __privateAdd(this, _SfzSampler_instances);
921
+ __privateAdd(this, _websfz);
940
922
  this.options = Object.freeze(
941
923
  Object.assign(
942
924
  {
@@ -971,7 +953,7 @@ var SfzSampler = class {
971
953
  });
972
954
  }
973
955
  start(sample) {
974
- __privateMethod(this, _startLayers, startLayers_fn).call(this, typeof sample === "object" ? sample : { note: sample });
956
+ __privateMethod(this, _SfzSampler_instances, startLayers_fn).call(this, typeof sample === "object" ? sample : { note: sample });
975
957
  }
976
958
  stop(sample) {
977
959
  this.player.stop(sample);
@@ -981,12 +963,11 @@ var SfzSampler = class {
981
963
  }
982
964
  };
983
965
  _websfz = new WeakMap();
984
- _startLayers = new WeakSet();
966
+ _SfzSampler_instances = new WeakSet();
985
967
  startLayers_fn = function(sample) {
986
968
  var _a;
987
969
  const midi = toMidi(sample.note);
988
- if (midi === void 0)
989
- return () => void 0;
970
+ if (midi === void 0) return () => void 0;
990
971
  const velocity = (_a = sample.velocity) != null ? _a : this.options.velocity;
991
972
  const regions = findRegions(__privateGet(this, _websfz), { midi, velocity });
992
973
  const onEnded = () => {
@@ -1100,8 +1081,7 @@ function createEmptyRegionGroup() {
1100
1081
  function findSamplesInRegions(group, sample, seqNumber, options) {
1101
1082
  const results = [];
1102
1083
  const midi = toMidi(sample.note);
1103
- if (midi === void 0)
1104
- return results;
1084
+ if (midi === void 0) return results;
1105
1085
  for (const region of group.regions) {
1106
1086
  const found = findSampleInRegion(
1107
1087
  midi,
@@ -1110,15 +1090,13 @@ function findSamplesInRegions(group, sample, seqNumber, options) {
1110
1090
  region,
1111
1091
  options
1112
1092
  );
1113
- if (found)
1114
- results.push(found);
1093
+ if (found) results.push(found);
1115
1094
  }
1116
1095
  return results;
1117
1096
  }
1118
1097
  function findFirstSampleInRegions(group, sample, seqNumber, options) {
1119
1098
  const midi = toMidi(sample.note);
1120
- if (midi === void 0)
1121
- return void 0;
1099
+ if (midi === void 0) return void 0;
1122
1100
  for (const region of group.regions) {
1123
1101
  const found = findSampleInRegion(
1124
1102
  midi,
@@ -1127,24 +1105,20 @@ function findFirstSampleInRegions(group, sample, seqNumber, options) {
1127
1105
  region,
1128
1106
  options
1129
1107
  );
1130
- if (found)
1131
- return found;
1108
+ if (found) return found;
1132
1109
  }
1133
1110
  return void 0;
1134
1111
  }
1135
1112
  function findSampleInRegion(midi, seqNum, sample, region, defaults) {
1136
1113
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
1137
1114
  const matchMidi = midi >= ((_a = region.midiLow) != null ? _a : 0) && midi < ((_b = region.midiHigh) != null ? _b : 127) + 1;
1138
- if (!matchMidi)
1139
- return void 0;
1115
+ if (!matchMidi) return void 0;
1140
1116
  const matchVelocity = sample.velocity === void 0 || sample.velocity >= ((_c = region.velLow) != null ? _c : 0) && sample.velocity <= ((_d = region.velHigh) != null ? _d : 127);
1141
- if (!matchVelocity)
1142
- return void 0;
1117
+ if (!matchVelocity) return void 0;
1143
1118
  if (region.seqLength) {
1144
1119
  const currentSeq = seqNum % region.seqLength;
1145
1120
  const regionIndex = ((_e = region.seqPosition) != null ? _e : 1) - 1;
1146
- if (currentSeq !== regionIndex)
1147
- return void 0;
1121
+ if (currentSeq !== regionIndex) return void 0;
1148
1122
  }
1149
1123
  const semitones = midi - region.midiPitch;
1150
1124
  const velocity = (_f = sample.velocity) != null ? _f : defaults == null ? void 0 : defaults.velocity;
@@ -1170,13 +1144,11 @@ function findSampleInRegion(midi, seqNum, sample, region, defaults) {
1170
1144
  };
1171
1145
  }
1172
1146
  function spreadRegions(regions) {
1173
- if (regions.length === 0)
1174
- return [];
1147
+ if (regions.length === 0) return [];
1175
1148
  regions.sort((a, b) => a.midiPitch - b.midiPitch);
1176
1149
  regions[0].midiLow = 0;
1177
1150
  regions[0].midiHigh = 127;
1178
- if (regions.length === 1)
1179
- return regions;
1151
+ if (regions.length === 1) return regions;
1180
1152
  for (let i = 1; i < regions.length; i++) {
1181
1153
  const prev = regions[i - 1];
1182
1154
  const curr = regions[i];
@@ -1224,8 +1196,7 @@ var RegionPlayer = class {
1224
1196
  }
1225
1197
  const toStop = typeof sample === "object" ? sample : { stopId: sample };
1226
1198
  const midi = toMidi(toStop.stopId);
1227
- if (!midi)
1228
- return;
1199
+ if (!midi) return;
1229
1200
  toStop.stopId = midi;
1230
1201
  this.player.stop(toStop);
1231
1202
  }
@@ -1287,13 +1258,10 @@ var PROP_STR_REGEX = /^([^=]+)=(.+)$/;
1287
1258
  var PROP_NUM_ARR_REGEX = /^([^=]+)_(\d+)=(\d+)$/;
1288
1259
  function parseToken(line) {
1289
1260
  line = line.trim();
1290
- if (line === "")
1291
- return void 0;
1292
- if (line.startsWith("//"))
1293
- return void 0;
1261
+ if (line === "") return void 0;
1262
+ if (line.startsWith("//")) return void 0;
1294
1263
  const modeMatch = line.match(MODE_REGEX);
1295
- if (modeMatch)
1296
- return { type: "mode", value: modeMatch[1] };
1264
+ if (modeMatch) return { type: "mode", value: modeMatch[1] };
1297
1265
  const propNumArrMatch = line.match(PROP_NUM_ARR_REGEX);
1298
1266
  if (propNumArrMatch)
1299
1267
  return {
@@ -1317,21 +1285,21 @@ function parseToken(line) {
1317
1285
  };
1318
1286
  return { type: "unknown", value: line };
1319
1287
  }
1320
- var _closeRegion, closeRegion_fn;
1288
+ var _Scope_instances, closeRegion_fn;
1321
1289
  var Scope = class {
1322
1290
  constructor() {
1323
- __privateAdd(this, _closeRegion);
1291
+ __privateAdd(this, _Scope_instances);
1324
1292
  this.values = {};
1325
1293
  this.global = {};
1326
1294
  this.group = {};
1327
1295
  }
1328
1296
  closeScope(mode, group) {
1329
1297
  if (mode === "global") {
1330
- __privateMethod(this, _closeRegion, closeRegion_fn).call(this, this.global);
1298
+ __privateMethod(this, _Scope_instances, closeRegion_fn).call(this, this.global);
1331
1299
  } else if (mode === "group") {
1332
- this.group = __privateMethod(this, _closeRegion, closeRegion_fn).call(this, {});
1300
+ this.group = __privateMethod(this, _Scope_instances, closeRegion_fn).call(this, {});
1333
1301
  } else if (mode === "region") {
1334
- const region = __privateMethod(this, _closeRegion, closeRegion_fn).call(this, __spreadValues(__spreadValues({
1302
+ const region = __privateMethod(this, _Scope_instances, closeRegion_fn).call(this, __spreadValues(__spreadValues({
1335
1303
  sampleName: "",
1336
1304
  midiPitch: -1
1337
1305
  }, this.global), this.group));
@@ -1365,28 +1333,25 @@ var Scope = class {
1365
1333
  this.values[key] = value;
1366
1334
  }
1367
1335
  popNum(key, dest, destKey) {
1368
- if (typeof this.values[key] !== "number")
1369
- return false;
1336
+ if (typeof this.values[key] !== "number") return false;
1370
1337
  dest[destKey] = this.values[key];
1371
1338
  delete this.values[key];
1372
1339
  return true;
1373
1340
  }
1374
1341
  popStr(key, dest, destKey) {
1375
- if (typeof this.values[key] !== "string")
1376
- return false;
1342
+ if (typeof this.values[key] !== "string") return false;
1377
1343
  dest[destKey] = this.values[key];
1378
1344
  delete this.values[key];
1379
1345
  return true;
1380
1346
  }
1381
1347
  popNumArr(key, dest, destKey) {
1382
- if (!Array.isArray(this.values[key]))
1383
- return false;
1348
+ if (!Array.isArray(this.values[key])) return false;
1384
1349
  dest[destKey] = this.values[key];
1385
1350
  delete this.values[key];
1386
1351
  return true;
1387
1352
  }
1388
1353
  };
1389
- _closeRegion = new WeakSet();
1354
+ _Scope_instances = new WeakSet();
1390
1355
  closeRegion_fn = function(region) {
1391
1356
  this.popStr("sample", region, "sampleName");
1392
1357
  this.popNum("pitch_keycenter", region, "midiPitch");
@@ -1416,8 +1381,7 @@ var instruments = [];
1416
1381
  var BASE_URL = "https://smpldsnds.github.io/sgossner-vcsl/";
1417
1382
  function getVersilianInstruments() {
1418
1383
  return __async(this, null, function* () {
1419
- if (instruments.length)
1420
- return instruments;
1384
+ if (instruments.length) return instruments;
1421
1385
  instruments = yield fetch(BASE_URL + "sfz_files.json").then(
1422
1386
  (res) => res.json()
1423
1387
  );
@@ -1576,8 +1540,7 @@ var Mellotron = class {
1576
1540
  void 0,
1577
1541
  this.options
1578
1542
  );
1579
- if (!found)
1580
- return () => void 0;
1543
+ if (!found) return () => void 0;
1581
1544
  return this.player.start(found);
1582
1545
  }
1583
1546
  stop(sample) {
@@ -1596,8 +1559,7 @@ function getMellotronConfig(options) {
1596
1559
  }
1597
1560
  function loadMellotronInstrument(instrument, buffers, group) {
1598
1561
  let variation = INSTRUMENT_VARIATIONS[instrument];
1599
- if (variation)
1600
- instrument = variation[0];
1562
+ if (variation) instrument = variation[0];
1601
1563
  return (context, storage) => {
1602
1564
  const baseUrl = `https://smpldsnds.github.io/archiveorg-mellotron/${instrument}/`;
1603
1565
  const audioExt = getPreferredAudioExtension();
@@ -1605,11 +1567,9 @@ function loadMellotronInstrument(instrument, buffers, group) {
1605
1567
  (sampleNames) => Promise.all(
1606
1568
  sampleNames.map((sampleName) => {
1607
1569
  var _a;
1608
- if (variation && !sampleName.includes(variation[1]))
1609
- return;
1570
+ if (variation && !sampleName.includes(variation[1])) return;
1610
1571
  const midi = toMidi((_a = sampleName.split(" ")[0]) != null ? _a : "");
1611
- if (!midi)
1612
- return;
1572
+ if (!midi) return;
1613
1573
  const sampleUrl = baseUrl + sampleName + audioExt;
1614
1574
  loadAudioBuffer(context, sampleUrl, storage).then((audioBuffer) => {
1615
1575
  var _a2;
@@ -1671,9 +1631,9 @@ function createDattorroReverbEffect(context) {
1671
1631
  var _effect, _ready, _output;
1672
1632
  var Reverb = class {
1673
1633
  constructor(context) {
1674
- __privateAdd(this, _effect, void 0);
1675
- __privateAdd(this, _ready, void 0);
1676
- __privateAdd(this, _output, void 0);
1634
+ __privateAdd(this, _effect);
1635
+ __privateAdd(this, _ready);
1636
+ __privateAdd(this, _output);
1677
1637
  this.input = context.createGain();
1678
1638
  __privateSet(this, _output, context.destination);
1679
1639
  __privateSet(this, _ready, createDattorroReverbEffect(context).then((reverb) => {
@@ -1713,7 +1673,7 @@ var _options;
1713
1673
  var Sampler = class {
1714
1674
  constructor(context, options = {}) {
1715
1675
  this.context = context;
1716
- __privateAdd(this, _options, void 0);
1676
+ __privateAdd(this, _options);
1717
1677
  var _a, _b, _c, _d, _e, _f;
1718
1678
  __privateSet(this, _options, {
1719
1679
  destination: (_a = options.destination) != null ? _a : context.destination,
@@ -1761,8 +1721,7 @@ function createAudioBuffersLoader(source, storage) {
1761
1721
  buffers[key] = value;
1762
1722
  } else if (typeof value === "string") {
1763
1723
  const buffer = yield loadAudioBuffer(context, value, storage);
1764
- if (buffer)
1765
- buffers[key] = buffer;
1724
+ if (buffer) buffers[key] = buffer;
1766
1725
  }
1767
1726
  }))
1768
1727
  ]);
@@ -1828,8 +1787,7 @@ var Smolken = class {
1828
1787
  }
1829
1788
  const toStop = typeof sample === "object" ? sample : { stopId: sample };
1830
1789
  const midi = toMidi(toStop.stopId);
1831
- if (!midi)
1832
- return;
1790
+ if (!midi) return;
1833
1791
  toStop.stopId = midi;
1834
1792
  this.player.stop(toStop);
1835
1793
  }
@@ -1852,8 +1810,7 @@ function soundfontInstrumentLoader(url, buffers, group) {
1852
1810
  yield Promise.all(
1853
1811
  noteNames.map((noteName) => __async(this, null, function* () {
1854
1812
  const midi = toMidi(noteName);
1855
- if (!midi)
1856
- return;
1813
+ if (!midi) return;
1857
1814
  const audioData = base64ToArrayBuffer(
1858
1815
  removeBase64Prefix(json[noteName])
1859
1816
  );
@@ -1870,8 +1827,7 @@ function soundfontInstrumentLoader(url, buffers, group) {
1870
1827
  }
1871
1828
  function midiJsToJson(source) {
1872
1829
  const header = source.indexOf("MIDI.Soundfont.");
1873
- if (header < 0)
1874
- throw Error("Invalid MIDI.js Soundfont format");
1830
+ if (header < 0) throw Error("Invalid MIDI.js Soundfont format");
1875
1831
  const start = source.indexOf("=", header) + 2;
1876
1832
  const end = source.lastIndexOf(",");
1877
1833
  return JSON.parse(source.slice(start, end) + "}");
@@ -2022,18 +1978,15 @@ var SOUNDFONT_INSTRUMENTS = [
2022
1978
 
2023
1979
  // src/soundfont/soundfont-loops.ts
2024
1980
  function getGoldstSoundfontLoopsUrl(instrument, kit) {
2025
- if (instrument.startsWith("http"))
2026
- return void 0;
1981
+ if (instrument.startsWith("http")) return void 0;
2027
1982
  return `https://goldst.dev/midi-js-soundfonts/${kit}/${instrument}-loop.json`;
2028
1983
  }
2029
1984
  function fetchSoundfontLoopData(url, sampleRate = 44100) {
2030
1985
  return __async(this, null, function* () {
2031
- if (!url)
2032
- return void 0;
1986
+ if (!url) return void 0;
2033
1987
  try {
2034
1988
  const req = yield fetch(url);
2035
- if (req.status !== 200)
2036
- return;
1989
+ if (req.status !== 200) return;
2037
1990
  const raw = yield req.json();
2038
1991
  const loopData = {};
2039
1992
  Object.keys(raw).forEach((key) => {
@@ -2061,7 +2014,7 @@ var _hasLoops;
2061
2014
  var Soundfont = class {
2062
2015
  constructor(context, options) {
2063
2016
  this.context = context;
2064
- __privateAdd(this, _hasLoops, void 0);
2017
+ __privateAdd(this, _hasLoops);
2065
2018
  this.config = getSoundfontConfig(options);
2066
2019
  this.player = new DefaultPlayer(context, options);
2067
2020
  this.group = createEmptyRegionGroup();
@@ -2100,8 +2053,7 @@ var Soundfont = class {
2100
2053
  this.group,
2101
2054
  typeof sample === "object" ? sample : { note: sample }
2102
2055
  );
2103
- if (!found)
2104
- return () => void 0;
2056
+ if (!found) return () => void 0;
2105
2057
  return this.player.start(found);
2106
2058
  }
2107
2059
  stop(sample) {
@@ -2188,8 +2140,7 @@ var Soundfont2Sampler = class {
2188
2140
  const sf2instrument = (_a = this.soundfont) == null ? void 0 : _a.instruments.find(
2189
2141
  (inst) => inst.header.name === instrumentName
2190
2142
  );
2191
- if (!sf2instrument)
2192
- return;
2143
+ if (!sf2instrument) return;
2193
2144
  const buffers = this.player.buffers;
2194
2145
  const group = {
2195
2146
  regions: []
@@ -2258,11 +2209,11 @@ function loadSoundfont(options) {
2258
2209
 
2259
2210
  // src/splendid-grand-piano.ts
2260
2211
  var BASE_URL2 = "https://danigb.github.io/samples/splendid-grand-piano";
2261
- var _sampleToMidi, sampleToMidi_fn;
2212
+ var _SplendidGrandPiano_instances, sampleToMidi_fn;
2262
2213
  var SplendidGrandPiano = class {
2263
2214
  constructor(context, options) {
2264
2215
  this.context = context;
2265
- __privateAdd(this, _sampleToMidi);
2216
+ __privateAdd(this, _SplendidGrandPiano_instances);
2266
2217
  this.options = Object.assign(
2267
2218
  {
2268
2219
  baseUrl: BASE_URL2,
@@ -2297,9 +2248,8 @@ var SplendidGrandPiano = class {
2297
2248
  start(sampleOrNote) {
2298
2249
  var _a, _b;
2299
2250
  const sample = typeof sampleOrNote === "object" ? __spreadValues({}, sampleOrNote) : { note: sampleOrNote };
2300
- const found = __privateMethod(this, _sampleToMidi, sampleToMidi_fn).call(this, sample);
2301
- if (!found)
2302
- return () => void 0;
2251
+ const found = __privateMethod(this, _SplendidGrandPiano_instances, sampleToMidi_fn).call(this, sample);
2252
+ if (!found) return () => void 0;
2303
2253
  sample.note = found[0];
2304
2254
  sample.stopId = (_a = sample.stopId) != null ? _a : found[1];
2305
2255
  sample.detune = found[2] + ((_b = sample.detune) != null ? _b : this.options.detune);
@@ -2309,28 +2259,24 @@ var SplendidGrandPiano = class {
2309
2259
  return this.player.stop(sample);
2310
2260
  }
2311
2261
  };
2312
- _sampleToMidi = new WeakSet();
2262
+ _SplendidGrandPiano_instances = new WeakSet();
2313
2263
  sampleToMidi_fn = function(sample) {
2314
2264
  var _a;
2315
2265
  const midi = toMidi(sample.note);
2316
- if (!midi)
2317
- return;
2266
+ if (!midi) return;
2318
2267
  const vel = (_a = sample.velocity) != null ? _a : this.options.velocity;
2319
2268
  const layerIdx = LAYERS.findIndex(
2320
2269
  (layer2) => vel >= layer2.vel_range[0] && vel <= layer2.vel_range[1]
2321
2270
  );
2322
2271
  const layer = LAYERS[layerIdx];
2323
- if (!layer)
2324
- return;
2272
+ if (!layer) return;
2325
2273
  return findNearestMidiInLayer(layer.name, midi, this.player.buffers);
2326
2274
  };
2327
2275
  function findNearestMidiInLayer(prefix, midi, buffers) {
2328
2276
  let i = 0;
2329
2277
  while (buffers[prefix + (midi + i)] === void 0 && i < 128) {
2330
- if (i > 0)
2331
- i = -i;
2332
- else
2333
- i = -i + 1;
2278
+ if (i > 0) i = -i;
2279
+ else i = -i + 1;
2334
2280
  }
2335
2281
  return i === 127 ? [prefix + midi, midi, 0] : [prefix + (midi + i), midi, -i * 100];
2336
2282
  }
@@ -2347,8 +2293,7 @@ function splendidGrandPianoLoader(baseUrl, storage, notesToLoad) {
2347
2293
  samples.map((_0) => __async(this, [_0], function* ([midi, name]) {
2348
2294
  const url = `${baseUrl}/${name}.${format}`;
2349
2295
  const buffer = yield loadAudioBuffer(context, url, storage);
2350
- if (buffer)
2351
- buffers[layer.name + midi] = buffer;
2296
+ if (buffer) buffers[layer.name + midi] = buffer;
2352
2297
  }))
2353
2298
  );
2354
2299
  }