Skip to content

Commit 6bfb02d

Browse files
committed
added new midi method work-in-progress
1 parent 144e31e commit 6bfb02d

12 files changed

Lines changed: 919 additions & 233 deletions

grammar/bind-functions.gen.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
11
{
2+
"midi": {
3+
"name": "name",
4+
"id": "name",
5+
"group": "group",
6+
"aux": "group",
7+
"bus": "group",
8+
"beat": "beat",
9+
"rhythm": "beat",
10+
"b": "beat",
11+
"play": "beat",
12+
"time": "time",
13+
"timing": "time",
14+
"t": "time",
15+
"amp": "amp",
16+
"gain": "amp",
17+
"vol": "amp",
18+
"volume": "amp",
19+
"amplitude": "amp",
20+
"a": "amp",
21+
"g": "amp",
22+
"v": "amp",
23+
"velocity": "amp",
24+
"vel": "amp",
25+
"note": "note",
26+
"pitch": "note",
27+
"n": "note",
28+
"envelope": "env",
29+
"shape": "env",
30+
"transient": "env",
31+
"env": "env",
32+
"e": "env",
33+
"length": "env",
34+
"duration": "env",
35+
"dur": "env",
36+
"channel": "out",
37+
"output": "out",
38+
"outlet": "out",
39+
"to": "out"
40+
},
241
"emitter": {
342
"name": "name",
443
"id": "name",
@@ -25,6 +64,8 @@
2564
"a": "amp",
2665
"g": "amp",
2766
"v": "amp",
67+
"velocity": "amp",
68+
"vel": "amp",
2869
"beat": "beat",
2970
"rhythm": "beat",
3071
"b": "beat",
@@ -35,6 +76,8 @@
3576
"env": "env",
3677
"e": "env",
3778
"length": "env",
79+
"duration": "env",
80+
"dur": "env",
3881
"note": "note",
3982
"pitch": "note",
4083
"n": "note",
@@ -78,6 +121,8 @@
78121
"a": "amp",
79122
"g": "amp",
80123
"v": "amp",
124+
"velocity": "amp",
125+
"vel": "amp",
81126
"beat": "beat",
82127
"rhythm": "beat",
83128
"b": "beat",
@@ -88,6 +133,8 @@
88133
"env": "env",
89134
"e": "env",
90135
"length": "env",
136+
"duration": "env",
137+
"dur": "env",
91138
"note": "note",
92139
"pitch": "note",
93140
"n": "note",
@@ -131,6 +178,8 @@
131178
"a": "amp",
132179
"g": "amp",
133180
"v": "amp",
181+
"velocity": "amp",
182+
"vel": "amp",
134183
"beat": "beat",
135184
"rhythm": "beat",
136185
"b": "beat",
@@ -141,6 +190,8 @@
141190
"env": "env",
142191
"e": "env",
143192
"length": "env",
193+
"duration": "env",
194+
"dur": "env",
144195
"time": "time",
145196
"timing": "time",
146197
"t": "time",
@@ -181,6 +232,8 @@
181232
"a": "amp",
182233
"g": "amp",
183234
"v": "amp",
235+
"velocity": "amp",
236+
"vel": "amp",
184237
"beat": "beat",
185238
"rhythm": "beat",
186239
"b": "beat",
@@ -191,6 +244,8 @@
191244
"env": "env",
192245
"e": "env",
193246
"length": "env",
247+
"duration": "env",
248+
"dur": "env",
194249
"time": "time",
195250
"timing": "time",
196251
"t": "time",

grammar/bind-functions.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"amplitude",
88
"a",
99
"g",
10-
"v"
10+
"v",
11+
"velocity",
12+
"vel"
1113
],
1214

1315
"beat" : [
@@ -23,7 +25,9 @@
2325
"transient",
2426
"env",
2527
"e",
26-
"length"
28+
"length",
29+
"duration",
30+
"dur"
2731
],
2832

2933
"note" : [
@@ -121,5 +125,12 @@
121125
"address",
122126
"tag",
123127
"url"
128+
],
129+
130+
"out" : [
131+
"channel",
132+
"output",
133+
"outlet",
134+
"to"
124135
]
125136
}

