Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

mus compiler with rest, midi and repeats

  • Loading branch information...
commit a8d0812dbcb8314026cca2eb3c9b62b3291c3c82 1 parent f3c81a1
@therac25 therac25 authored
Showing with 19 additions and 2 deletions.
  1. +19 −2 mus/compiler.js
View
21 mus/compiler.js
@@ -22,6 +22,16 @@ var pitch_to_midi = function(p){
}
+var repeat_to_seq = function(section, count){
+ if(count === 1)
+ return section;
+ else
+ return { tag:'seq',
+ left: section,
+ right: repeat_to_seq(section, count-1)};
+}
+
+
var compile = function (musexpr) {
var res = compile_aux(musexpr, 0);
return res.notes;
@@ -45,6 +55,7 @@ var compile_aux = function (musexpr, start0) {
}
else if(musexpr.tag === 'repeat'){
+ return compile_aux(repeat_to_seq(musexpr.section, musexpr.count), start0);
}
else if(musexpr.tag === 'seq'){
@@ -71,12 +82,18 @@ var melody_mus =
{ tag: 'seq',
left:
{ tag: 'seq',
- left: { tag: 'note', pitch: 'a4', dur: 250 },
+ left: { tag: 'repeat',
+ section: { tag: 'note', pitch: 'c4', dur: 250 },
+ count: 3 },
right: { tag: 'note', pitch: 'b4', dur: 250 } },
right:
{ tag: 'seq',
left: { tag: 'rest', dur: 500 },
right: { tag: 'note', pitch: 'd4', dur: 500 } } };
+
console.log(melody_mus);
-console.log(compile(melody_mus));
+console.log(compile(melody_mus));
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.