mercury-engine 1.0.4 → 1.0.6

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.
@@ -8,7 +8,7 @@
8
8
  <!-- <script src="https://unpkg.com/mercury-engine/dist/mercury.min.es5.js"></script> -->
9
9
 
10
10
  <!-- from local while developing -->
11
- <script src="./../../dist/mercury.min.es5.js"></script>
11
+ <script src="./../../dist/mercury.js"></script>
12
12
  </head>
13
13
 
14
14
  <body>
@@ -75,7 +75,10 @@
75
75
 
76
76
  // evaluate the code on the click of a button
77
77
  let b1 = document.getElementById('b1');
78
- b1.onclick = () => Engine.code(mercuryCode);
78
+ b1.onclick = () => {
79
+ let tree = Engine.code(mercuryCode);
80
+ console.log(tree.errors);
81
+ }
79
82
 
80
83
  // stop the code on the click of a button
81
84
  let b2 = document.getElementById('b2');
@@ -0,0 +1,78 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <title>Handling Errors</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
+ </head>
13
+
14
+ <body>
15
+ <p style="font-family: 'arial';">
16
+ This example demonstrates how errors can be displayed when returned from parsed code that is invalid. The engine returns the full parse tree when code is evaluated (see the console log). This includes a key for errors and warnings.
17
+ </p>
18
+
19
+ <!-- 2 buttons in the html page -->
20
+ <button id="b1">start</button>
21
+ <button id="b2">silence</button>
22
+
23
+ <p id="status" style="font-family: 'arial';"></p>
24
+
25
+ <script>
26
+ // This script loads the Mercury Engine and allows to insert code
27
+ // from a textarea in the html page
28
+
29
+ // Include the package from unpkg.com
30
+ const { Mercury } = MercuryEngine;
31
+
32
+ // Initialize a Mercury engine with callback function when loaded
33
+ const Engine = new Mercury({
34
+ onload: () => {
35
+ console.log('The engine and sounds are loaded!');
36
+ }
37
+ });
38
+
39
+ // print the errors to the html
40
+ window.addEventListener('mercuryLog', (e) => {
41
+ let p = JSON.stringify(e.detail).replace(/\,/g, ' ').replace(/\"/g, '');
42
+ document.getElementById('status').innerHTML += `${p}<br>`;
43
+ });
44
+
45
+ // Some mercury code that includes syntax errors
46
+ const mercuryCode = `
47
+ set invalidSetting 110
48
+ set randomSeed 4831 ]
49
+ set scale dorian d
50
+
51
+ list progression chordsFromNumerals([I7 IIIm7 IV7 V7)
52
+ new polySynth saw name(chrd)
53
+ set chrd note( progression 1) time(2/1) shape(1 2/1) fx(triggerFilter, low 1/1 1/1 4000 100) super(0.132 3)
54
+
55
+ list melody add(repeat(flat(progression) 2) [0 12])
56
+ new polySynth name(lead)
57
+ set lead note(melody 2) time(1/8) shape(1 2/1) super(0.112 3) gain(0.6) fx(triggerFilter low 1 1/6 5000 100)
58
+
59
+ set all fx(squash 1) fx(reverb 0.4 7)
60
+
61
+ list drums choose(17 [hat_808 kick_808 snare_808])
62
+ new sample drums time(1/8) gain(0.7) fx(degrade 0.7) fx(delay 3/16 5/16 0.9) timediv([1 1 1 2])
63
+ `
64
+
65
+ // evaluate the code on the click of a button
66
+ let b1 = document.getElementById('b1');
67
+ b1.onclick = () => {
68
+ let tree = Engine.code(mercuryCode);
69
+ console.log(tree);
70
+ }
71
+
72
+ // stop the code on the click of a button
73
+ let b2 = document.getElementById('b2');
74
+ b2.onclick = () => Engine.silence();
75
+ </script>
76
+ </body>
77
+
78
+ </html>
@@ -8,7 +8,7 @@
8
8
  <!-- <script src="https://unpkg.com/mercury-engine/dist/mercury.min.es5.js"></script> -->
9
9
 
10
10
  <!-- from local while developing -->
11
- <script src="./../../dist/mercury.min.es5.js"></script>
11
+ <script src="./../../dist/mercury.js"></script>
12
12
  </head>
13
13
 
14
14
  <body>
package/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
 
2
2
  exports.Mercury = require('./src/mercury.js').Mercury;
3
+
4
+ // module.exports.Mercury = require('./src/mercury.js').Mercury;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mercury-engine",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "The mercury engine generates web audio output from mercury code input",
5
5
  "main": "./dist/mercury.js",
6
6
  "scripts": {