mercury-engine 1.0.3 → 1.0.5
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 +45 -3
- package/dist/mercury.js +39 -18
- package/dist/mercury.min.es5.js +1 -1
- package/dist/mercury.min.js +1 -1
- package/examples/basic/index.html +6 -2
- package/examples/interface/index.html +87 -0
- package/examples/midi/index.html +2 -2
- package/examples/samples/freesound-samples.json +6 -0
- package/examples/samples/samples-freesound.html +74 -0
- package/examples/samples/samples-from-json.html +79 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,6 +85,7 @@ Initialize the engine and include a callback function through { onload: }, this
|
|
|
85
85
|
const Engine = Mercury({
|
|
86
86
|
onload: () => {
|
|
87
87
|
console.log('This callback is called when samples are loaded!');
|
|
88
|
+
console.log('The loaded samples:', Engine.getBuffers());
|
|
88
89
|
}
|
|
89
90
|
});
|
|
90
91
|
```
|
|
@@ -125,10 +126,34 @@ Engine.getCode();
|
|
|
125
126
|
Add your own samples from for example a url like raw github or freesound. The url can also contain a .json file that references multiple samples and the sample name.
|
|
126
127
|
|
|
127
128
|
```js
|
|
128
|
-
Engine.addBuffers();
|
|
129
|
+
Engine.addBuffers(files, callback);
|
|
129
130
|
```
|
|
130
131
|
|
|
131
|
-
|
|
132
|
+
For example use a json file containing sample names and urls
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
Engine.addBuffers('https://raw.githubusercontent.com/tmhglnd/mercury-engine/main/examples/samples/freesound-samples.json');
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Or load samples directly by creating an array of urls
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
let s1 = 'https://cdn.freesound.org/previews/671/671221_3797507-lq.mp3';
|
|
142
|
+
let s2 = 'https://cdn.freesound.org/previews/145/145778_2101444-lq.mp3';
|
|
143
|
+
|
|
144
|
+
Engine.addBuffers([s1, s2]);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Add a callback function, this is called when all samples are loaded
|
|
148
|
+
|
|
149
|
+
```js
|
|
150
|
+
Engine.addBuffers('https://someurl.json', () => {
|
|
151
|
+
console.log('This callback is called when samples are loaded!');
|
|
152
|
+
console.log('The loaded samples:', Engine.getBuffers());
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Get the content of all the loaded Buffers, this is returned as a `ToneAudioBuffers` class
|
|
132
157
|
|
|
133
158
|
```js
|
|
134
159
|
Engine.getBuffers();
|
|
@@ -228,11 +253,28 @@ window.addEventListener('mercuryLog', (e) => {
|
|
|
228
253
|
});
|
|
229
254
|
```
|
|
230
255
|
|
|
256
|
+
### DOM elements from P5js
|
|
257
|
+
|
|
258
|
+
It is possible to control parameters from instruments in the Mercury code by writing a string that contains `{}` with the js code inside to get the dom value. For example when using DOM elements from the P5js library, such as sliders, they can be used in the code.
|
|
259
|
+
|
|
260
|
+
```js
|
|
261
|
+
let slider;
|
|
262
|
+
|
|
263
|
+
// p5js setup function
|
|
264
|
+
function setup() {
|
|
265
|
+
noCanvas();
|
|
266
|
+
// create a slider with range 50 - 5000, initial 1000
|
|
267
|
+
slider = createSlider(50, 5000, 1000, 0);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// use the slider value as a cutoff frequency for the filter
|
|
271
|
+
Engine.code(`new synth saw note(0 0) fx(filter low '{slider.value()}' 0.4)`);
|
|
272
|
+
```
|
|
273
|
+
|
|
231
274
|
## 📋 To Do
|
|
232
275
|
|
|
233
276
|
- [ ] Include OSC communcation options via socket.io
|
|
234
277
|
- [ ] Use engine in the Mercury-playground instead of the other code-base
|
|
235
|
-
- [ ] Allow control of parameters via DOM elements
|
|
236
278
|
|
|
237
279
|
## 🔋 Powered By
|
|
238
280
|
|
package/dist/mercury.js
CHANGED
|
@@ -17245,7 +17245,8 @@ class MercuryInterpreter {
|
|
|
17245
17245
|
// return if the code contains any syntax errors
|
|
17246
17246
|
Util.log(`Could not run because of syntax error`);
|
|
17247
17247
|
Util.log(`Please see Help for more information`);
|
|
17248
|
-
return
|
|
17248
|
+
// return the parsetree also if there are errors
|
|
17249
|
+
return this.parse;
|
|
17249
17250
|
}
|
|
17250
17251
|
// if no errors the last evaluated code is stored
|
|
17251
17252
|
this._code = c;
|
|
@@ -17427,6 +17428,8 @@ class MercuryInterpreter {
|
|
|
17427
17428
|
this.p5canvas.display();
|
|
17428
17429
|
});
|
|
17429
17430
|
}
|
|
17431
|
+
// return the parsetree to see from outside
|
|
17432
|
+
return this.parse;
|
|
17430
17433
|
}
|
|
17431
17434
|
}
|
|
17432
17435
|
module.exports = { MercuryInterpreter }
|
|
@@ -17436,7 +17439,6 @@ console.log(`
|
|
|
17436
17439
|
Mercury Engine by Timo Hoogland (c) 2023
|
|
17437
17440
|
more info:
|
|
17438
17441
|
https://www.timohoogland.com
|
|
17439
|
-
https://mercury.timohoogland.com
|
|
17440
17442
|
https://github.com/tmhglnd/mercury-playground
|
|
17441
17443
|
https://github.com/tmhglnd/mercury-engine
|
|
17442
17444
|
|
|
@@ -17463,7 +17465,7 @@ class Mercury extends MercuryInterpreter {
|
|
|
17463
17465
|
super({ hydra, p5canvas });
|
|
17464
17466
|
|
|
17465
17467
|
// store sample files in buffers
|
|
17466
|
-
this.samples = JSON.parse("{\n \"noise_a\": \"noise/noise_a.wav\",\n \"drone_cymbal\": \"ambient/cymbal/drone_cymbal.wav\",\n \"drone_cymbal_01\": \"ambient/cymbal/drone_cymbal_01.wav\",\n \"clap_808\": \"drums/clap/clap_808.wav\",\n \"clap_808_short\": \"drums/clap/clap_808_short.wav\",\n \"clap_909\": \"drums/clap/clap_909.wav\",\n \"clap_min\": \"drums/clap/clap_min.wav\",\n \"hat_808\": \"drums/hat/hat_808.wav\",\n \"hat_808_open\": \"drums/hat/hat_808_open.wav\",\n \"hat_808_semi\": \"drums/hat/hat_808_semi.wav\",\n \"hat_909\": \"drums/hat/hat_909.wav\",\n \"hat_909_open\": \"drums/hat/hat_909_open.wav\",\n \"hat_909_open_short\": \"drums/hat/hat_909_open_short.wav\",\n \"hat_909_short\": \"drums/hat/hat_909_short.wav\",\n \"hat_click\": \"drums/hat/hat_click.wav\",\n \"hat_dub\": \"drums/hat/hat_dub.wav\",\n \"hat_min\": \"drums/hat/hat_min.wav\",\n \"hat_min_open\": \"drums/hat/hat_min_open.wav\",\n \"kick_808\": \"drums/kick/kick_808.wav\",\n \"kick_808_dist\": \"drums/kick/kick_808_dist.wav\",\n \"kick_909\": \"drums/kick/kick_909.wav\",\n \"kick_909_dist\": \"drums/kick/kick_909_dist.wav\",\n \"kick_909_dist_long\": \"drums/kick/kick_909_dist_long.wav\",\n \"kick_909_long\": \"drums/kick/kick_909_long.wav\",\n \"kick_deep\": \"drums/kick/kick_deep.wav\",\n \"kick_dub\": \"drums/kick/kick_dub.wav\",\n \"kick_house\": \"drums/kick/kick_house.wav\",\n \"kick_min\": \"drums/kick/kick_min.wav\",\n \"kick_sub\": \"drums/kick/kick_sub.wav\",\n \"kick_ua\": \"drums/kick/kick_ua.wav\",\n \"kick_vintage\": \"drums/kick/kick_vintage.wav\",\n \"block\": \"drums/perc/block.wav\",\n \"block_lo\": \"drums/perc/block_lo.wav\",\n \"bongo\": \"drums/perc/bongo.wav\",\n \"bongo_lo\": \"drums/perc/bongo_lo.wav\",\n \"clave_808\": \"drums/perc/clave_808.wav\",\n \"cowbell_808\": \"drums/perc/cowbell_808.wav\",\n \"cymbal_808\": \"drums/perc/cymbal_808.wav\",\n \"maracas_808\": \"drums/perc/maracas_808.wav\",\n \"snare_808\": \"drums/snare/snare_808.wav\",\n \"snare_909\": \"drums/snare/snare_909.wav\",\n \"snare_909_short\": \"drums/snare/snare_909_short.wav\",\n \"snare_ac\": \"drums/snare/snare_ac.wav\",\n \"snare_dnb\": \"drums/snare/snare_dnb.wav\",\n \"snare_dub\": \"drums/snare/snare_dub.wav\",\n \"snare_fat\": \"drums/snare/snare_fat.wav\",\n \"snare_hvy\": \"drums/snare/snare_hvy.wav\",\n \"snare_min\": \"drums/snare/snare_min.wav\",\n \"snare_rock\": \"drums/snare/snare_rock.wav\",\n \"snare_step\": \"drums/snare/snare_step.wav\",\n \"tabla_01\": \"drums/tabla/tabla_01.wav\",\n \"tabla_02\": \"drums/tabla/tabla_02.wav\",\n \"tabla_03\": \"drums/tabla/tabla_03.wav\",\n \"tabla_hi\": \"drums/tabla/tabla_hi.wav\",\n \"tabla_hi_long\": \"drums/tabla/tabla_hi_long.wav\",\n \"tabla_hi_short\": \"drums/tabla/tabla_hi_short.wav\",\n \"tabla_lo\": \"drums/tabla/tabla_lo.wav\",\n \"tabla_lo_long\": \"drums/tabla/tabla_lo_long.wav\",\n \"tabla_lo_short\": \"drums/tabla/tabla_lo_short.wav\",\n \"tabla_mid\": \"drums/tabla/tabla_mid.wav\",\n \"tabla_mid_long\": \"drums/tabla/tabla_mid_long.wav\",\n \"tabla_mid_short\": \"drums/tabla/tabla_mid_short.wav\",\n \"tom_808\": \"drums/tom/tom_808.wav\",\n \"tom_hi\": \"drums/tom/tom_hi.wav\",\n \"tom_lo\": \"drums/tom/tom_lo.wav\",\n \"tom_mid\": \"drums/tom/tom_mid.wav\",\n \"tongue\": \"foley/body/tongue.wav\",\n \"tongue_lo\": \"foley/body/tongue_lo.wav\",\n \"shatter\": \"foley/glass/shatter.wav\",\n \"metal\": \"foley/metal/metal.wav\",\n \"metal_lo\": \"foley/metal/metal_lo.wav\",\n \"wobble\": \"foley/plastic/wobble.wav\",\n \"wobble_02\": \"foley/plastic/wobble_02.wav\",\n \"door\": \"foley/wood/door.wav\",\n \"scrape\": \"foley/wood/scrape.wav\",\n \"scrape_01\": \"foley/wood/scrape_01.wav\",\n \"wood_hit\": \"foley/wood/wood_hit.wav\",\n \"wood_metal\": \"foley/wood/wood_metal.wav\",\n \"wood_plate\": \"foley/wood/wood_plate.wav\",\n \"bell\": \"idiophone/bell/bell.wav\",\n \"chimes\": \"idiophone/chimes/chimes.wav\",\n \"chimes_chord\": \"idiophone/chimes/chimes_chord.wav\",\n \"chimes_chord_01\": \"idiophone/chimes/chimes_chord_01.wav\",\n \"chimes_chord_02\": \"idiophone/chimes/chimes_chord_02.wav\",\n \"chimes_hi\": \"idiophone/chimes/chimes_hi.wav\",\n \"gong_hi\": \"idiophone/gong/gong_hi.wav\",\n \"gong_lo\": \"idiophone/gong/gong_lo.wav\",\n \"kalimba_a\": \"idiophone/kalimba/kalimba_a.wav\",\n \"kalimba_ab\": \"idiophone/kalimba/kalimba_ab.wav\",\n \"kalimba_cis\": \"idiophone/kalimba/kalimba_cis.wav\",\n \"kalimba_e\": \"idiophone/kalimba/kalimba_e.wav\",\n \"kalimba_g\": \"idiophone/kalimba/kalimba_g.wav\",\n \"bamboo_a\": \"idiophone/marimba-bamboo/bamboo_a.wav\",\n \"bamboo_c\": \"idiophone/marimba-bamboo/bamboo_c.wav\",\n \"bamboo_f\": \"idiophone/marimba-bamboo/bamboo_f.wav\",\n \"bamboo_g\": \"idiophone/marimba-bamboo/bamboo_g.wav\",\n \"bowl_hi\": \"idiophone/singing-bowl/bowl_hi.wav\",\n \"bowl_lo\": \"idiophone/singing-bowl/bowl_lo.wav\",\n \"bowl_mid\": \"idiophone/singing-bowl/bowl_mid.wav\",\n \"rhodes_8bit\": \"keys/pad/rhodes_8bit.wav\",\n \"piano_a\": \"keys/piano/piano_a.wav\",\n \"piano_b\": \"keys/piano/piano_b.wav\",\n \"piano_c\": \"keys/piano/piano_c.wav\",\n \"piano_d\": \"keys/piano/piano_d.wav\",\n \"piano_e\": \"keys/piano/piano_e.wav\",\n \"piano_f\": \"keys/piano/piano_f.wav\",\n \"piano_g\": \"keys/piano/piano_g.wav\",\n \"amen\": \"loops/breaks/amen.wav\",\n \"amen_alt\": \"loops/breaks/amen_alt.wav\",\n \"amen_break\": \"loops/breaks/amen_break.wav\",\n \"amen_fill\": \"loops/breaks/amen_fill.wav\",\n \"house\": \"loops/breaks/house.wav\",\n \"chimes_l\": \"loops/chimes/chimes_l.wav\",\n \"noise_c\": \"loops/noise/noise_c.wav\",\n \"noise_e\": \"loops/noise/noise_e.wav\",\n \"noise_e_01\": \"loops/noise/noise_e_01.wav\",\n \"noise_mw\": \"loops/noise/noise_mw.wav\",\n \"noise_p\": \"loops/noise/noise_p.wav\",\n \"noise_r\": \"loops/noise/noise_r.wav\",\n \"choir_01\": \"vocal/choir/choir_01.wav\",\n \"choir_02\": \"vocal/choir/choir_02.wav\",\n \"choir_03\": \"vocal/choir/choir_03.wav\",\n \"choir_o\": \"vocal/choir/choir_o.wav\",\n \"wiper\": \"loops/foley/car/wiper.wav\",\n \"wiper_out\": \"loops/foley/car/wiper_out.wav\",\n \"wood_l\": \"loops/foley/wood/wood_l.wav\",\n \"wood_l_01\": \"loops/foley/wood/wood_l_01.wav\",\n \"violin_a\": \"string/bowed/violin/violin_a.wav\",\n \"violin_b\": \"string/bowed/violin/violin_b.wav\",\n \"violin_c\": \"string/bowed/violin/violin_c.wav\",\n \"violin_d\": \"string/bowed/violin/violin_d.wav\",\n \"violin_e\": \"string/bowed/violin/violin_e.wav\",\n \"violin_f\": \"string/bowed/violin/violin_f.wav\",\n \"violin_g\": \"string/bowed/violin/violin_g.wav\",\n \"harp_down\": \"string/plucked/harp/harp_down.wav\",\n \"harp_up\": \"string/plucked/harp/harp_up.wav\",\n \"pluck_a\": \"string/plucked/violin/pluck_a.wav\",\n \"pluck_b\": \"string/plucked/violin/pluck_b.wav\",\n \"pluck_c\": \"string/plucked/violin/pluck_c.wav\",\n \"pluck_d\": \"string/plucked/violin/pluck_d.wav\",\n \"pluck_e\": \"string/plucked/violin/pluck_e.wav\",\n \"pluck_f\": \"string/plucked/violin/pluck_f.wav\",\n \"pluck_g\": \"string/plucked/violin/pluck_g.wav\"\n}\n");
|
|
17468
|
+
this.samples = JSON.parse("{\n \"_base\": \"https://raw.githubusercontent.com/tmhglnd/mercury-playground/main/public/assets/samples/\",\n \"noise_a\": \"noise/noise_a.wav\",\n \"drone_cymbal\": \"ambient/cymbal/drone_cymbal.wav\",\n \"drone_cymbal_01\": \"ambient/cymbal/drone_cymbal_01.wav\",\n \"clap_808\": \"drums/clap/clap_808.wav\",\n \"clap_808_short\": \"drums/clap/clap_808_short.wav\",\n \"clap_909\": \"drums/clap/clap_909.wav\",\n \"clap_min\": \"drums/clap/clap_min.wav\",\n \"hat_808\": \"drums/hat/hat_808.wav\",\n \"hat_808_open\": \"drums/hat/hat_808_open.wav\",\n \"hat_808_semi\": \"drums/hat/hat_808_semi.wav\",\n \"hat_909\": \"drums/hat/hat_909.wav\",\n \"hat_909_open\": \"drums/hat/hat_909_open.wav\",\n \"hat_909_open_short\": \"drums/hat/hat_909_open_short.wav\",\n \"hat_909_short\": \"drums/hat/hat_909_short.wav\",\n \"hat_click\": \"drums/hat/hat_click.wav\",\n \"hat_dub\": \"drums/hat/hat_dub.wav\",\n \"hat_min\": \"drums/hat/hat_min.wav\",\n \"hat_min_open\": \"drums/hat/hat_min_open.wav\",\n \"kick_808\": \"drums/kick/kick_808.wav\",\n \"kick_808_dist\": \"drums/kick/kick_808_dist.wav\",\n \"kick_909\": \"drums/kick/kick_909.wav\",\n \"kick_909_dist\": \"drums/kick/kick_909_dist.wav\",\n \"kick_909_dist_long\": \"drums/kick/kick_909_dist_long.wav\",\n \"kick_909_long\": \"drums/kick/kick_909_long.wav\",\n \"kick_deep\": \"drums/kick/kick_deep.wav\",\n \"kick_dub\": \"drums/kick/kick_dub.wav\",\n \"kick_house\": \"drums/kick/kick_house.wav\",\n \"kick_min\": \"drums/kick/kick_min.wav\",\n \"kick_sub\": \"drums/kick/kick_sub.wav\",\n \"kick_ua\": \"drums/kick/kick_ua.wav\",\n \"kick_vintage\": \"drums/kick/kick_vintage.wav\",\n \"block\": \"drums/perc/block.wav\",\n \"block_lo\": \"drums/perc/block_lo.wav\",\n \"bongo\": \"drums/perc/bongo.wav\",\n \"bongo_lo\": \"drums/perc/bongo_lo.wav\",\n \"clave_808\": \"drums/perc/clave_808.wav\",\n \"cowbell_808\": \"drums/perc/cowbell_808.wav\",\n \"cymbal_808\": \"drums/perc/cymbal_808.wav\",\n \"maracas_808\": \"drums/perc/maracas_808.wav\",\n \"snare_808\": \"drums/snare/snare_808.wav\",\n \"snare_909\": \"drums/snare/snare_909.wav\",\n \"snare_909_short\": \"drums/snare/snare_909_short.wav\",\n \"snare_ac\": \"drums/snare/snare_ac.wav\",\n \"snare_dnb\": \"drums/snare/snare_dnb.wav\",\n \"snare_dub\": \"drums/snare/snare_dub.wav\",\n \"snare_fat\": \"drums/snare/snare_fat.wav\",\n \"snare_hvy\": \"drums/snare/snare_hvy.wav\",\n \"snare_min\": \"drums/snare/snare_min.wav\",\n \"snare_rock\": \"drums/snare/snare_rock.wav\",\n \"snare_step\": \"drums/snare/snare_step.wav\",\n \"tabla_01\": \"drums/tabla/tabla_01.wav\",\n \"tabla_02\": \"drums/tabla/tabla_02.wav\",\n \"tabla_03\": \"drums/tabla/tabla_03.wav\",\n \"tabla_hi\": \"drums/tabla/tabla_hi.wav\",\n \"tabla_hi_long\": \"drums/tabla/tabla_hi_long.wav\",\n \"tabla_hi_short\": \"drums/tabla/tabla_hi_short.wav\",\n \"tabla_lo\": \"drums/tabla/tabla_lo.wav\",\n \"tabla_lo_long\": \"drums/tabla/tabla_lo_long.wav\",\n \"tabla_lo_short\": \"drums/tabla/tabla_lo_short.wav\",\n \"tabla_mid\": \"drums/tabla/tabla_mid.wav\",\n \"tabla_mid_long\": \"drums/tabla/tabla_mid_long.wav\",\n \"tabla_mid_short\": \"drums/tabla/tabla_mid_short.wav\",\n \"tom_808\": \"drums/tom/tom_808.wav\",\n \"tom_hi\": \"drums/tom/tom_hi.wav\",\n \"tom_lo\": \"drums/tom/tom_lo.wav\",\n \"tom_mid\": \"drums/tom/tom_mid.wav\",\n \"tongue\": \"foley/body/tongue.wav\",\n \"tongue_lo\": \"foley/body/tongue_lo.wav\",\n \"shatter\": \"foley/glass/shatter.wav\",\n \"metal\": \"foley/metal/metal.wav\",\n \"metal_lo\": \"foley/metal/metal_lo.wav\",\n \"wobble\": \"foley/plastic/wobble.wav\",\n \"wobble_02\": \"foley/plastic/wobble_02.wav\",\n \"door\": \"foley/wood/door.wav\",\n \"scrape\": \"foley/wood/scrape.wav\",\n \"scrape_01\": \"foley/wood/scrape_01.wav\",\n \"wood_hit\": \"foley/wood/wood_hit.wav\",\n \"wood_metal\": \"foley/wood/wood_metal.wav\",\n \"wood_plate\": \"foley/wood/wood_plate.wav\",\n \"bell\": \"idiophone/bell/bell.wav\",\n \"chimes\": \"idiophone/chimes/chimes.wav\",\n \"chimes_chord\": \"idiophone/chimes/chimes_chord.wav\",\n \"chimes_chord_01\": \"idiophone/chimes/chimes_chord_01.wav\",\n \"chimes_chord_02\": \"idiophone/chimes/chimes_chord_02.wav\",\n \"chimes_hi\": \"idiophone/chimes/chimes_hi.wav\",\n \"gong_hi\": \"idiophone/gong/gong_hi.wav\",\n \"gong_lo\": \"idiophone/gong/gong_lo.wav\",\n \"kalimba_a\": \"idiophone/kalimba/kalimba_a.wav\",\n \"kalimba_ab\": \"idiophone/kalimba/kalimba_ab.wav\",\n \"kalimba_cis\": \"idiophone/kalimba/kalimba_cis.wav\",\n \"kalimba_e\": \"idiophone/kalimba/kalimba_e.wav\",\n \"kalimba_g\": \"idiophone/kalimba/kalimba_g.wav\",\n \"bamboo_a\": \"idiophone/marimba-bamboo/bamboo_a.wav\",\n \"bamboo_c\": \"idiophone/marimba-bamboo/bamboo_c.wav\",\n \"bamboo_f\": \"idiophone/marimba-bamboo/bamboo_f.wav\",\n \"bamboo_g\": \"idiophone/marimba-bamboo/bamboo_g.wav\",\n \"bowl_hi\": \"idiophone/singing-bowl/bowl_hi.wav\",\n \"bowl_lo\": \"idiophone/singing-bowl/bowl_lo.wav\",\n \"bowl_mid\": \"idiophone/singing-bowl/bowl_mid.wav\",\n \"rhodes_8bit\": \"keys/pad/rhodes_8bit.wav\",\n \"piano_a\": \"keys/piano/piano_a.wav\",\n \"piano_b\": \"keys/piano/piano_b.wav\",\n \"piano_c\": \"keys/piano/piano_c.wav\",\n \"piano_d\": \"keys/piano/piano_d.wav\",\n \"piano_e\": \"keys/piano/piano_e.wav\",\n \"piano_f\": \"keys/piano/piano_f.wav\",\n \"piano_g\": \"keys/piano/piano_g.wav\",\n \"amen\": \"loops/breaks/amen.wav\",\n \"amen_alt\": \"loops/breaks/amen_alt.wav\",\n \"amen_break\": \"loops/breaks/amen_break.wav\",\n \"amen_fill\": \"loops/breaks/amen_fill.wav\",\n \"house\": \"loops/breaks/house.wav\",\n \"chimes_l\": \"loops/chimes/chimes_l.wav\",\n \"noise_c\": \"loops/noise/noise_c.wav\",\n \"noise_e\": \"loops/noise/noise_e.wav\",\n \"noise_e_01\": \"loops/noise/noise_e_01.wav\",\n \"noise_mw\": \"loops/noise/noise_mw.wav\",\n \"noise_p\": \"loops/noise/noise_p.wav\",\n \"noise_r\": \"loops/noise/noise_r.wav\",\n \"choir_01\": \"vocal/choir/choir_01.wav\",\n \"choir_02\": \"vocal/choir/choir_02.wav\",\n \"choir_03\": \"vocal/choir/choir_03.wav\",\n \"choir_o\": \"vocal/choir/choir_o.wav\",\n \"wiper\": \"loops/foley/car/wiper.wav\",\n \"wiper_out\": \"loops/foley/car/wiper_out.wav\",\n \"wood_l\": \"loops/foley/wood/wood_l.wav\",\n \"wood_l_01\": \"loops/foley/wood/wood_l_01.wav\",\n \"violin_a\": \"string/bowed/violin/violin_a.wav\",\n \"violin_b\": \"string/bowed/violin/violin_b.wav\",\n \"violin_c\": \"string/bowed/violin/violin_c.wav\",\n \"violin_d\": \"string/bowed/violin/violin_d.wav\",\n \"violin_e\": \"string/bowed/violin/violin_e.wav\",\n \"violin_f\": \"string/bowed/violin/violin_f.wav\",\n \"violin_g\": \"string/bowed/violin/violin_g.wav\",\n \"harp_down\": \"string/plucked/harp/harp_down.wav\",\n \"harp_up\": \"string/plucked/harp/harp_up.wav\",\n \"pluck_a\": \"string/plucked/violin/pluck_a.wav\",\n \"pluck_b\": \"string/plucked/violin/pluck_b.wav\",\n \"pluck_c\": \"string/plucked/violin/pluck_c.wav\",\n \"pluck_d\": \"string/plucked/violin/pluck_d.wav\",\n \"pluck_e\": \"string/plucked/violin/pluck_e.wav\",\n \"pluck_f\": \"string/plucked/violin/pluck_f.wav\",\n \"pluck_g\": \"string/plucked/violin/pluck_g.wav\"\n}\n");
|
|
17467
17469
|
|
|
17468
17470
|
// this.buffers = new Tone.ToneAudioBuffers();
|
|
17469
17471
|
// add the buffers via function
|
|
@@ -17492,17 +17494,26 @@ class Mercury extends MercuryInterpreter {
|
|
|
17492
17494
|
this.setLowPass(5);
|
|
17493
17495
|
this.setCrossFade(250);
|
|
17494
17496
|
|
|
17497
|
+
// get the base url and add to the sample locations
|
|
17498
|
+
this.baseUrl = this.samples['_base'];
|
|
17499
|
+
delete this.samples['_base'];
|
|
17500
|
+
Object.keys(this.samples).forEach((s) => {
|
|
17501
|
+
this.samples[s] = this.baseUrl + this.samples[s];
|
|
17502
|
+
});
|
|
17495
17503
|
// load the buffers from the github
|
|
17496
17504
|
this.buffers = new Tone.ToneAudioBuffers({
|
|
17497
17505
|
urls: this.samples,
|
|
17498
|
-
baseUrl: "https://raw.githubusercontent.com/tmhglnd/mercury-playground/main/public/assets/samples/",
|
|
17499
17506
|
onload: () => {
|
|
17500
|
-
console.log('Samples loaded', this.buffers);
|
|
17507
|
+
// console.log('Samples loaded', this.buffers);
|
|
17501
17508
|
// executes a callback from the class constructor
|
|
17502
17509
|
// if a callback is provided
|
|
17503
17510
|
if (onload){ onload(); }
|
|
17504
17511
|
}
|
|
17505
17512
|
});
|
|
17513
|
+
// this.buffers = new Tone.ToneAudioBuffers();
|
|
17514
|
+
// this.addBuffers('https://raw.githubusercontent.com/tmhglnd/mercury-engine/main/src/data/samples.json', () => {
|
|
17515
|
+
// console.log('Samples loaded', this.buffers._buffers.keys());
|
|
17516
|
+
// });
|
|
17506
17517
|
|
|
17507
17518
|
// the midi status, inputs and outputs
|
|
17508
17519
|
this.midi = { enabled: false, inputs: [], outputs: [] };
|
|
@@ -17587,36 +17598,46 @@ class Mercury extends MercuryInterpreter {
|
|
|
17587
17598
|
|
|
17588
17599
|
// add files to the buffer from a single File Link
|
|
17589
17600
|
// an array or file paths, or a json of { name:file, ... }
|
|
17590
|
-
|
|
17601
|
+
// optional callback function called when all files are loaded
|
|
17602
|
+
addBuffers(uploads, callback){
|
|
17603
|
+
// make sure uploades is an array to iterate over
|
|
17604
|
+
uploads = Array.isArray(uploads)? uploads : [uploads];
|
|
17605
|
+
|
|
17606
|
+
let promises = [];
|
|
17607
|
+
|
|
17591
17608
|
// for every file from uploads
|
|
17592
|
-
uploads.forEach((
|
|
17593
|
-
let n =
|
|
17594
|
-
let url =
|
|
17595
|
-
if (
|
|
17609
|
+
uploads.forEach((file) => {
|
|
17610
|
+
let n = file;
|
|
17611
|
+
let url = file;
|
|
17612
|
+
if (file.name){
|
|
17596
17613
|
// get the filename from File object
|
|
17597
|
-
n =
|
|
17598
|
-
url = URL.createObjectURL(
|
|
17614
|
+
n = file.name;
|
|
17615
|
+
url = URL.createObjectURL(file);
|
|
17599
17616
|
}
|
|
17600
|
-
if (Array.isArray(
|
|
17617
|
+
if (Array.isArray(file)){
|
|
17601
17618
|
// if array use first value as the name
|
|
17602
|
-
n =
|
|
17603
|
-
url =
|
|
17619
|
+
n = file[0];
|
|
17620
|
+
url = file[1];
|
|
17604
17621
|
}
|
|
17605
17622
|
if (n.endsWith('.json')){
|
|
17606
17623
|
// read from json if loaded is a json file
|
|
17607
|
-
this.addBufferFromJson(url);
|
|
17624
|
+
promises.push(Promise.resolve(this.addBufferFromJson(url)));
|
|
17608
17625
|
} else {
|
|
17609
17626
|
// otherwise read the soundfile regularly
|
|
17610
|
-
this.addBufferFromURL(url, n);
|
|
17627
|
+
promises.push(Promise.resolve(this.addBufferFromURL(url, n)));
|
|
17611
17628
|
}
|
|
17612
17629
|
});
|
|
17630
|
+
|
|
17631
|
+
Promise.all(promises).then((values, reject) => {
|
|
17632
|
+
if (callback) { callback(); }
|
|
17633
|
+
});
|
|
17613
17634
|
}
|
|
17614
17635
|
|
|
17615
17636
|
// add a single file to the buffer from URL
|
|
17616
17637
|
// use the name as reference in the buffer
|
|
17617
17638
|
// if name is undefined it will be constructed from the URL
|
|
17618
17639
|
//
|
|
17619
|
-
addBufferFromURL(url, n){
|
|
17640
|
+
async addBufferFromURL(url, n){
|
|
17620
17641
|
// get file name from url string
|
|
17621
17642
|
n = n.split('\\').pop().split('/').pop();
|
|
17622
17643
|
// remove extension
|