grammar/instrument-methods.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
{
2+
"midi" : [
3+
"name",
4+
"group",
5+
"beat",
6+
"time",
7+
"amp",
8+
"note",
9+
"env",
10+
"out"
11+
],
12+
213
"emitter" : [
314
"name",
415
"address",

mercury_ide/code/mercury.js

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
//==============================================================================
1+
//====================================================================
22
// mercury.js
33
// by Timo Hoogland (@t.mo / @tmhglnd), www.timohoogland.com
44
// GNU GPL-3.0 License
55
//
66
// The Mercury Parser and Ring Methods
77
// Using the total-serialism node package
8-
//==============================================================================
8+
//====================================================================
99

1010
const max = require('max-api');
11+
// const moo = require('moo');
12+
1113
const Gen = require('total-serialism').Generative;
1214
const Algo = require('total-serialism').Algorithmic;
1315
const Mod = require('total-serialism').Transform;
@@ -18,6 +20,11 @@ const Dict = require('./dictionary.js');
1820

1921
var dict = new Dict();
2022

23+
// let lexer = moo.compile({
24+
// string: /["|'|\`](?:\\["\\]|[^\n"\\])*["|'|\`]/,
25+
// rest: moo.error
26+
// })
27+
2128
const handlers = {
2229
// parse the input strings from code editor
2330
// seperate lines are input as a string of characters
@@ -37,17 +44,18 @@ const handlers = {
3744
// input the ring, get the varname
3845
// and join the expression to string to be parsed
3946
'ring' : (name, ...args) => {
40-
// console.log('ring', '@name', name, '@args', args);
4147
if (args < 1){
4248
// do nothing if not enough arguments
43-
console.error("not enough arguments for method ring");
49+
max.post("not enough arguments for method ring");
4450
return;
4551
}
46-
console.log("ring", "@name", name, "@args", ...args);
52+
// max.post("@ring", "name:", name, "args:", ...args);
4753
if (isNaN(name)){
4854
let expr = args.join(' ');
4955
let parsed = parseString(expr);
56+
// max.post('@parseString', parsed);
5057
let eval = evaluateParse(parsed);
58+
// max.post('@eval', eval);
5159

5260
let arr = [];
5361
for (i in eval){
@@ -56,7 +64,7 @@ const handlers = {
5664
dict.set(name, arr);
5765
} else {
5866
// numbers are not allowed as ring name
59-
console.error("Ring:", name, "is not a valid name");
67+
max.post("ring:", name, "is not a valid name");
6068
}
6169
},
6270
// All the Array transformation/generation methods
@@ -366,28 +374,28 @@ max.addHandlers(handlers);
366374
function mainParse(lines){
367375
// remove double whitespaces
368376
lines = lines.slice().map(x => x.replace(/\s{2,}/g, ' '));
369-
// max.post("@mainParse", lines);
377+
max.post("@mainParse", lines);
370378

371379
let rings = [];
372380
let other = [];
373381
// regular expression to match rings
374-
let r = /ring\ .+/;
382+
let ring = /ring\ .+/;
375383
let seed = /set\ randomSeed\ .+/;
376384
let scale = /set\ scale\ .+/;
377385
let tempo = /set\ tempo\ .+/;
378386
let mute = /(silence|mute|killAll)/;
379387

380388
for (let i in lines){
381389
l = lines[i];
382-
if (r.test(l)){
390+
if (ring.test(l)){
383391
rings.push(l);
384392
} else if (seed.test(l) || scale.test(l) || tempo.test(l)){
385393
other.push(l);
386394
let expr = l.split(' ');
387395
expr.shift();
388396
mainFunc.call(handlers, ...expr);
389397
} else if (mute.test(l)){
390-
max.post("silence detected");
398+
max.post("@silence");
391399
other.push("silence");
392400
} else {
393401
other.push(l);
@@ -397,14 +405,38 @@ function mainParse(lines){
397405
mainFunc.call(handlers, 'clear');
398406

399407
for (let r in rings){
408+
// max.post('@ring', rings[r]);
400409
let params = rings[r].split(' ');
401410
mainFunc.call(handlers, ...params);
402411
}
403412
// output the new variables dictionary
404413
max.outlet(dict.items);
405414

406415
for (let o in other){
407-
let expr = other[o].split(' ').map(x => parseNumber(x));
416+
// let string = /["|'|\`](?:\\["\\]|[^\n"\\])*["|'|\`]/g;
417+
// max.post('@string', string.exec(other[o]));
418+
let expr = [];
419+
let s = '';
420+
let isString = false;
421+
for (let char in other[o]){
422+
let c = other[o].charAt(char);
423+
if (c === '"' || c === "'" || c === "`"){
424+
if (isString){
425+
expr.push(s);
426+
} else {
427+
expr = expr.concat(s.split(' ').filter(i => i).map(x => parseNumber(x)));
428+
}
429+
isString = !isString;
430+
s = '';
431+
} else {
432+
s += c;
433+
}
434+
}
435+
expr = expr.concat(s.split(' ').filter(i => i).map(x => parseNumber(x)));
436+
// expr.push(s);
437+
438+
// expr = other[o].split(' ').map(x => parseNumber(x));
439+
max.post('@parsed', expr);
408440
max.outlet('parsed', ...expr);
409441
}
410442
max.outlet('done');
@@ -468,7 +500,7 @@ function parseParam(v){
468500
}
469501

470502
// parse the input string to an array of values and
471-
// possible function name. excepts multi-dimensional arrays
503+
// possible function name. accepts multi-dimensional arrays
472504
// arrays of 3 dimension or higher will be stripped down to 2d
473505
//
474506
function parseString(str){

mercury_ide/code/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mercury_ide/code/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dependencies": {
1212
"fast-glob": "^3.2.4",
1313
"fs-extra": "^9.0.1",
14+
"moo": "^0.5.1",
1415
"path": "^0.12.7",
1516
"slash": "^3.0.0",
1617
"total-serialism": "^1.8.7"

0 commit comments

Comments
 (0)