Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save bspaulding/d8522ae787a1c3b0629f031a7c412ace to your computer and use it in GitHub Desktop.

Select an option

Save bspaulding/d8522ae787a1c3b0629f031a7c412ace to your computer and use it in GitHub Desktop.
var events = [];
function HandleMIDI(event) {
event.trace();
events.push(event);
if (events.length === 2 && events[1].pitch !== 74) {
schedulePattern(events);
events = [];
} else if (events.length === 3) {
schedulePatternB(events);
events = [];
}
}
var bpm = 90;
var sixteenthMs = 60000 / (bpm * 4);
function schedulePattern(events) {
var one = events[0];
var five = events[1];
one.sendAfterMilliseconds(0);
one.sendAfterMilliseconds(sixteenthMs);
five.sendAfterMilliseconds(sixteenthMs * 2);
one.sendAfterMilliseconds(sixteenthMs * 3);
five.sendAfterMilliseconds(sixteenthMs * 4);
five.sendAfterMilliseconds(sixteenthMs * 5);
one.sendAfterMilliseconds(sixteenthMs * 6);
five.sendAfterMilliseconds(sixteenthMs * 7);
one.sendAfterMilliseconds(sixteenthMs * 8);
one.sendAfterMilliseconds(sixteenthMs * 9);
five.sendAfterMilliseconds(sixteenthMs * 10);
one.sendAfterMilliseconds(sixteenthMs * 11);
five.sendAfterMilliseconds(sixteenthMs * 12);
five.sendAfterMilliseconds(sixteenthMs * 13);
one.sendAfterMilliseconds(sixteenthMs * 14);
five.sendAfterMilliseconds(sixteenthMs * 15);
}
function schedulePatternB(events) {
var one = events[0];
var four = events[1];
var three = events[2]; // out of order?
one.sendAfterMilliseconds(0);
three.sendAfterMilliseconds(sixteenthMs);
four.sendAfterMilliseconds(sixteenthMs * 2);
one.sendAfterMilliseconds(sixteenthMs * 3);
four.sendAfterMilliseconds(sixteenthMs * 4);
four.sendAfterMilliseconds(sixteenthMs * 5);
one.sendAfterMilliseconds(sixteenthMs * 6);
four.sendAfterMilliseconds(sixteenthMs * 7);
one.sendAfterMilliseconds(sixteenthMs * 8);
three.sendAfterMilliseconds(sixteenthMs * 9);
four.sendAfterMilliseconds(sixteenthMs * 10);
one.sendAfterMilliseconds(sixteenthMs * 11);
four.sendAfterMilliseconds(sixteenthMs * 12);
four.sendAfterMilliseconds(sixteenthMs * 13);
one.sendAfterMilliseconds(sixteenthMs * 14);
four.sendAfterMilliseconds(sixteenthMs * 15);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment