mercury-engine 1.0.0 → 1.0.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 +3 -3
- package/dist/mercury.js +62 -182
- package/dist/mercury.min.es5.js +1 -1
- package/dist/mercury.min.js +1 -1
- package/examples/basic/index.html +80 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -71,14 +71,14 @@ const Engine = Mercury(() => {
|
|
|
71
71
|
// to play from the browser window
|
|
72
72
|
Engine.resume()
|
|
73
73
|
|
|
74
|
-
// Evaluate a mercury code file by providing
|
|
74
|
+
// Evaluate a mercury code file by providing a string of code
|
|
75
75
|
// This also resumes the transport if .resume() was not called yet
|
|
76
|
-
Engine.code(
|
|
76
|
+
Engine.code(`
|
|
77
77
|
set tempo 100
|
|
78
78
|
new sample kick_909 time(1/4)
|
|
79
79
|
new sample hat_909 time(1/4 1/8) gain(0.6)
|
|
80
80
|
new synth saw note(0 0) time(1/16) shape(1 80)
|
|
81
|
-
`
|
|
81
|
+
`);
|
|
82
82
|
|
|
83
83
|
// stop the transport and silence the audio
|
|
84
84
|
Engine.silence();
|
package/dist/mercury.js
CHANGED
|
@@ -17116,158 +17116,11 @@ module.exports={
|
|
|
17116
17116
|
"neurofunk" : 180
|
|
17117
17117
|
}
|
|
17118
17118
|
},{}],68:[function(require,module,exports){
|
|
17119
|
-
module.exports={
|
|
17120
|
-
"noise_a": "noise/noise_a.wav",
|
|
17121
|
-
"drone_cymbal": "ambient/cymbal/drone_cymbal.wav",
|
|
17122
|
-
"drone_cymbal_01": "ambient/cymbal/drone_cymbal_01.wav",
|
|
17123
|
-
"clap_808": "drums/clap/clap_808.wav",
|
|
17124
|
-
"clap_808_short": "drums/clap/clap_808_short.wav",
|
|
17125
|
-
"clap_909": "drums/clap/clap_909.wav",
|
|
17126
|
-
"clap_min": "drums/clap/clap_min.wav",
|
|
17127
|
-
"hat_808": "drums/hat/hat_808.wav",
|
|
17128
|
-
"hat_808_open": "drums/hat/hat_808_open.wav",
|
|
17129
|
-
"hat_808_semi": "drums/hat/hat_808_semi.wav",
|
|
17130
|
-
"hat_909": "drums/hat/hat_909.wav",
|
|
17131
|
-
"hat_909_open": "drums/hat/hat_909_open.wav",
|
|
17132
|
-
"hat_909_open_short": "drums/hat/hat_909_open_short.wav",
|
|
17133
|
-
"hat_909_short": "drums/hat/hat_909_short.wav",
|
|
17134
|
-
"hat_click": "drums/hat/hat_click.wav",
|
|
17135
|
-
"hat_dub": "drums/hat/hat_dub.wav",
|
|
17136
|
-
"hat_min": "drums/hat/hat_min.wav",
|
|
17137
|
-
"hat_min_open": "drums/hat/hat_min_open.wav",
|
|
17138
|
-
"kick_808": "drums/kick/kick_808.wav",
|
|
17139
|
-
"kick_808_dist": "drums/kick/kick_808_dist.wav",
|
|
17140
|
-
"kick_909": "drums/kick/kick_909.wav",
|
|
17141
|
-
"kick_909_dist": "drums/kick/kick_909_dist.wav",
|
|
17142
|
-
"kick_909_dist_long": "drums/kick/kick_909_dist_long.wav",
|
|
17143
|
-
"kick_909_long": "drums/kick/kick_909_long.wav",
|
|
17144
|
-
"kick_deep": "drums/kick/kick_deep.wav",
|
|
17145
|
-
"kick_dub": "drums/kick/kick_dub.wav",
|
|
17146
|
-
"kick_house": "drums/kick/kick_house.wav",
|
|
17147
|
-
"kick_min": "drums/kick/kick_min.wav",
|
|
17148
|
-
"kick_sub": "drums/kick/kick_sub.wav",
|
|
17149
|
-
"kick_ua": "drums/kick/kick_ua.wav",
|
|
17150
|
-
"kick_vintage": "drums/kick/kick_vintage.wav",
|
|
17151
|
-
"block": "drums/perc/block.wav",
|
|
17152
|
-
"block_lo": "drums/perc/block_lo.wav",
|
|
17153
|
-
"bongo": "drums/perc/bongo.wav",
|
|
17154
|
-
"bongo_lo": "drums/perc/bongo_lo.wav",
|
|
17155
|
-
"clave_808": "drums/perc/clave_808.wav",
|
|
17156
|
-
"cowbell_808": "drums/perc/cowbell_808.wav",
|
|
17157
|
-
"cymbal_808": "drums/perc/cymbal_808.wav",
|
|
17158
|
-
"maracas_808": "drums/perc/maracas_808.wav",
|
|
17159
|
-
"snare_808": "drums/snare/snare_808.wav",
|
|
17160
|
-
"snare_909": "drums/snare/snare_909.wav",
|
|
17161
|
-
"snare_909_short": "drums/snare/snare_909_short.wav",
|
|
17162
|
-
"snare_ac": "drums/snare/snare_ac.wav",
|
|
17163
|
-
"snare_dnb": "drums/snare/snare_dnb.wav",
|
|
17164
|
-
"snare_dub": "drums/snare/snare_dub.wav",
|
|
17165
|
-
"snare_fat": "drums/snare/snare_fat.wav",
|
|
17166
|
-
"snare_hvy": "drums/snare/snare_hvy.wav",
|
|
17167
|
-
"snare_min": "drums/snare/snare_min.wav",
|
|
17168
|
-
"snare_rock": "drums/snare/snare_rock.wav",
|
|
17169
|
-
"snare_step": "drums/snare/snare_step.wav",
|
|
17170
|
-
"tabla_01": "drums/tabla/tabla_01.wav",
|
|
17171
|
-
"tabla_02": "drums/tabla/tabla_02.wav",
|
|
17172
|
-
"tabla_03": "drums/tabla/tabla_03.wav",
|
|
17173
|
-
"tabla_hi": "drums/tabla/tabla_hi.wav",
|
|
17174
|
-
"tabla_hi_long": "drums/tabla/tabla_hi_long.wav",
|
|
17175
|
-
"tabla_hi_short": "drums/tabla/tabla_hi_short.wav",
|
|
17176
|
-
"tabla_lo": "drums/tabla/tabla_lo.wav",
|
|
17177
|
-
"tabla_lo_long": "drums/tabla/tabla_lo_long.wav",
|
|
17178
|
-
"tabla_lo_short": "drums/tabla/tabla_lo_short.wav",
|
|
17179
|
-
"tabla_mid": "drums/tabla/tabla_mid.wav",
|
|
17180
|
-
"tabla_mid_long": "drums/tabla/tabla_mid_long.wav",
|
|
17181
|
-
"tabla_mid_short": "drums/tabla/tabla_mid_short.wav",
|
|
17182
|
-
"tom_808": "drums/tom/tom_808.wav",
|
|
17183
|
-
"tom_hi": "drums/tom/tom_hi.wav",
|
|
17184
|
-
"tom_lo": "drums/tom/tom_lo.wav",
|
|
17185
|
-
"tom_mid": "drums/tom/tom_mid.wav",
|
|
17186
|
-
"tongue": "foley/body/tongue.wav",
|
|
17187
|
-
"tongue_lo": "foley/body/tongue_lo.wav",
|
|
17188
|
-
"shatter": "foley/glass/shatter.wav",
|
|
17189
|
-
"metal": "foley/metal/metal.wav",
|
|
17190
|
-
"metal_lo": "foley/metal/metal_lo.wav",
|
|
17191
|
-
"wobble": "foley/plastic/wobble.wav",
|
|
17192
|
-
"wobble_02": "foley/plastic/wobble_02.wav",
|
|
17193
|
-
"door": "foley/wood/door.wav",
|
|
17194
|
-
"scrape": "foley/wood/scrape.wav",
|
|
17195
|
-
"scrape_01": "foley/wood/scrape_01.wav",
|
|
17196
|
-
"wood_hit": "foley/wood/wood_hit.wav",
|
|
17197
|
-
"wood_metal": "foley/wood/wood_metal.wav",
|
|
17198
|
-
"wood_plate": "foley/wood/wood_plate.wav",
|
|
17199
|
-
"bell": "idiophone/bell/bell.wav",
|
|
17200
|
-
"chimes": "idiophone/chimes/chimes.wav",
|
|
17201
|
-
"chimes_chord": "idiophone/chimes/chimes_chord.wav",
|
|
17202
|
-
"chimes_chord_01": "idiophone/chimes/chimes_chord_01.wav",
|
|
17203
|
-
"chimes_chord_02": "idiophone/chimes/chimes_chord_02.wav",
|
|
17204
|
-
"chimes_hi": "idiophone/chimes/chimes_hi.wav",
|
|
17205
|
-
"gong_hi": "idiophone/gong/gong_hi.wav",
|
|
17206
|
-
"gong_lo": "idiophone/gong/gong_lo.wav",
|
|
17207
|
-
"kalimba_a": "idiophone/kalimba/kalimba_a.wav",
|
|
17208
|
-
"kalimba_ab": "idiophone/kalimba/kalimba_ab.wav",
|
|
17209
|
-
"kalimba_cis": "idiophone/kalimba/kalimba_cis.wav",
|
|
17210
|
-
"kalimba_e": "idiophone/kalimba/kalimba_e.wav",
|
|
17211
|
-
"kalimba_g": "idiophone/kalimba/kalimba_g.wav",
|
|
17212
|
-
"bamboo_a": "idiophone/marimba-bamboo/bamboo_a.wav",
|
|
17213
|
-
"bamboo_c": "idiophone/marimba-bamboo/bamboo_c.wav",
|
|
17214
|
-
"bamboo_f": "idiophone/marimba-bamboo/bamboo_f.wav",
|
|
17215
|
-
"bamboo_g": "idiophone/marimba-bamboo/bamboo_g.wav",
|
|
17216
|
-
"bowl_hi": "idiophone/singing-bowl/bowl_hi.wav",
|
|
17217
|
-
"bowl_lo": "idiophone/singing-bowl/bowl_lo.wav",
|
|
17218
|
-
"bowl_mid": "idiophone/singing-bowl/bowl_mid.wav",
|
|
17219
|
-
"rhodes_8bit": "keys/pad/rhodes_8bit.wav",
|
|
17220
|
-
"piano_a": "keys/piano/piano_a.wav",
|
|
17221
|
-
"piano_b": "keys/piano/piano_b.wav",
|
|
17222
|
-
"piano_c": "keys/piano/piano_c.wav",
|
|
17223
|
-
"piano_d": "keys/piano/piano_d.wav",
|
|
17224
|
-
"piano_e": "keys/piano/piano_e.wav",
|
|
17225
|
-
"piano_f": "keys/piano/piano_f.wav",
|
|
17226
|
-
"piano_g": "keys/piano/piano_g.wav",
|
|
17227
|
-
"amen": "loops/breaks/amen.wav",
|
|
17228
|
-
"amen_alt": "loops/breaks/amen_alt.wav",
|
|
17229
|
-
"amen_break": "loops/breaks/amen_break.wav",
|
|
17230
|
-
"amen_fill": "loops/breaks/amen_fill.wav",
|
|
17231
|
-
"house": "loops/breaks/house.wav",
|
|
17232
|
-
"chimes_l": "loops/chimes/chimes_l.wav",
|
|
17233
|
-
"noise_c": "loops/noise/noise_c.wav",
|
|
17234
|
-
"noise_e": "loops/noise/noise_e.wav",
|
|
17235
|
-
"noise_e_01": "loops/noise/noise_e_01.wav",
|
|
17236
|
-
"noise_mw": "loops/noise/noise_mw.wav",
|
|
17237
|
-
"noise_p": "loops/noise/noise_p.wav",
|
|
17238
|
-
"noise_r": "loops/noise/noise_r.wav",
|
|
17239
|
-
"choir_01": "vocal/choir/choir_01.wav",
|
|
17240
|
-
"choir_02": "vocal/choir/choir_02.wav",
|
|
17241
|
-
"choir_03": "vocal/choir/choir_03.wav",
|
|
17242
|
-
"choir_o": "vocal/choir/choir_o.wav",
|
|
17243
|
-
"wiper": "loops/foley/car/wiper.wav",
|
|
17244
|
-
"wiper_out": "loops/foley/car/wiper_out.wav",
|
|
17245
|
-
"wood_l": "loops/foley/wood/wood_l.wav",
|
|
17246
|
-
"wood_l_01": "loops/foley/wood/wood_l_01.wav",
|
|
17247
|
-
"violin_a": "string/bowed/violin/violin_a.wav",
|
|
17248
|
-
"violin_b": "string/bowed/violin/violin_b.wav",
|
|
17249
|
-
"violin_c": "string/bowed/violin/violin_c.wav",
|
|
17250
|
-
"violin_d": "string/bowed/violin/violin_d.wav",
|
|
17251
|
-
"violin_e": "string/bowed/violin/violin_e.wav",
|
|
17252
|
-
"violin_f": "string/bowed/violin/violin_f.wav",
|
|
17253
|
-
"violin_g": "string/bowed/violin/violin_g.wav",
|
|
17254
|
-
"harp_down": "string/plucked/harp/harp_down.wav",
|
|
17255
|
-
"harp_up": "string/plucked/harp/harp_up.wav",
|
|
17256
|
-
"pluck_a": "string/plucked/violin/pluck_a.wav",
|
|
17257
|
-
"pluck_b": "string/plucked/violin/pluck_b.wav",
|
|
17258
|
-
"pluck_c": "string/plucked/violin/pluck_c.wav",
|
|
17259
|
-
"pluck_d": "string/plucked/violin/pluck_d.wav",
|
|
17260
|
-
"pluck_e": "string/plucked/violin/pluck_e.wav",
|
|
17261
|
-
"pluck_f": "string/plucked/violin/pluck_f.wav",
|
|
17262
|
-
"pluck_g": "string/plucked/violin/pluck_g.wav"
|
|
17263
|
-
}
|
|
17264
|
-
|
|
17265
|
-
},{}],69:[function(require,module,exports){
|
|
17266
17119
|
|
|
17267
17120
|
const Tone = require('tone');
|
|
17268
17121
|
const Mercury = require('mercury-lang');
|
|
17269
17122
|
const TL = require('total-serialism').Translate;
|
|
17270
|
-
|
|
17123
|
+
const Util = require('total-serialism').Utility;
|
|
17271
17124
|
|
|
17272
17125
|
const MonoSample = require('./core/MonoSample.js');
|
|
17273
17126
|
const MonoMidi = require('./core/MonoMidi.js');
|
|
@@ -17278,7 +17131,7 @@ const PolySample = require('./core/PolySample.js');
|
|
|
17278
17131
|
const Tempos = require('./data/genre-tempos.json');
|
|
17279
17132
|
|
|
17280
17133
|
class MercuryInterpreter {
|
|
17281
|
-
constructor(){
|
|
17134
|
+
constructor({ hydra, p5canvas } = {}){
|
|
17282
17135
|
// cross-fade time
|
|
17283
17136
|
this.crossFade = 0.5;
|
|
17284
17137
|
|
|
@@ -17293,6 +17146,10 @@ class MercuryInterpreter {
|
|
|
17293
17146
|
this.parse;
|
|
17294
17147
|
this.tree;
|
|
17295
17148
|
this.errors;
|
|
17149
|
+
|
|
17150
|
+
// Hydra and P5 canvas
|
|
17151
|
+
this.canvas = hydra;
|
|
17152
|
+
this.p5canvas = p5canvas;
|
|
17296
17153
|
}
|
|
17297
17154
|
|
|
17298
17155
|
getSounds(){
|
|
@@ -17329,19 +17186,27 @@ class MercuryInterpreter {
|
|
|
17329
17186
|
s.length = 0;
|
|
17330
17187
|
}
|
|
17331
17188
|
|
|
17332
|
-
|
|
17189
|
+
setCrossFade(f){
|
|
17190
|
+
// set the crossFade in milliseconds
|
|
17191
|
+
this.crossFade = Number(f) / 1000;
|
|
17192
|
+
// log(`Crossfade: ${f}ms`);
|
|
17193
|
+
}
|
|
17194
|
+
|
|
17195
|
+
code(file=''){
|
|
17333
17196
|
// parse and evaluate the inputted code
|
|
17334
17197
|
// as an asyncronous function with promise
|
|
17335
17198
|
let c = (!file)? this._code : file;
|
|
17336
17199
|
this._code = c;
|
|
17337
17200
|
|
|
17338
17201
|
let t = Tone.Transport.seconds;
|
|
17202
|
+
|
|
17339
17203
|
// is this necessary?
|
|
17340
17204
|
// let parser = new Promise((resolve) => {
|
|
17341
17205
|
// return resolve(Mercury(c));
|
|
17342
17206
|
// });
|
|
17343
17207
|
// this.parse = await parser;
|
|
17344
17208
|
this.parse = Mercury(c);
|
|
17209
|
+
|
|
17345
17210
|
console.log(`Evaluated code in: ${((Tone.Transport.seconds-t) * 1000).toFixed(3)}ms`);
|
|
17346
17211
|
|
|
17347
17212
|
this.tree = this.parse.parseTree;
|
|
@@ -17365,17 +17230,6 @@ class MercuryInterpreter {
|
|
|
17365
17230
|
console.log(p);
|
|
17366
17231
|
});
|
|
17367
17232
|
|
|
17368
|
-
// hide canvas and noLoop
|
|
17369
|
-
// p5canvas.hide();
|
|
17370
|
-
|
|
17371
|
-
// handle .display to p5
|
|
17372
|
-
// tree.display.forEach((p) => {
|
|
17373
|
-
// // restart canvas if view is used
|
|
17374
|
-
// let n = Util.mul(Util.normalize(p), 255);
|
|
17375
|
-
// p5canvas.sketch.fillCanvas(n);
|
|
17376
|
-
// p5canvas.display();
|
|
17377
|
-
// });
|
|
17378
|
-
|
|
17379
17233
|
// set timer to check evaluation time
|
|
17380
17234
|
t = Tone.Transport.seconds;
|
|
17381
17235
|
|
|
@@ -17383,9 +17237,7 @@ class MercuryInterpreter {
|
|
|
17383
17237
|
const globalMap = {
|
|
17384
17238
|
'crossFade' : (args) => {
|
|
17385
17239
|
// set crossFade time in ms
|
|
17386
|
-
this.
|
|
17387
|
-
// log(`crossfade time is ${args[0]}ms`);
|
|
17388
|
-
console.log(`Crossfade: ${args[0]}ms`);
|
|
17240
|
+
this.setCrossFade(args[0]);
|
|
17389
17241
|
},
|
|
17390
17242
|
'tempo' : (args) => {
|
|
17391
17243
|
let t = args[0];
|
|
@@ -17397,7 +17249,7 @@ class MercuryInterpreter {
|
|
|
17397
17249
|
}
|
|
17398
17250
|
args[0] = t;
|
|
17399
17251
|
}
|
|
17400
|
-
this.
|
|
17252
|
+
this.setBPM(...args);
|
|
17401
17253
|
// engine.setBPM(...args);
|
|
17402
17254
|
// log(`set bpm to ${bpm}`);
|
|
17403
17255
|
},
|
|
@@ -17450,38 +17302,38 @@ class MercuryInterpreter {
|
|
|
17450
17302
|
// Handling all the different instrument types here
|
|
17451
17303
|
const objectMap = {
|
|
17452
17304
|
'sample' : (obj) => {
|
|
17453
|
-
let inst = new MonoSample(this, obj.type, canvas);
|
|
17305
|
+
let inst = new MonoSample(this, obj.type, this.canvas);
|
|
17454
17306
|
objectMap.applyFunctions(obj.functions, inst, obj.type);
|
|
17455
17307
|
return inst;
|
|
17456
17308
|
},
|
|
17457
17309
|
'loop' : (obj) => {
|
|
17458
|
-
let inst = new MonoSample(this, obj.type, canvas);
|
|
17310
|
+
let inst = new MonoSample(this, obj.type, this.canvas);
|
|
17459
17311
|
objectMap.applyFunctions(obj.functions, inst, obj.type);
|
|
17460
17312
|
return inst;
|
|
17461
17313
|
},
|
|
17462
17314
|
'synth' : (obj) => {
|
|
17463
17315
|
console.log(obj);
|
|
17464
|
-
let inst = new MonoSynth(this, obj.type, canvas);
|
|
17316
|
+
let inst = new MonoSynth(this, obj.type, this.canvas);
|
|
17465
17317
|
objectMap.applyFunctions(obj.functions, inst, obj.type);
|
|
17466
17318
|
return inst;
|
|
17467
17319
|
},
|
|
17468
17320
|
'polySynth' : (obj) => {
|
|
17469
|
-
let inst = new PolySynth(this, obj.type, canvas);
|
|
17321
|
+
let inst = new PolySynth(this, obj.type, this.canvas);
|
|
17470
17322
|
objectMap.applyFunctions(obj.functions, inst, obj.type);
|
|
17471
17323
|
return inst;
|
|
17472
17324
|
},
|
|
17473
17325
|
'polySample' : (obj) => {
|
|
17474
|
-
let inst = new PolySample(this, obj.type, canvas);
|
|
17326
|
+
let inst = new PolySample(this, obj.type, this.canvas);
|
|
17475
17327
|
objectMap.applyFunctions(obj.functions, inst, obj.type);
|
|
17476
17328
|
return inst;
|
|
17477
17329
|
},
|
|
17478
17330
|
'midi' : (obj) => {
|
|
17479
|
-
let inst = new MonoMidi(this, obj.type, canvas);
|
|
17331
|
+
let inst = new MonoMidi(this, obj.type, this.canvas);
|
|
17480
17332
|
objectMap.applyFunctions(obj.functions, inst, obj.type);
|
|
17481
17333
|
return inst;
|
|
17482
17334
|
},
|
|
17483
17335
|
'input' : (obj) => {
|
|
17484
|
-
let inst = new MonoInput(this, obj.type, canvas);
|
|
17336
|
+
let inst = new MonoInput(this, obj.type, this.canvas);
|
|
17485
17337
|
objectMap.applyFunctions(obj.functions, inst, obj.type);
|
|
17486
17338
|
return inst;
|
|
17487
17339
|
},
|
|
@@ -17537,17 +17389,32 @@ class MercuryInterpreter {
|
|
|
17537
17389
|
this.removeSounds(this._sounds, this.crossFade);
|
|
17538
17390
|
|
|
17539
17391
|
this.resume();
|
|
17392
|
+
|
|
17393
|
+
// if p5js canvas is included in the html page
|
|
17394
|
+
if (this.p5canvas){
|
|
17395
|
+
// hide canvas and noLoop
|
|
17396
|
+
this.p5canvas.hide();
|
|
17397
|
+
|
|
17398
|
+
// handle .display to p5
|
|
17399
|
+
tree.display.forEach((p) => {
|
|
17400
|
+
// restart canvas if view is used
|
|
17401
|
+
let n = Util.mul(Util.normalize(p), 255);
|
|
17402
|
+
this.p5canvas.sketch.fillCanvas(n);
|
|
17403
|
+
this.p5canvas.display();
|
|
17404
|
+
});
|
|
17405
|
+
}
|
|
17540
17406
|
}
|
|
17541
17407
|
}
|
|
17542
17408
|
module.exports = { MercuryInterpreter }
|
|
17543
|
-
},{"./core/MonoInput.js":58,"./core/MonoMidi.js":59,"./core/MonoSample.js":60,"./core/MonoSynth.js":61,"./core/PolySample.js":63,"./core/PolySynth.js":64,"./data/genre-tempos.json":67,"mercury-lang":27,"tone":44,"total-serialism":47}],
|
|
17409
|
+
},{"./core/MonoInput.js":58,"./core/MonoMidi.js":59,"./core/MonoSample.js":60,"./core/MonoSynth.js":61,"./core/PolySample.js":63,"./core/PolySynth.js":64,"./data/genre-tempos.json":67,"mercury-lang":27,"tone":44,"total-serialism":47}],69:[function(require,module,exports){
|
|
17544
17410
|
|
|
17545
17411
|
console.log(`
|
|
17546
17412
|
Mercury Engine by Timo Hoogland (c) 2023
|
|
17547
17413
|
more info:
|
|
17548
17414
|
https://www.timohoogland.com
|
|
17549
17415
|
https://mercury.timohoogland.com
|
|
17550
|
-
https://github.com/tmhglnd/mercury
|
|
17416
|
+
https://github.com/tmhglnd/mercury-playground
|
|
17417
|
+
https://github.com/tmhglnd/mercury-engine
|
|
17551
17418
|
|
|
17552
17419
|
`);
|
|
17553
17420
|
|
|
@@ -17564,16 +17431,22 @@ Tone.getContext().addAudioWorkletModule(URL.createObjectURL(new Blob([ fxExtensi
|
|
|
17564
17431
|
// also has the interpreter evaluating the code and adding the instruments
|
|
17565
17432
|
//
|
|
17566
17433
|
class Mercury extends MercuryInterpreter {
|
|
17567
|
-
constructor(
|
|
17568
|
-
// initalize the constructor of inheriting class
|
|
17569
|
-
|
|
17434
|
+
constructor({ onload, hydra, p5canvas } = {}){
|
|
17435
|
+
// initalize the constructor of inheriting class with
|
|
17436
|
+
// optionally a hydra and p5 canvas
|
|
17437
|
+
super({ hydra, p5canvas });
|
|
17438
|
+
|
|
17570
17439
|
// store sample files in buffers
|
|
17571
|
-
this.samples =
|
|
17440
|
+
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");
|
|
17572
17441
|
|
|
17573
17442
|
// this.buffers = new Tone.ToneAudioBuffers();
|
|
17574
17443
|
// add the buffers via function
|
|
17575
17444
|
// this.addBuffers(['http://localhost:8080/mercury-engine/src/data/samples.json'])
|
|
17576
17445
|
|
|
17446
|
+
// setting parameters
|
|
17447
|
+
this.bpm = 100;
|
|
17448
|
+
this.volume = 1;
|
|
17449
|
+
|
|
17577
17450
|
// effects on main output for Tone
|
|
17578
17451
|
this.gain = new Tone.Gain(1);
|
|
17579
17452
|
this.lowPass = new Tone.Filter(18000, 'lowpass');
|
|
@@ -17590,7 +17463,7 @@ class Mercury extends MercuryInterpreter {
|
|
|
17590
17463
|
onload: () => {
|
|
17591
17464
|
console.log('Samples loaded', this.buffers);
|
|
17592
17465
|
// executes a callback from the class constructor
|
|
17593
|
-
if (
|
|
17466
|
+
if (onload){ onload(); }
|
|
17594
17467
|
}
|
|
17595
17468
|
});
|
|
17596
17469
|
}
|
|
@@ -17625,7 +17498,8 @@ class Mercury extends MercuryInterpreter {
|
|
|
17625
17498
|
}
|
|
17626
17499
|
|
|
17627
17500
|
// set the bpm and optionally ramp in milliseconds
|
|
17628
|
-
|
|
17501
|
+
setBPM(bpm, ramp=0) {
|
|
17502
|
+
this.bpm = bpm;
|
|
17629
17503
|
if (ramp > 0){
|
|
17630
17504
|
Tone.Transport.bpm.rampTo(bpm, ramp / 1000);
|
|
17631
17505
|
} else {
|
|
@@ -17641,7 +17515,7 @@ class Mercury extends MercuryInterpreter {
|
|
|
17641
17515
|
// generate a random bpm between 75 and 150
|
|
17642
17516
|
randomBPM(){
|
|
17643
17517
|
let bpm = Math.floor(Math.random() * 75) + 75.0;
|
|
17644
|
-
this.
|
|
17518
|
+
this.setBPM(bpm);
|
|
17645
17519
|
}
|
|
17646
17520
|
|
|
17647
17521
|
// add files to the buffer from a single File Link
|
|
@@ -17752,6 +17626,7 @@ class Mercury extends MercuryInterpreter {
|
|
|
17752
17626
|
|
|
17753
17627
|
// set volume in floatingpoint and ramptime
|
|
17754
17628
|
setVolume(v, t=0){
|
|
17629
|
+
this.volume = v;
|
|
17755
17630
|
if (t > 0){
|
|
17756
17631
|
this.gain.gain.rampTo(v, t/1000, Tone.now());
|
|
17757
17632
|
} else {
|
|
@@ -17759,6 +17634,11 @@ class Mercury extends MercuryInterpreter {
|
|
|
17759
17634
|
}
|
|
17760
17635
|
}
|
|
17761
17636
|
|
|
17637
|
+
// get the volume as float between 0-1
|
|
17638
|
+
getVolume(){
|
|
17639
|
+
return this.gain.gain.value;
|
|
17640
|
+
}
|
|
17641
|
+
|
|
17762
17642
|
// a recording function
|
|
17763
17643
|
// default starts recording, a false/0 stops recording
|
|
17764
17644
|
// optionally add a filename to the downloading file
|
|
@@ -17788,5 +17668,5 @@ class Mercury extends MercuryInterpreter {
|
|
|
17788
17668
|
}
|
|
17789
17669
|
}
|
|
17790
17670
|
module.exports = { Mercury };
|
|
17791
|
-
},{"./
|
|
17671
|
+
},{"./interpreter":68,"tone":44}]},{},[69])(69)
|
|
17792
17672
|
});
|