Public
Edited
Nov 13, 2023
Insert cell
Insert cell
Tone = require('tone')
Insert cell
viewof mute = html`<input type='checkbox' />`
Insert cell
viewof play = html`<input type='checkbox' />`
Insert cell
Volume = new Tone.Volume(volume)
Insert cell
{ Volume.mute = mute }
Insert cell
viewof delay = DOM.range(100, 500, 10)
Insert cell
viewof volume = html`<input type='range' min=-24 max=0 value=-12 />`
Insert cell
synth = {
//create a synth and connect it to the master output (your speakers)
var synth = new Tone.PolySynth(Tone.Synth).chain(Volume, Tone.Master);
synth.set({
oscillator: {
type: 'sine',
},
envelope: {
decay: 1,
release: 1
}
});
try {
yield synth;
yield invalidation;
} finally {
synth.dispose();
}
}
Insert cell
beat = {
let i = 0;
while (play) {
yield Promises.delay(delay, i++);
}
}
Insert cell
note = {
let noteName = String.fromCharCode(65 + (beat % 7));
if (noteName == 'B') noteName = 'D';
return `${noteName}${2 + Math.floor((beat / 7) % 4)}`;
}
Insert cell
{
synth.triggerAttackRelease(note, '4n'); // quarter note from upward scale on every beat
if (beat % 7 == 0) synth.triggerAttackRelease('E5', '8n'); //
if (beat % 14 == 0) synth.triggerAttackRelease(['G3', 'E4', 'C5'], '1n');
if (Math.floor(beat % (7 * 4)) == 16)
synth.triggerAttackRelease(['G4', 'C6', 'B5'], '4n');
if (Math.floor(beat % (7 * 4)) == 18)
synth.triggerAttackRelease(['G4', 'C6', 'A6'], '4n');
if (Math.floor(beat % (7 * 4)) == 20)
synth.triggerAttackRelease(['A4', 'C6', 'E5'], '16n');
}
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