smplr 0.4.1 → 0.4.3
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 +23 -1
- package/dist/index.d.ts +4 -13
- package/dist/index.js +17 -166
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -161
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -178,7 +178,7 @@ 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, getSoundfontNames } from "smplr";
|
|
182
182
|
|
|
183
183
|
const marimba = new Soundfont(new AudioContext(), { instrument: "marimba" });
|
|
184
184
|
marimba.start({ note: "C4" });
|
|
@@ -186,6 +186,28 @@ marimba.start({ note: "C4" });
|
|
|
186
186
|
|
|
187
187
|
It's intended to be a modern replacement of [soundfont-player](https://github.com/danigb/soundfont-player)
|
|
188
188
|
|
|
189
|
+
#### Soundfont instruments and kits
|
|
190
|
+
|
|
191
|
+
Use `getSoundfontNames` to get all available instrument names.
|
|
192
|
+
|
|
193
|
+
Two kits are available: `MusyngKit` or `FluidR3_GM`. The first is used by default: it sounds better but it weights more.
|
|
194
|
+
|
|
195
|
+
```js
|
|
196
|
+
const marimba = new Soundfont(context, {
|
|
197
|
+
instrument: "clavinet",
|
|
198
|
+
kit: "FluidR3_GM", // "MusyngKit" is used by default if not specified
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Alternatively, you can pass your custom url as the instrument. In that case, the `kit` is ignored:
|
|
203
|
+
|
|
204
|
+
```js
|
|
205
|
+
const marimba = new Soundfont(context, {
|
|
206
|
+
instrument:
|
|
207
|
+
"https://gleitz.github.io/midi-js-soundfonts/MusyngKite/marimba-mp3.js",
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
189
211
|
### Piano
|
|
190
212
|
|
|
191
213
|
A sampled acoustic piano. It uses Steinway samples with 4 velocity layers from
|
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
|
|
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
|
-
|
|
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
|
|
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 getSoundfontNames(): 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 {
|
|
261
|
+
export { DrumMachine, DrumMachineConfig, ElectricPiano, LAYERS, Mallet, NAME_TO_PATH, Reverb, Sampler, SamplerAudioLoader, SamplerConfig, SamplerNote, Soundfont, SoundfontConfig, SplendidGrandPiano, SplendidGrandPianoConfig, getDrumMachineNames, getElectricPianoNames, getMalletNames, getSoundfontNames };
|
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
|
-
|
|
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
|
-
|
|
90
|
+
getSoundfontNames: () => getSoundfontNames
|
|
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(
|
|
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 (!
|
|
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 +
|
|
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
|
|
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,7 @@ _output3 = new WeakMap();
|
|
|
912
909
|
var Soundfont = class extends Sampler {
|
|
913
910
|
constructor(context, options) {
|
|
914
911
|
var _a, _b;
|
|
915
|
-
const
|
|
916
|
-
const url = urlBuilder(options.instrument);
|
|
912
|
+
const url = options.instrument.startsWith("http") ? options.instrument : gleitzKitUrl(options.instrument, options.kit);
|
|
917
913
|
super(context, {
|
|
918
914
|
destination: options.destination,
|
|
919
915
|
detune: options.detune,
|
|
@@ -932,9 +928,6 @@ var Soundfont = class extends Sampler {
|
|
|
932
928
|
this.output.addInsert(gain);
|
|
933
929
|
}
|
|
934
930
|
};
|
|
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
931
|
function soundfontLoader(url) {
|
|
939
932
|
return (context, buffers) => __async(this, null, function* () {
|
|
940
933
|
const sourceFile = yield (yield fetch(url)).text();
|
|
@@ -974,148 +967,13 @@ function base64ToArrayBuffer(base64) {
|
|
|
974
967
|
}
|
|
975
968
|
return bytes.buffer;
|
|
976
969
|
}
|
|
977
|
-
function gleitzKitUrl(
|
|
970
|
+
function gleitzKitUrl(name, kit = "MusyngKite") {
|
|
971
|
+
var _a;
|
|
972
|
+
const format = (_a = findFirstSupportedFormat(["ogg", "mp3"])) != null ? _a : "mp3";
|
|
978
973
|
return `https://gleitz.github.io/midi-js-soundfonts/${kit}/${name}-${format}.js`;
|
|
979
974
|
}
|
|
980
|
-
|
|
981
|
-
|
|
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: [
|
|
975
|
+
function getSoundfontNames() {
|
|
976
|
+
return [
|
|
1119
977
|
"accordion",
|
|
1120
978
|
"acoustic_bass",
|
|
1121
979
|
"acoustic_grand_piano",
|
|
@@ -1244,12 +1102,8 @@ var MusyngKite = {
|
|
|
1244
1102
|
"whistle",
|
|
1245
1103
|
"woodblock",
|
|
1246
1104
|
"xylophone"
|
|
1247
|
-
]
|
|
1248
|
-
}
|
|
1249
|
-
var SoundfontLibraries = {
|
|
1250
|
-
FluidR3,
|
|
1251
|
-
MusyngKite
|
|
1252
|
-
};
|
|
1105
|
+
];
|
|
1106
|
+
}
|
|
1253
1107
|
|
|
1254
1108
|
// src/splendid-grand-piano.ts
|
|
1255
1109
|
var BASE_URL2 = "https://danigb.github.io/samples/splendid-grand-piano";
|
|
@@ -1645,21 +1499,18 @@ var LAYERS = [
|
|
|
1645
1499
|
];
|
|
1646
1500
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1647
1501
|
0 && (module.exports = {
|
|
1648
|
-
DATA,
|
|
1649
1502
|
DrumMachine,
|
|
1650
1503
|
ElectricPiano,
|
|
1651
|
-
FluidR3,
|
|
1652
1504
|
LAYERS,
|
|
1653
1505
|
Mallet,
|
|
1654
|
-
|
|
1506
|
+
NAME_TO_PATH,
|
|
1655
1507
|
Reverb,
|
|
1656
1508
|
Sampler,
|
|
1657
1509
|
Soundfont,
|
|
1658
|
-
SoundfontLibraries,
|
|
1659
1510
|
SplendidGrandPiano,
|
|
1660
1511
|
getDrumMachineNames,
|
|
1661
1512
|
getElectricPianoNames,
|
|
1662
1513
|
getMalletNames,
|
|
1663
|
-
|
|
1514
|
+
getSoundfontNames
|
|
1664
1515
|
});
|
|
1665
1516
|
//# sourceMappingURL=index.js.map
|