smplr 0.4.1 → 0.4.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/README.md CHANGED
@@ -178,12 +178,14 @@ A Soundfont player. By default it loads audio from Benjamin Gleitzman's package
178
178
  [pre-rendered sound fonts](https://github.com/gleitz/midi-js-soundfonts).
179
179
 
180
180
  ```js
181
- import { Soundfont } from "smplr";
181
+ import { Soundfont, getSoundfontInstrumentNames } from "smplr";
182
182
 
183
183
  const marimba = new Soundfont(new AudioContext(), { instrument: "marimba" });
184
184
  marimba.start({ note: "C4" });
185
185
  ```
186
186
 
187
+ Use `getSoundfontInstrumentNames` to get all available instrument names.
188
+
187
189
  It's intended to be a modern replacement of [soundfont-player](https://github.com/danigb/soundfont-player)
188
190
 
189
191
  ### Piano
package/dist/index.d.ts CHANGED
@@ -199,7 +199,7 @@ declare class Mallet extends SfzSampler {
199
199
  instrument: string;
200
200
  });
201
201
  }
202
- declare const DATA: Record<string, string | undefined>;
202
+ declare const NAME_TO_PATH: Record<string, string | undefined>;
203
203
 
204
204
  declare const PARAMS: readonly ["preDelay", "bandwidth", "inputDiffusion1", "inputDiffusion2", "decay", "decayDiffusion1", "decayDiffusion2", "damping", "excursionRate", "excursionDepth", "wet", "dry"];
205
205
  declare class Reverb {
@@ -214,7 +214,7 @@ declare class Reverb {
214
214
  }
215
215
 
216
216
  type SoundfontConfig = {
217
- library: SoundfontLibrary | LibraryUrlBuilder;
217
+ kit: "FluidR3_GM" | "MusyngKite";
218
218
  instrument: string;
219
219
  destination: AudioNode;
220
220
  detune: number;
@@ -229,16 +229,7 @@ declare class Soundfont extends Sampler {
229
229
  instrument: string;
230
230
  });
231
231
  }
232
- declare function gleitzKitUrl(kit: "FluidR3_GM" | "MusyngKite", name: string, format: string): string;
233
- type LibraryUrlBuilder = (instrument: string, format?: string) => string;
234
- type SoundfontLibrary = {
235
- name: string;
236
- url: (name: string, format?: "ogg" | "mp3") => string;
237
- instruments: string[];
238
- };
239
- declare const FluidR3: SoundfontLibrary;
240
- declare const MusyngKite: SoundfontLibrary;
241
- declare const SoundfontLibraries: Record<string, SoundfontLibrary>;
232
+ declare function getSoundfontInstrumentNames(): string[];
242
233
 
