mercury-engine 1.0.2 → 1.0.3

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
@@ -23,7 +23,7 @@ Mercury currently has 2 versions:
23
23
 
24
24
  [**💬 Join the Mercury Community on Discord**](https://discord.gg/vt59NYU)
25
25
 
26
- ![The Mercury playground in the browser](media/screenshot.png)
26
+ <!-- ![The Mercury playground in the browser](media/screenshot.png) -->
27
27
 
28
28
  # 🚀 Install
29
29
 
@@ -41,13 +41,23 @@ const Engine = new Mercury();
41
41
 
42
42
  ## Include in html
43
43
 
44
- Include latest or specific version of bundled es5 version through url in index.html
44
+ Include latest or a specific version of distribution (minified, es5) through url in script index.html
45
+
46
+ Recommended for most cases:
47
+
48
+ ```html
49
+ <script src="https://unpkg.com/mercury-engine/dist/mercury.min.es5.js"></script>
50
+ ```
51
+
52
+ Other options:
45
53
 
46
54
  ```html
47
- <script src="https://unpkg.com/mercury-engine@1.0.0/build/mercury.min.js"></script>
55
+ <script src="https://unpkg.com/mercury-engine/dist/mercury.js"></script>
56
+ <script src="https://unpkg.com/mercury-engine@1.0.0/dist/mercury.min.js"></script>
57
+ <script src="https://unpkg.com/mercury-engine@1.0.0/dist/mercury.min.es5.js"></script>
48
58
  ```
49
59
 
50
- Use in a html `<script>` like so:
60
+ Load the engine in the `<script>` code like so:
51
61
 
52
62
  ```js
53
63
  const { Mercury } = MercuryEngine;
@@ -55,60 +65,173 @@ const { Mercury } = MercuryEngine;
55
65
  const Engine = new Mercury();
56
66
  ```
57
67
 
68
+ ## Examples
69
+
70
+ See the `examples` folder for a few `.html` files that demonstrate the usage. Run them locally by cloning this repository with `git clone https://github.com/tmhglnd/mercury-engine`. Then `cd mercury-engine` and run a simple http-server, for example with the `http-server` node package (install globally with `npm i -g http-server`). Navigate to `localhost:8080/examples` and try them out.
71
+
58
72
  # Usage
59
73
 
74
+ ### Include and initialize
75
+
76
+ Include the package
77
+
60
78
  ```js
61
- // include the package
62
79
  const { Mercury } = require('mercury-engine');
80
+ ```
81
+
82
+ Initialize the engine and include a callback function through { onload: }, this will be executed when samples are loaded.
63
83
 
64
- // initialize the engine and included a callback function
65
- const Engine = Mercury(() => {
66
- console.log('This callback is called when samples are loaded!');
84
+ ```js
85
+ const Engine = Mercury({
86
+ onload: () => {
87
+ console.log('This callback is called when samples are loaded!');
88
+ }
67
89
  });
90
+ ```
91
+
92
+ ### Resume, evaluate and silence
93
+
94
+ Resume the transport and start the webaudio. This has to be done from a user interaction (click or keypress) to allow sound to play from the browser window.
95
+
96
+ ```js
97
+ Engine.resume();
98
+ ```
68
99
 
69
- // resume the transport and start the webaudio
70
- // this has to be done from a user interaction (click/key) to allow sound
71
- // to play from the browser window
72
- Engine.resume()
100
+ Evaluate a mercury code file by providing a string of code. This also resumes the transport if .resume() was not called yet.
73
101
 
74
- // Evaluate a mercury code file by providing a string of code
75
- // This also resumes the transport if .resume() was not called yet
102
+ ```js
76
103
  Engine.code(`
77
104
  set tempo 100
78
105
  new sample kick_909 time(1/4)
79
106
  new sample hat_909 time(1/4 1/8) gain(0.6)
80
107
  new synth saw note(0 0) time(1/16) shape(1 80)
81
108
  `);
109
+ ```
110
+
111
+ Stop the transport and silence the audio
82
112
 
83
- // stop the transport and silence the audio
113
+ ```js
84
114
  Engine.silence();
115
+ ```
116
+
117
+ Return the last succesfully evaluated code. If code is evaluated that resulted in an error it is not stored.
118
+
119
+ ```js
120
+ Engine.getCode();
121
+ ```
122
+
123
+ ### Samples
124
+
125
+ 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
+ ```js
128
+ Engine.addBuffers();
129
+ ```
85
130
 
86
- // start the recording of the sound
131
+ Get the content of all the loaded Buffers, this is returned as a ToneAudioBuffers class
132
+
133
+ ```js
134
+ Engine.getBuffers();
135
+ ```
136
+
137
+ ### Recording
138
+
139
+ Start the recording of the sound
140
+
141
+ ```js
87
142
  Engine.record(true);
143
+ ```
88
144
 
89
- // returns 'started' if the recording is on
90
- Engine.isRecording()
145
+ Returns 'started' if the recording is on
91
146
 
92
- // stop the recording and download the file myRecording.webm
147
+ ```js
148
+ Engine.isRecording();
149
+ ```
150
+
151
+ Stop the recording and download the file `myRecording.webm`
152
+
153
+ ```js
93
154
  Engine.record(false, 'myRecording');
155
+ ```
156
+
157
+ ### MIDI
158
+
159
+ WebMIDI is included and started if the browser is compatible with it. If not, an error will be printed to the console. You can provide a callback function `onmidi` to execute some code when the WebMIDI enabling was succesful.
160
+
161
+ ```js
162
+ const Engine = Mercury({
163
+ onmidi: () => {
164
+ console.log('The WebMIDI status is:', Engine.midi.status);
165
+ console.log('With inputs:', Engine.midi.inputs);
166
+ console.log('And outputs:', Engine.midi.outputs);
167
+ }
168
+ });
169
+ ```
170
+
171
+ ### Settings
94
172
 
95
- // set the BPM without adding `set tempo` to the Mercury code
173
+ Set the BPM without using `set tempo` in the Mercury code
174
+
175
+ ```js
96
176
  Engine.setBPM(140);
177
+ ```
178
+
179
+ Set a randomized BPM
180
+
181
+ ```js
182
+ Engine.randomBPM();
183
+ ```
184
+
185
+ Set the volume without using `set volume` in the Mercury code. Volume in floating amplitude 0 to 1.
97
186
 
98
- // set the volume without adding `set volume` to the Mercury code
187
+ ```js
99
188
  Engine.setVolume(0.5);
189
+ ```
100
190
 
101
- // add your own samples from for example a url like raw github or freesound
102
- // the url can also contain a .json file that references multiple samples and
103
- // the sample name
104
- Engine.addSamples();
191
+ Set the crossFade between 2 code evaluations without using `set crossFade` in the Mercury code. Time in milliseconds.
192
+
193
+ ```js
194
+ Engine.setCrossFade(500);
195
+ ```
196
+
197
+ Set the HighPass Filter cutoff frequency without using `set highPass` in the Mercury code.
198
+
199
+ ```js
200
+ Engine.setHighPass(400);
201
+ ```
202
+
203
+ Set the LowPass Filter cutoff frequency without using `set lowPass` in the Mercury code.
204
+
205
+ ```js
206
+ Engine.setLowPass(5000);
207
+ ```
208
+
209
+ Get the value for any of the settings
210
+
211
+ ```js
212
+ console.log(Engine.bpm);
213
+ console.log(Engine.volume);
214
+ console.log(Engine.crossFade);
215
+ console.log(Engine.highPass);
216
+ console.log(Engine.lowPass);
217
+ ```
218
+
219
+ ### Log function listener
220
+
221
+ Logs that are important for the Mercury coder are also emitted as a custom event in the browser. You can create an event listener for `mercuryLog`. The `e.detail` contains the printed message. This can be used to for example print things to custom html elements instead of the javascript console.
222
+
223
+ ```js
224
+ window.addEventListener('mercuryLog', (e) => {
225
+ let p = JSON.stringify(e.detail).replace(/\,/g, ' ').replace(/\"/g, '');
226
+ document.getElementById('logger').innerHTML += `${p}<br>`;
227
+ console.log('customprint:', e.detail);
228
+ });
105
229
  ```
106
230
 
107
231
  ## 📋 To Do
108
232
 
109
233
  - [ ] Include OSC communcation options via socket.io
110
234
  - [ ] Use engine in the Mercury-playground instead of the other code-base
111
- - [ ] Create examples for the engine
112
235
  - [ ] Allow control of parameters via DOM elements
113
236
 
114
237
  ## 🔋 Powered By