Published
Edited
Jan 8, 2019
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
tempoToMs = tempo => Math.floor(60000000 / tempo);
Insert cell
Insert cell
Insert cell
{
if (audioOut && synth && player) {
let ts = 0
let cid = 0
let events = [
[
ts,
cid++,
[
0xff,0x51,0x03,
Math.floor(mspt / 0x10000),
Math.floor(mspt / 0x100) % 0x100,
mspt % 0x100
]
]
]

let addPatch = (ch, program) => {
events.push([ts, cid++, [0xc0 + ch, program]]);
}

let addControl = (ch, cc, v) => {
events.push([ts, cid++, [0xb0 + ch, cc, v]]);
}

let addControlLerp = (ch, cc, v1, v2, duration) => {
let lerpEvents = genControlLerp(ts, cid, ch, cc, v1, v2, duration);
cid += lerpEvents.length;
events = events.concat(lerpEvents);
}

let addNote = (ch, note, v1, v2, duration) => {
let noteEvents = genNote(ts, cid, ch, note, v1, v2, duration);
cid += noteEvents.length;
events = events.concat(noteEvents);
}

let wait = duration => {
ts += duration;
}

let doCycle = (ch, note, nd, vd) => {
addControlLerp(ch, 11, 127, 0, vd);
addNote(ch, note, 0x70, 0, nd);
wait(ppqn / 4);
}

addPatch(0, 2); // change patch
addPatch(1, 0); // change patch
addPatch(2, 1); // change patch
addControl(0, 7, 127); // set vol
addControl(1, 7, 127); // set vol
addControl(2, 7, 127); // set vol

let mainPattern = () => {
pattern.forEach(n => {
doCycle(0, n, ppqn / 4, ppqn /8);
});
};

let mainPattern2 = () => {
pattern.forEach(n => {
doCycle(1, n - 12, ppqn * 3, ppqn * 3);
mainPattern();
});
};

let mainPattern3 = () => {
pattern.forEach(n => {
doCycle(2, n - 24, ppqn * 3, ppqn * 3);
mainPattern2();
});
};

mainPattern3();

synth.reset();
player.playMIDI([events], ppqn); // play it!

invalidation.then(() => {
synth.kill_all_voices();
synth.reset_all_channels();
player.stop();
})
yield events
}
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more