ometa B <: Parser { //the number part digit = super(#digit):d -> d.digitValue(), number = number:n digit:d -> (n * 10 + d) | digit, //expressions addExpr = addExpr:a '+' mulExpr:b -> ['+', a, b] | addExpr:a '-' mulExpr:b -> ['-', a, b] | mulExpr, mulExpr = mulExpr:a '*' primExpr:b -> ['*', a, b] | mulExpr:a '/' primExpr:b -> ['/', a, b] | primExpr, primExpr = '(' expr:a ')' -> a | number:a -> a, expr = addExpr:a -> a, //number lists numlist = expr:a ' ' numlist:b -> a.concat(b) | '^' ' ' numlist:a -> [['^'].concat([a])] | 'v' ' ' numlist:a -> [['v'].concat([a])] | expr:a, tune = numlist:a -> a } str = "^ 5 6 7+8*9" B.matchAll(str, 'tune') //todo //stops //octave changes //melodies containing melodies //validation do_everything = function() { eval(readFile("Amarin_Test3_Library")) //configurations //number_of_tracks = 2 //ticks_per_beat = 24 //beats_per_second = 80 heap = [] midi_file = [] heap //var assignment //add_var_to_heap("x", [1, 2, 3, "4", "5", "0", "6"], [24, 24, 24, 24, 24, 24, 24], [1, 3, 4, 6, 8, 10, 12], "c4") add_var_to_heap( ["x", [ "!", [[["^", [1], [2], [3], [4], [5]]], [[24], [24], [24], [24], [24]], [[1], [3], [5], [6], [8], [10], [12], [13]], [[60]] ] ] ]) heap //the whole x add_var_to_heap( ["y", [ "?", "x"]]) add_var_to_heap( ["z", [ "!", [ [["v", ["?", "y"], [20]]], [["?", "x"], [24]], [["?", "y"]], [["?", "x"]] ] ] ] ) add_var_to_heap( ["x2", [ "!", [ [["^", ["?", "y"]]], [["/", ["?", "x"], [2]]], [["?", "y"]], [["?", "x"]] ] ] ] ) heap add_var_to_heap( ["x3", [ "&", ["?", "y"], ["?", "x2"] ] ] ) heap //test x in the tune //x+1 //^x //vx //x*2 //x/2 //x&y //file header midi_file = [] write2file(file_header()) //piano = x heap heap_melody = get_var_from_heap("x3") ir = melody2ir(heap_melody[1]) midi_events = [] midi_events = midi_events.concat(program_change(0, 0)) midi_events = midi_events.concat(ir2midi(ir,0)) midi_events = midi_events.concat(end_of_track()) write2file(track_header(midi_events.length)) write2file(midi_events) midi_file //only call this when the midi_file is ready to be compiled create_binary() }