mercury-engine 1.0.1 → 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 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 an object with {file:<code>}
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({ file: `
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
@@ -17120,7 +17120,7 @@ module.exports={
17120
17120
  const Tone = require('tone');
17121
17121
  const Mercury = require('mercury-lang');
17122
17122
  const TL = require('total-serialism').Translate;
17123
- // const Util = require('total-serialism').Utility;
17123
+ const Util = require('total-serialism').Utility;
17124
17124
 
17125
17125
  const MonoSample = require('./core/MonoSample.js');
17126
17126
  const MonoMidi = require('./core/MonoMidi.js');
@@ -17131,7 +17131,7 @@ const PolySample = require('./core/PolySample.js');
17131
17131
  const Tempos = require('./data/genre-tempos.json');
17132
17132
 
17133
17133
  class MercuryInterpreter {
17134
- constructor(){
17134
+ constructor({ hydra, p5canvas } = {}){
17135
17135
  // cross-fade time
17136
17136
  this.crossFade = 0.5;
17137
17137
 
@@ -17146,6 +17146,10 @@ class MercuryInterpreter {
17146
17146
  this.parse;
17147
17147
  this.tree;
17148
17148
  this.errors;
17149
+
17150
+ // Hydra and P5 canvas
17151
+ this.canvas = hydra;
17152
+ this.p5canvas = p5canvas;
17149
17153
  }
17150
17154
 
17151
17155
  getSounds(){
@@ -17182,19 +17186,27 @@ class MercuryInterpreter {
17182
17186
  s.length = 0;
17183
17187
  }
17184
17188
 
17185
- code({ file='', canvas, p5canvas } = {}){
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=''){
17186
17196
  // parse and evaluate the inputted code
17187
17197
  // as an asyncronous function with promise
17188
17198
  let c = (!file)? this._code : file;
17189
17199
  this._code = c;
17190
17200
 
17191
17201
  let t = Tone.Transport.seconds;
17202
+
17192
17203
  // is this necessary?
17193
17204
  // let parser = new Promise((resolve) => {
17194
17205
  // return resolve(Mercury(c));
17195
17206
  // });
17196
17207
  // this.parse = await parser;
17197
17208
  this.parse = Mercury(c);
17209
+
17198
17210
  console.log(`Evaluated code in: ${((Tone.Transport.seconds-t) * 1000).toFixed(3)}ms`);
17199
17211
 
17200
17212
  this.tree = this.parse.parseTree;
@@ -17218,17 +17230,6 @@ class MercuryInterpreter {
17218
17230
  console.log(p);
17219
17231
  });
17220
17232
 
17221
- // hide canvas and noLoop
17222
- // p5canvas.hide();
17223
-
17224
- // handle .display to p5
17225
- // tree.display.forEach((p) => {
17226
- // // restart canvas if view is used
17227
- // let n = Util.mul(Util.normalize(p), 255);
17228
- // p5canvas.sketch.fillCanvas(n);
17229
- // p5canvas.display();
17230
- // });
17231
-
17232
17233
  // set timer to check evaluation time
17233
17234
  t = Tone.Transport.seconds;
17234
17235
 
@@ -17236,9 +17237,7 @@ class MercuryInterpreter {
17236
17237
  const globalMap = {
17237
17238
  'crossFade' : (args) => {
17238
17239
  // set crossFade time in ms
17239
- this.crossFade = Number(args[0]) / 1000;
17240
- // log(`crossfade time is ${args[0]}ms`);
17241
- console.log(`Crossfade: ${args[0]}ms`);
17240
+ this.setCrossFade(args[0]);
17242
17241
  },
17243
17242
  'tempo' : (args) => {
17244
17243
  let t = args[0];
@@ -17250,7 +17249,7 @@ class MercuryInterpreter {
17250
17249
  }
17251
17250
  args[0] = t;
17252
17251
  }
17253
- this.bpm(...args);
17252
+ this.setBPM(...args);
17254
17253
  // engine.setBPM(...args);
17255
17254
  // log(`set bpm to ${bpm}`);
17256
17255
  },
@@ -17303,38 +17302,38 @@ class MercuryInterpreter {
17303
17302
  // Handling all the different instrument types here
17304
17303
  const objectMap = {
17305
17304
  'sample' : (obj) => {
17306
- let inst = new MonoSample(this, obj.type, canvas);
17305
+ let inst = new MonoSample(this, obj.type, this.canvas);
17307
17306
  objectMap.applyFunctions(obj.functions, inst, obj.type);
17308
17307
  return inst;
17309
17308
  },
17310
17309
  'loop' : (obj) => {
17311
- let inst = new MonoSample(this, obj.type, canvas);
17310
+ let inst = new MonoSample(this, obj.type, this.canvas);
17312
17311
  objectMap.applyFunctions(obj.functions, inst, obj.type);
17313
17312
  return inst;
17314
17313
  },
17315
17314
  'synth' : (obj) => {
17316
17315
  console.log(obj);
17317
- let inst = new MonoSynth(this, obj.type, canvas);
17316
+ let inst = new MonoSynth(this, obj.type, this.canvas);
17318
17317
  objectMap.applyFunctions(obj.functions, inst, obj.type);
17319
17318
  return inst;
17320
17319
  },
17321
17320
  'polySynth' : (obj) => {
17322
- let inst = new PolySynth(this, obj.type, canvas);
17321
+ let inst = new PolySynth(this, obj.type, this.canvas);
17323
17322
  objectMap.applyFunctions(obj.functions, inst, obj.type);
17324
17323
  return inst;
17325
17324
  },
17326
17325
  'polySample' : (obj) => {
17327
- let inst = new PolySample(this, obj.type, canvas);
17326
+ let inst = new PolySample(this, obj.type, this.canvas);
17328
17327
  objectMap.applyFunctions(obj.functions, inst, obj.type);
17329
17328
  return inst;
17330
17329
  },
17331
17330
  'midi' : (obj) => {
17332
- let inst = new MonoMidi(this, obj.type, canvas);
17331
+ let inst = new MonoMidi(this, obj.type, this.canvas);
17333
17332
  objectMap.applyFunctions(obj.functions, inst, obj.type);
17334
17333
  return inst;
17335
17334
  },
17336
17335
  'input' : (obj) => {
17337
- let inst = new MonoInput(this, obj.type, canvas);
17336
+ let inst = new MonoInput(this, obj.type, this.canvas);
17338
17337
  objectMap.applyFunctions(obj.functions, inst, obj.type);
17339
17338
  return inst;
17340
17339
  },
@@ -17390,6 +17389,20 @@ class MercuryInterpreter {
17390
17389
  this.removeSounds(this._sounds, this.crossFade);
17391
17390
 
17392
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
+ }
17393
17406
  }
17394
17407
  }
17395
17408
  module.exports = { MercuryInterpreter }
@@ -17400,7 +17413,8 @@ Mercury Engine by Timo Hoogland (c) 2023
17400
17413
  more info:
17401
17414
  https://www.timohoogland.com
17402
17415
  https://mercury.timohoogland.com
17403
- https://github.com/tmhglnd/mercury
17416
+ https://github.com/tmhglnd/mercury-playground
17417
+ https://github.com/tmhglnd/mercury-engine
17404
17418
 
17405
17419
  `);
17406
17420
 
@@ -17413,15 +17427,15 @@ const { MercuryInterpreter } = require('./interpreter');
17413
17427
  const fxExtensions = "\n// A white noise generator at -6dBFS to test AudioWorkletProcessor\n//\nclass NoiseProcessor extends AudioWorkletProcessor {\n\tprocess(inputs, outputs, parameters){\n\t\tconst output = outputs[0];\n\n\t\toutput.forEach((channel) => {\n\t\t\tfor (let i=0; i<channel.length; i++) {\n\t\t\t\tchannel[i] = Math.random() - 0.5;\n\t\t\t}\n\t\t});\n\t\treturn true;\n\t}\n}\nregisterProcessor('noise-processor', NoiseProcessor);\n\n// A Downsampling Chiptune effect. Downsamples the signal by a specified amount\n// Resulting in a lower samplerate, making it sound more like 8bit/chiptune\n// Programmed with a custom AudioWorkletProcessor, see effects/Processors.js\n//\nclass DownSampleProcessor extends AudioWorkletProcessor {\n\tstatic get parameterDescriptors() {\n\t\treturn [{\n\t\t\tname: 'down',\n\t\t\tdefaultValue: 8,\n\t\t\tminValue: 1,\n\t\t\tmaxValue: 2048\n\t\t}];\n\t}\n\n\tconstructor(){\n\t\tsuper();\n\t\t// the frame counter\n\t\tthis.count = 0;\n\t\t// sample and hold variable array\n\t\tthis.sah = [];\n\t}\n\n\tprocess(inputs, outputs, parameters){\n\t\tconst input = inputs[0];\n\t\tconst output = outputs[0];\n\n\t\t// if there is anything to process\n\t\tif (input.length > 0){\n\t\t\t// for the length of the sample array (generally 128)\n\t\t\tfor (let i=0; i<input[0].length; i++){\n\t\t\t\tconst d = (parameters.down.length > 1) ? parameters.down[i] : parameters.down[0];\n\t\t\t\t// for every channel\n\t\t\t\tfor (let channel=0; channel<input.length; ++channel){\n\t\t\t\t\t// if counter equals 0, sample and hold\n\t\t\t\t\tif (this.count % d === 0){\n\t\t\t\t\t\tthis.sah[channel] = input[channel][i];\n\t\t\t\t\t}\n\t\t\t\t\t// output the currently held sample\n\t\t\t\t\toutput[channel][i] = this.sah[channel];\n\t\t\t\t}\n\t\t\t\t// increment sample counter\n\t\t\t\tthis.count++;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\nregisterProcessor('downsampler-processor', DownSampleProcessor);\n\n// A distortion algorithm using the tanh (hyperbolic-tangent) as a \n// waveshaping technique. Some mapping to apply a more equal loudness \n// distortion is applied on the overdrive parameter\n//\nclass TanhDistortionProcessor extends AudioWorkletProcessor {\n\tconstructor(){\n\t\tsuper();\n\t}\n\n\tprocess(inputs, outputs, parameters){\n\t\tconst input = inputs[0];\n\t\tconst output = outputs[0];\n\n\t\tif (input.length > 0){\n\t\t\tfor (let channel=0; channel<input.length; ++channel){\n\t\t\t\tfor (let i=0; i<input[channel].length; i++){\n\t\t\t\t\t// simple waveshaping with tanh\n\t\t\t\t\toutput[channel][i] = Math.tanh(input[channel][i]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\nregisterProcessor('tanh-distortion-processor', TanhDistortionProcessor);\n\n// A distortion/compression effect of an incoming signal\n// Based on an algorithm by Peter McCulloch\n// \nclass SquashProcessor extends AudioWorkletProcessor {\n\tstatic get parameterDescriptors(){\n\t\treturn [{\n\t\t\tname: 'amount',\n\t\t\tdefaultValue: 4,\n\t\t\tminValue: 1,\n\t\t\tmaxValue: 1024\n\t\t}];\n\t}\n\n\tconstructor(){\n\t\tsuper();\n\t}\n\n\tprocess(inputs, outputs, parameters){\n\t\tconst input = inputs[0];\n\t\tconst output = outputs[0];\n\t\t\n\t\tif (input.length > 0){\n\t\t\tfor (let channel=0; channel<input.length; ++channel){\n\t\t\t\tfor (let i=0; i<input[channel].length; i++){\n\t\t\t\t\t// (s * a) / ((s * a)^2 * 0.28 + 1) / √a\n\t\t\t\t\t// drive amount, minimum of 1\n\t\t\t\t\tconst a = (parameters.amount.length > 1)? parameters.amount[i] : parameters.amount[0];\n\t\t\t\t\t// set the waveshaper effect\n\t\t\t\t\tconst s = input[channel][i];\n\t\t\t\t\tconst p = (s * a) / ((s * a) * (s * a) * 0.28 + 1.0);\n\t\t\t\t\toutput[channel][i] = p;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\nregisterProcessor('squash-processor', SquashProcessor);";
17414
17428
  Tone.getContext().addAudioWorkletModule(URL.createObjectURL(new Blob([ fxExtensions ], { type: 'text/javascript' })));
17415
17429
 
17416
- // const minifyInline = require('minify-inline-json');
17417
-
17418
17430
  // Mercury main class controls Tone and loads samples
17419
17431
  // also has the interpreter evaluating the code and adding the instruments
17420
17432
  //
17421
17433
  class Mercury extends MercuryInterpreter {
17422
- constructor(callback){
17423
- // initalize the constructor of inheriting class
17424
- super();
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
+
17425
17439
  // store sample files in buffers
17426
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");
17427
17441
 
@@ -17429,6 +17443,10 @@ class Mercury extends MercuryInterpreter {
17429
17443
  // add the buffers via function
17430
17444
  // this.addBuffers(['http://localhost:8080/mercury-engine/src/data/samples.json'])
17431
17445
 
17446
+ // setting parameters
17447
+ this.bpm = 100;
17448
+ this.volume = 1;
17449
+
17432
17450
  // effects on main output for Tone
17433
17451
  this.gain = new Tone.Gain(1);
17434
17452
  this.lowPass = new Tone.Filter(18000, 'lowpass');
@@ -17445,7 +17463,7 @@ class Mercury extends MercuryInterpreter {
17445
17463
  onload: () => {
17446
17464
  console.log('Samples loaded', this.buffers);
17447
17465
  // executes a callback from the class constructor
17448
- if (callback){ callback(); }
17466
+ if (onload){ onload(); }
17449
17467
  }
17450
17468
  });
17451
17469
  }
@@ -17480,7 +17498,8 @@ class Mercury extends MercuryInterpreter {
17480
17498
  }
17481
17499
 
17482
17500
  // set the bpm and optionally ramp in milliseconds
17483
- bpm(bpm, ramp=0) {
17501
+ setBPM(bpm, ramp=0) {
17502
+ this.bpm = bpm;
17484
17503
  if (ramp > 0){
17485
17504
  Tone.Transport.bpm.rampTo(bpm, ramp / 1000);
17486
17505
  } else {
@@ -17496,7 +17515,7 @@ class Mercury extends MercuryInterpreter {
17496
17515
  // generate a random bpm between 75 and 150
17497
17516
  randomBPM(){
17498
17517
  let bpm = Math.floor(Math.random() * 75) + 75.0;
17499
- this.bpm(bpm);
17518
+ this.setBPM(bpm);
17500
17519
  }
17501
17520
 
17502
17521
  // add files to the buffer from a single File Link
@@ -17607,6 +17626,7 @@ class Mercury extends MercuryInterpreter {
17607
17626
 
17608
17627
  // set volume in floatingpoint and ramptime
17609
17628
  setVolume(v, t=0){
17629
+ this.volume = v;
17610
17630
  if (t > 0){
17611
17631
  this.gain.gain.rampTo(v, t/1000, Tone.now());
17612
17632
  } else {
@@ -17614,6 +17634,11 @@ class Mercury extends MercuryInterpreter {
17614
17634
  }
17615
17635
  }
17616
17636
 
17637
+ // get the volume as float between 0-1
17638
+ getVolume(){
17639
+ return this.gain.gain.value;
17640
+ }
17641
+
17617
17642
  // a recording function
17618
17643
  // default starts recording, a false/0 stops recording
17619
17644
  // optionally add a filename to the downloading file