mercury-engine 1.1.0 → 1.2.1

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.
@@ -0,0 +1,83 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <title>Mercury & Hydra Example</title>
6
+
7
+ <!-- Use the latest minified es5 distribution -->
8
+ <!-- <script src="https://unpkg.com/mercury-engine/dist/mercury.min.es5.js"></script> -->
9
+
10
+ <!-- from local while developing -->
11
+ <script src="./../../dist/mercury.js"></script>
12
+ <script src="https://unpkg.com/hydra-synth"></script>
13
+
14
+ <script src="https://unpkg.com/meyda/dist/web/meyda.min.js"></script>
15
+
16
+ </head>
17
+
18
+ <body>
19
+ <p style="font-family: 'arial';">
20
+ This example demonstrates how the Meter in the Mercury engine can be used to control some visual parameters in real time from for example the <a target="blank" href="https://hydra.ojack.xyz">Hydra</a> live coding language. Open the developers console to see the volume analysis printed as well.
21
+ </p>
22
+
23
+ <!-- 2 buttons in the html page -->
24
+ <button id="b1">start</button>
25
+ <button id="b2">silence</button>
26
+
27
+ <p id="engine-status" style="font-family: 'arial';"></p>
28
+
29
+ <script>
30
+ // Include the package from unpkg.com
31
+ const { Mercury } = MercuryEngine;
32
+
33
+ // global variable for storing the sound analysis from Mercury
34
+ let amp;
35
+ // create a new hydra-synth instance
36
+ var hydra = new Hydra({ detectAudio: false });
37
+ // generate some visuals
38
+ osc(10, 0.2, () => amp * 20).hue(() => amp * 5).out();
39
+
40
+ // Initialize a Mercury engine with callback function when loaded
41
+ const Engine = new Mercury({
42
+ onload: () => {
43
+ console.log('The engine and sounds are loaded!');
44
+ // when ready create the meter and set an interval to update
45
+ // the value for the visuals. 16ms is chosen because of
46
+ // 1000ms/60fps = 16.667
47
+ Engine.addMeter();
48
+ setInterval(() => {
49
+ amp = Engine.getMeter();
50
+ consoleMeter(amp);
51
+ }, 16);
52
+ }
53
+ });
54
+
55
+ // Some mercury code initially created
56
+ const mercuryCode = `
57
+ set tempo 100
58
+ list drm choose(16 [kick_dub hat_808 snare_step])
59
+ new polySample drm time(1/16) play(euclid(16 9)) note(0 2)
60
+ `
61
+
62
+ // evaluate the code on the click of a button
63
+ let b1 = document.getElementById('b1');
64
+ b1.onclick = () => {
65
+ let tree = Engine.code(mercuryCode);
66
+ console.log(tree.errors);
67
+ }
68
+
69
+ // stop the code on the click of a button
70
+ let b2 = document.getElementById('b2');
71
+ b2.onclick = () => Engine.silence();
72
+
73
+ // function for "led bar meter print"
74
+ function consoleMeter(m){
75
+ leds = Math.floor((m ** 0.5) * 30);
76
+ disp = '';
77
+ for (let i=0; i<leds; i++){ disp += '▊'; }
78
+ console.log(`vol: ${disp}`);
79
+ }
80
+ </script>
81
+ </body>
82
+
83
+ </html>
@@ -70,7 +70,7 @@
70
70
  new synth saw name(s1)
71
71
  set s1 note('{note.value()}' 0) slide(1/16)
72
72
  set s1 fx(filter low '{cutoff.value()}' 0.4 1/16)
73
- set s1 super('{detune.value()}' 3) shape(off)
73
+ set s1 super(3 '{detune.value()}') shape(off)
74
74
  set s1 time(1/16) fx(degrade '{degrade.value()}')
75
75
  `
76
76
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mercury-engine",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "The mercury engine generates web audio output from mercury code input",
5
5
  "main": "./dist/mercury.js",
6
6
  "scripts": {