UNPKG

mercury-lang

Version:

Parser for the mercury live coding language

85 lines (66 loc) 2.27 kB
// Parsing numbers print [ 012 34 -56 +7.89 1.011121E3 0.4321 ] // Parse note names print [ a A b B c C d D e E f F g G ] print [ a# B# C# Dx Gb fbb ] print [ a1 A0 b2b B4# c1 C2bb d4## D3 e2 E1 f4# F5 g6 G2 ] // Parse rhythmic division values print [ 1/4 3/16 7/16 4/5 3/1 ] print [ 7:8 3:2 1:5 ] // Parse comments // valid strings start and end with: "" '' `` // or a combination of those works as well print ["hello world" 'also a string' `and another!` 'this works?'] print "1 +2 /3.14* 45.67" // Parse identifier/name // valid identifiers start with characters [a-zA-Z] // can have _ - . and numbers [0-9] print [ Kick_dub dub_15 foLey-02.wav -negative ] // Parse Signal modulation strings TODO print [ ~mySig ~my-sig ~my_Sig ~23sig ~sig423 ] // Parsing osc type strings TODO // print [ /oscString/param /oscString/temp /anotherOsc/param ] // lists can have single values, arrays, keywords and strings list arr1 3.141592654 list arr2 [ 1 2 arr1 ] list arr3 [ 1 2 arr2 56 7.89e-13 ] list arr4 [ hat_dub hat_dub_open hat_909 ] list arr5 [ 'hello world' 'foo bar' ] list arr6 [ 1 2 [3 4] 5 [6 [7 8] 9] 10 11 ] // lists can be generated with functions list beat euclid(16 9 0) list grv choose(8 [hat kick snare]) list arpMel clone( palin( spread(5 0 12) ) 0 0 7 3 ) list join [ random(4 10 20) urn(4) ] array notes palin([c4 e4 f4 d#4 gb5]) // generate a synth, sample, loop or midi new synth saw new sample hat new midi default new loop amen new polySynth sine new polySample kick new osc address // an instrument can have an array new sample [ hat kick snare ] new synth [ saw triangle sine ] // instruments can have functions make synth saw note([0 3 7] 0) time(1/8) shape(1 50) name(bob) make sample kick time(0.25 0.5) play([1 0 1 1]) name(alice) // functions can have functions new synth square note(sine(8 5.512 0 12)) play(euclid(8 5)) time(1/16) // set functions to named instruments set bob fx(double) fx(delay 3/16 0.7) set alice fx(drive) // set functions to all instruments set all fx(reverb 0.5 5) // set global settings set randomSeed 9876 set tempo 143 1000 set scale major g# set hipass 500 3000 set lopass 2000 500 set crossFade 100 set tempo hiphop uptempo new sample bell gain(/osc/paramAddress) fx(drive /osc/1/fxDrive) silence