243
234
  /**
244
235
  * Splendid Grand Piano options
@@ -267,4 +258,4 @@ declare const LAYERS: ({
267
258
  cutoff?: undefined;
268
259
  })[];
269
260
 
270
- export { DATA, DrumMachine, DrumMachineConfig, ElectricPiano, FluidR3, LAYERS, LibraryUrlBuilder, Mallet, MusyngKite, Reverb, Sampler, SamplerAudioLoader, SamplerConfig, SamplerNote, Soundfont, SoundfontConfig, SoundfontLibraries, SoundfontLibrary, SplendidGrandPiano, SplendidGrandPianoConfig, getDrumMachineNames, getElectricPianoNames, getMalletNames, gleitzKitUrl };
261
+ export { DrumMachine, DrumMachineConfig, ElectricPiano, LAYERS, Mallet, NAME_TO_PATH, Reverb, Sampler, SamplerAudioLoader, SamplerConfig, SamplerNote, Soundfont, SoundfontConfig, SplendidGrandPiano, SplendidGrandPianoConfig, getDrumMachineNames, getElectricPianoNames, getMalletNames, getSoundfontInstrumentNames };
package/dist/index.js CHANGED
@@ -75,22 +75,19 @@ var __async = (__this, __arguments, generator) => {
75
75
  // src/index.ts
76
76
  var src_exports = {};
77
77
  __export(src_exports, {
78
- DATA: () => DATA,
79
78
  DrumMachine: () => DrumMachine,
80
79
  ElectricPiano: () => ElectricPiano,
81
- FluidR3: () => FluidR3,
82
80
  LAYERS: () => LAYERS,
83
81
  Mallet: () => Mallet,
84
- MusyngKite: () => MusyngKite,
82
+ NAME_TO_PATH: () => NAME_TO_PATH,
85
83
  Reverb: () => Reverb,
86
84
  Sampler: () => Sampler,
87
85
  Soundfont: () => Soundfont,
88
- SoundfontLibraries: () => SoundfontLibraries,
89
86
  SplendidGrandPiano: () => SplendidGrandPiano,
90
87
  getDrumMachineNames: () => getDrumMachineNames,
91
88
  getElectricPianoNames: () => getElectricPianoNames,
92
89
  getMalletNames: () => getMalletNames,
93
- gleitzKitUrl: () => gleitzKitUrl
90
+ getSoundfontInstrumentNames: () => getSoundfontInstrumentNames
94
91
  });
95
92
  module.exports = __toCommonJS(src_exports);
96
93
 
@@ -402,7 +399,7 @@ var Sampler = class {
402
399
  );
403
400
  const buffer = this.buffers[sample];
404
401
  if (!buffer) {
405
- console.warn(`Sample not found: ${sample}`);
402
+ console.warn(`Sample not found: '${sample}'`);
406
403
  return () => void 0;
407
404
  }
408
405
  return startSample({
@@ -797,7 +794,7 @@ var ElectricPiano = class extends SfzSampler {
797
794
 
798
795
  // src/mallet.ts
799
796
  function getMalletNames() {
800
- return Object.keys(DATA);
797
+ return Object.keys(NAME_TO_PATH);
801
798
  }
802
799
  var Mallet = class extends SfzSampler {
803
800
  constructor(context, options) {
@@ -808,16 +805,16 @@ var Mallet = class extends SfzSampler {
808
805
  }
809
806
  };
810
807
  function getMallet(name) {
811
- if (!DATA[name])
808
+ if (!NAME_TO_PATH[name])
812
809
  throw Error(`Mallet instrument "${name}" not valid`);
813
810
  return {
814
811
  name,
815
- websfzUrl: BASE_URL + DATA[name] + EXT
812
+ websfzUrl: BASE_URL + NAME_TO_PATH[name] + EXT
816
813
  };
817
814
  }
818
815
  var BASE_URL = "https://danigb.github.io/samples/vcsl/";
819
816
  var EXT = ".websfz.json";
820
- var DATA = {
817
+ var NAME_TO_PATH = {
821
818
  "Balafon - Hard Mallet": "Struck Idiophones/balafon-hard-mallet",
822
819
  "Balafon - Keyswitch": "Struck Idiophones/balafon-keyswitch",
823
820
  "Balafon - Soft Mallet": "Struck Idiophones/balafon-soft-mallet",
@@ -912,8 +909,8 @@ _output3 = new WeakMap();
912
909
  var Soundfont = class extends Sampler {
913
910
  constructor(context, options) {
914
911
  var _a, _b;
915
- const urlBuilder = getUrlBuilder(options.library);
916
- const url = urlBuilder(options.instrument);
912
+ const url = options.instrument.startsWith("http") ? options.instrument : gleitzKitUrl(options.instrument, options.kit);
913
+ console.log("!!! URL", { url });
917
914
  super(context, {
918
915
  destination: options.destination,
919
916
  detune: options.detune,
@@ -932,9 +929,6 @@ var Soundfont = class extends Sampler {
932
929
  this.output.addInsert(gain);
933
930
  }
934
931
  };
935
- function getUrlBuilder(library) {
936
- return library === void 0 ? (instrument, format) => gleitzKitUrl("MusyngKite", instrument, format != null ? format : "ogg") : typeof library === "function" ? library : library.url;
937
- }
938
932
  function soundfontLoader(url) {
939
933
  return (context, buffers) => __async(this, null, function* () {
940
934
  const sourceFile = yield (yield fetch(url)).text();
@@ -974,148 +968,13 @@ function base64ToArrayBuffer(base64) {
974
968
  }
975
969
  return bytes.buffer;
976
970
  }
977
- function gleitzKitUrl(kit, name, format) {
971
+ function gleitzKitUrl(name, kit = "MusyngKite") {
972
+ var _a;
973
+ const format = (_a = findFirstSupportedFormat(["ogg", "mp3"])) != null ? _a : "mp3";
978
974
  return `https://gleitz.github.io/midi-js-soundfonts/${kit}/${name}-${format}.js`;
979
975
  }
980
- var FluidR3 = {
981
- name: "FluidR3_GM",
982
- url: (name, format = "mp3") => gleitzKitUrl("FluidR3_GM", name, format),
983
- instruments: [
984
- "accordion",
985
- "acoustic_bass",
986
- "acoustic_grand_piano",
987
- "acoustic_guitar_nylon",
988
- "acoustic_guitar_steel",
989
- "agogo",
990
- "alto_sax",
991
- "applause",
992
- "bagpipe",
993
- "banjo",
994
- "baritone_sax",
995
- "bassoon",
996
- "bird_tweet",
997
- "blown_bottle",
998
- "brass_section",
999
- "breath_noise",
1000
- "bright_acoustic_piano",
1001
- "celesta",
1002
- "cello",
1003
- "choir_aahs",
1004
- "church_organ",
1005
- "clarinet",
1006
- "clavinet",
1007
- "contrabass",
1008
- "distortion_guitar",
1009
- "drawbar_organ",
1010
- "dulcimer",
1011
- "electric_bass_finger",
1012
- "electric_bass_pick",
1013
- "electric_grand_piano",
1014
- "electric_guitar_clean",
1015
- "electric_guitar_jazz",
1016
- "electric_guitar_muted",
1017
- "electric_piano_1",
1018
- "electric_piano_2",
1019
- "english_horn",
1020
- "fiddle",
1021
- "flute",
1022
- "french_horn",
1023
- "fretless_bass",
1024
- "fx_1_rain",
1025
- "fx_2_soundtrack",
1026
- "fx_3_crystal",
1027
- "fx_4_atmosphere",
1028
- "fx_5_brightness",
1029
- "fx_6_goblins",
1030
- "fx_7_echoes",
1031
- "fx_8_scifi",
1032
- "glockenspiel",
1033
- "guitar_fret_noise",
1034
- "guitar_harmonics",
1035
- "gunshot",
1036
- "harmonica",
1037
- "harpsichord",
1038
- "helicopter",
1039
- "honkytonk_piano",
1040
- "kalimba",
1041
- "koto",
1042
- "lead_1_square",
1043
- "lead_2_sawtooth",
1044
- "lead_3_calliope",
1045
- "lead_4_chiff",
1046
- "lead_5_charang",
1047
- "lead_6_voice",
1048
- "lead_7_fifths",
1049
- "lead_8_bass__lead",
1050
- "marimba",
1051
- "melodic_tom",
1052
- "music_box",
1053
- "muted_trumpet",
1054
- "oboe",
1055
- "ocarina",
1056
- "orchestra_hit",
1057
- "orchestral_harp",
1058
- "overdriven_guitar",
1059
- "pad_1_new_age",
1060
- "pad_2_warm",
1061
- "pad_3_polysynth",
1062
- "pad_4_choir",
1063
- "pad_5_bowed",
1064
- "pad_6_metallic",
1065
- "pad_7_halo",
1066
- "pad_8_sweep",
1067
- "pan_flute",
1068
- "percussive_organ",
1069
- "percussion",
1070
- "piccolo",
1071
- "pizzicato_strings",
1072
- "recorder",
1073
- "reed_organ",
1074
- "reverse_cymbal",
1075
- "rock_organ",
1076
- "seashore",
1077
- "shakuhachi",
1078
- "shamisen",
1079
- "shanai",
1080
- "sitar",
1081
- "slap_bass_1",
1082
- "slap_bass_2",
1083
- "soprano_sax",
1084
- "steel_drums",
1085
- "string_ensemble_1",
1086
- "string_ensemble_2",
1087
- "synth_bass_1",
1088
- "synth_bass_2",
1089
- "synth_brass_1",
1090
- "synth_brass_2",
1091
- "synth_choir",
1092
- "synth_drum",
1093
- "synth_strings_1",
1094
- "synth_strings_2",
1095
- "taiko_drum",
1096
- "tango_accordion",
1097
- "telephone_ring",
1098
- "tenor_sax",
1099
- "timpani",
1100
- "tinkle_bell",
1101
- "tremolo_strings",
1102
- "trombone",
1103
- "trumpet",
1104
- "tuba",
1105
- "tubular_bells",
1106
- "vibraphone",
1107
- "viola",
1108
- "violin",
1109
- "voice_oohs",
1110
- "whistle",
1111
- "woodblock",
1112
- "xylophone"
1113
- ]
1114
- };
1115
- var MusyngKite = {
1116
- name: "MusyngKite",
1117
- url: (name, format = "mp3") => gleitzKitUrl("MusyngKite", name, format),
1118
- instruments: [
976
+ function getSoundfontInstrumentNames() {
977
+ return [
1119
978
  "accordion",
1120
979
  "acoustic_bass",
1121
980
  "acoustic_grand_piano",
@@ -1244,12 +1103,8 @@ var MusyngKite = {
1244
1103
  "whistle",
1245
1104
  "woodblock",
1246
1105
  "xylophone"
1247
- ]
1248
- };
1249
- var SoundfontLibraries = {
1250
- FluidR3,
1251
- MusyngKite
1252
- };
1106
+ ];
1107
+ }
1253
1108
 
1254
1109
  // src/splendid-grand-piano.ts
1255
1110
  var BASE_URL2 = "https://danigb.github.io/samples/splendid-grand-piano";
@@ -1645,21 +1500,18 @@ var LAYERS = [
1645
1500
  ];
1646
1501
  // Annotate the CommonJS export names for ESM import in node:
1647
1502
  0 && (module.exports = {
1648
- DATA,
1649
1503
  DrumMachine,
1650
1504
  ElectricPiano,
1651
- FluidR3,
1652
1505
  LAYERS,
1653
1506
  Mallet,
1654
- MusyngKite,
1507
+ NAME_TO_PATH,
1655
1508
  Reverb,
1656
1509
  Sampler,
1657
1510
  Soundfont,
1658
- SoundfontLibraries,
1659
1511
  SplendidGrandPiano,
1660
1512
  getDrumMachineNames,
1661
1513
  getElectricPianoNames,
1662
1514
  getMalletNames,
1663
- gleitzKitUrl
1515
+ getSoundfontInstrumentNames
1664
1516
  });
1665
1517
  //# sourceMappingURL=index.js.map