mercury-lang
Advanced tools
Comparing version 1.9.7 to 1.9.8
{ | ||
"name": "mercury-lang", | ||
"version": "1.9.7", | ||
"version": "1.9.8", | ||
"description": "Parser for the mercury live coding language", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -121,9 +121,17 @@ //==================================================================== | ||
// generate unique ID name for object before checking the name() | ||
// this ID is used for groups if there are any | ||
inst.functions.name = [ uniqueID(8) ]; | ||
Object.keys(el).forEach((k) => { | ||
inst = map[k](el[k], ccode, '@object', inst); | ||
}); | ||
// add the name to the all group | ||
ccode.groups.all.push(inst.functions.name[0]); | ||
// generate unique ID name for object if no name() | ||
if (!inst.functions.name){ | ||
inst.functions.name = [ uniqueID(8) ]; | ||
} | ||
// if (!inst.functions.name){ | ||
// inst.functions.name = [ uniqueID(8) ]; | ||
// } | ||
// console.log('code', ccode); | ||
// add object to complete code | ||
@@ -146,11 +154,23 @@ ccode.objects[inst.functions.name] = inst; | ||
ccode.objects[inst.functions.name] = inst; | ||
} else if (name === 'all'){ | ||
} else if (code.groups[name]){ //name === 'all' | ||
// if set all, set all instrument objects | ||
Object.keys(ccode.objects).forEach((o) => { | ||
code.groups[name].forEach((o) => { | ||
let inst = ccode.objects[o]; | ||
Object.keys(el).forEach((k) => { | ||
inst = map[k](el[k], ccode, '@object', inst); | ||
}); | ||
ccode.objects[inst.functions.name] = inst; | ||
if (inst){ | ||
Object.keys(el).forEach((k) => { | ||
inst = map[k](el[k], ccode, '@object', inst); | ||
}); | ||
ccode.objects[inst.functions.name] = inst; | ||
} | ||
}); | ||
// console.log(ccode.objects); | ||
// Object.keys(ccode.objects).forEach((o) => { | ||
// let inst = ccode.objects[o]; | ||
// Object.keys(el).forEach((k) => { | ||
// inst = map[k](el[k], ccode, '@object', inst); | ||
// }); | ||
// ccode.objects[inst.functions.name] = inst; | ||
// }); | ||
} else { | ||
@@ -263,9 +283,13 @@ // if name is part of global settings | ||
} else { | ||
if (func === 'name'){ | ||
ccode.groups.all.push(...args); | ||
// if (func === 'name'){ | ||
// ccode.groups.all.push(...args); | ||
// } else | ||
if (func === 'group'){ | ||
args.forEach((a) => { | ||
// add empty array if the group doesn't exist yet | ||
if (!ccode.groups[a]) { ccode.groups[a] = []; } | ||
// add the name of the inst to the group array | ||
ccode.groups[a].push(funcs.name[0]); | ||
}); | ||
} | ||
else if (func === 'group'){ | ||
// TO-DO: | ||
// code for group functions | ||
} | ||
funcs[func] = args; | ||
@@ -272,0 +296,0 @@ } |
@@ -445,2 +445,69 @@ // | ||
test('Using groups to apply functions', () => { | ||
let expected = { | ||
'bob' : { | ||
'object' : 'synth', | ||
'type' : 'saw', | ||
'functions' : { | ||
'name' : [ 'bob' ], | ||
'group' : [ 'bus1', 'bus2' ], | ||
'time' : [ '1/8' ], | ||
'note' : [[ 6, 10, 0, 10 ]], | ||
'env' : [ 1, 250 ], | ||
'beat' : [[ 1, 0, 1, 1 ]], | ||
'pan' : [ 0 ], | ||
'amp' : [ 0.7 ], | ||
'wave2' : [ 'saw', 0 ], | ||
'add_fx' : [], | ||
} | ||
}, | ||
'alice' : { | ||
'object' : 'sample', | ||
'type' : 'kick', | ||
'functions' : { | ||
'name' : [ 'alice' ], | ||
'group' : [ 'bus1', 'bus3' ], | ||
'time' : [ 0.25, 0.5 ], | ||
'speed' : [ 1 ], | ||
'note' : [ "off" ], | ||
'tune' : [ 60 ], | ||
'env' : [ -1 ], | ||
'pan' : [ 0 ], | ||
'beat' : [[ 1, 0, 1, 1 ]], | ||
'amp' : [ 0.3 ], | ||
'stretch': [0, 1, 1], | ||
'add_fx' : [], | ||
} | ||
}, | ||
'simon' : { | ||
'object' : 'synth', | ||
'type' : 'square', | ||
'functions' : { | ||
'name' : [ 'simon' ], | ||
'group' : [ 'bus2', 'bus3' ], | ||
'time' : [ '1/1', 0 ], | ||
'note' : [[ 6, 10, 0, 10 ]], | ||
'env' : [ 1, 250 ], | ||
'beat' : [[ 1, 0, 0, 1, 0 ]], | ||
'amp' : [ 0.3 ], | ||
'pan' : [ 0 ], | ||
'wave2' : [ 'saw', 0 ], | ||
'add_fx' : [], | ||
} | ||
} | ||
} | ||
let code = ` | ||
new synth saw time(1/8) name(bob) group(bus1 bus2) | ||
new sample kick time(0.25 0.5) name(alice) group(bus1 bus3) | ||
new synth square play(euclid(5 2)) name(simon) group(bus2 bus3) | ||
set bus1 play([1 0 1 1]) | ||
set bus2 note(sine(4 5.512 0 12)) | ||
set bus3 gain(0.3) | ||
`; | ||
expect(Mercury(code).parseTree.objects).toStrictEqual(expected); | ||
}); | ||
// test('Instruments with Array Synth/Sample names', () => { | ||
@@ -447,0 +514,0 @@ // let expected = { |
@@ -12,3 +12,3 @@ // set volume 0.9 5000 | ||
speel synth [ sine saw ] time(1/4 1/8) note(7 1) env(1 300) beat(0.2) group(sn bass) add_fx(reverb 0.9 11) add_fx(lfo 1/4 up) | ||
speel synth [ sine saw ] time(1/4 1/8) note(7 1) env(1 300) beat(0.2) add_fx(reverb 0.9 11) add_fx(lfo 1/4 up) //group(sn bass) | ||
@@ -15,0 +15,0 @@ new sample [ kick_min snare_dub ] time(1/16) shape(1 1/32 2) beat(0.9) |
@@ -13,3 +13,3 @@ set volume 0.9 5000 | ||
new synth [ sine saw ] time(1/4 1/8) note(7 1) env(1 300) beat(0.2) group(sn bass) add_fx(reverb 0.9 11) add_fx(lfo 1/4 up) | ||
new synth [ sine saw ] time(1/4 1/8) note(7 1) env(1 300) beat(0.2) add_fx(reverb 0.9 11) add_fx(lfo 1/4 up) //group(sn bass) | ||
@@ -19,3 +19,3 @@ new sample [ kick_min snare_dub ] time(1/16) shape(1 1/32 2) beat(0.9) | ||
new synth sine name(aSynth) | ||
set aSynth note(notes 1) timing(1/16) shape(1000 200) play(0.8) aux(sn ld) | ||
set aSynth note(notes 1) timing(1/16) shape(1000 200) play(0.8) //aux(sn ld) | ||
set aSynth gain(0.5 100) | ||
@@ -27,3 +27,3 @@ | ||
set bSynth note(random(4 0 12) 2) time(1/16) env(300 1000) | ||
set bSynth pan(random) group(bass intro) | ||
set bSynth pan(random) //group(bass intro) | ||
set bSynth gain(0) beat(0.7) | ||
@@ -30,0 +30,0 @@ |
Sorry, the diff of this file is too big to display
2373385
18537