Published
Edited
Jan 9, 2019
1 fork
Importers
9 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
track1 = [
{ len: 1/8 },
72, -1, -1, 67,
-1, -1, 64, -1,
-1, 69, -1, 71,
-1, 70, 69, -1,
{ len: 1/6 },
67, 76, 79,
{ len: 1/8 },
81, -1, 77, 79,
-1, 76, -1, 72,
74, 71, -1, -1,
]
Insert cell
track2 = [
{ len: 1/8 },
64, -1, -1, 60,
-1, -1, 55, -1,
-1, 60, -1, 62,
-1, 61, 60, -1,
{ len: 1/6 },
60, 67, 71,
{ len: 1/8 },
72, -1, 69, 71,
-1, 69, -1, 64,
65, 62, -1, -1,
]
Insert cell
track3 = [
{ len: 1/8 },
55, -1, -1, 52,
-1, -1, 48, -1,
-1, 53, -1, 55,
-1, 54, 53, -1,
{ len: 1/6 },
52, 60, 64,
{ len: 1/8 },
65, -1, 62, 64,
-1, 60, -1, 57,
59, 55, -1, -1,
]
Insert cell
Insert cell
song = ({ bpm: bpm, tracks: [track1, track2, track3] })
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
songToEvents = song => {
let events = []
let gid = 0;
song.tracks.forEach((track, t) => {
let tsTime = 0;
let noteLen = defaultNoteLen;
let bpm = song.bpm;
track.forEach((event, i) => {
if (typeof event == "number") {
const noteLenTime = beatsToSeconds(noteLen * 4, bpm)
if (event >= 0) {
events.push([tsTime, gid++, t, i, noteNumberToFreq(event), noteLenTime])
}
tsTime += noteLenTime
} else {
if (event.len) {
noteLen = event.len
}
};
});
});
return events
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
beatsToSeconds = (ts, bpm) => 60 / bpm * ts
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
noteNumberToFreq = noteNumber => tuningFreq * Math.pow(octaveMultiple, (noteNumber - tuningNoteNumber) / toneDivisions)
Insert cell
Insert cell
Insert cell
Insert cell
env = ({
"attack": 0.003,
"decay": 0.4,
"sustain": 0.0,
"release": 0.01
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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