diff --git a/packages/core/examples/canvas.html b/packages/core/examples/canvas.html index 685cc56e..736c9a22 100644 --- a/packages/core/examples/canvas.html +++ b/packages/core/examples/canvas.html @@ -27,7 +27,7 @@ const events = pattern.firstCycle(); // query first cycle events.forEach((event) => { ctx.fillStyle = event.value; - ctx.fillRect(event.whole.begin * canvas.width, 0, event.duration * canvas.width, canvas.height); + ctx.fillRect(event.whole.begin * canvas.width, 0, event.duration.valueOf() * canvas.width, canvas.height); }); } diff --git a/packages/midi/midi.mjs b/packages/midi/midi.mjs index c9b93777..52d3ecbd 100644 --- a/packages/midi/midi.mjs +++ b/packages/midi/midi.mjs @@ -69,7 +69,7 @@ Pattern.prototype.midi = function (output, channel = 1) { // await enableWebMidi() device.playNote(note, channel, { time, - duration: event.duration * 1000 - 5, + duration: event.duration.valueOf() * 1000 - 5, velocity, }); }; diff --git a/packages/tone/tone.mjs b/packages/tone/tone.mjs index 2426dac3..cf3d750a 100644 --- a/packages/tone/tone.mjs +++ b/packages/tone/tone.mjs @@ -54,14 +54,14 @@ Pattern.prototype.tone = function (instrument) { note = getPlayableNoteValue(event); instrument.triggerAttack(note, time); } else if (instrument instanceof NoiseSynth) { - instrument.triggerAttackRelease(event.duration, time); // noise has no value + instrument.triggerAttackRelease(event.duration.valueOf(), time); // noise has no value } else if (instrument instanceof Piano) { note = getPlayableNoteValue(event); instrument.keyDown({ note, time, velocity }); - instrument.keyUp({ note, time: time + event.duration, velocity }); + instrument.keyUp({ note, time: time + event.duration.valueOf(), velocity }); } else if (instrument instanceof Sampler) { note = getPlayableNoteValue(event); - instrument.triggerAttackRelease(note, event.duration, time, velocity); + instrument.triggerAttackRelease(note, event.duration.valueOf(), time, velocity); } else if (instrument instanceof Players) { if (!instrument.has(event.value)) { throw new Error(`name "${event.value}" not defined for players`); @@ -69,10 +69,10 @@ Pattern.prototype.tone = function (instrument) { const player = instrument.player(event.value); // velocity ? player.start(time); - player.stop(time + event.duration); + player.stop(time + event.duration.valueOf()); } else { note = getPlayableNoteValue(event); - instrument.triggerAttackRelease(note, event.duration, time, velocity); + instrument.triggerAttackRelease(note, event.duration.valueOf(), time, velocity); } }; return event.setContext({ ...event.context, instrument, onTrigger }); diff --git a/packages/webaudio/webaudio.mjs b/packages/webaudio/webaudio.mjs index de07a56e..f66f94bd 100644 --- a/packages/webaudio/webaudio.mjs +++ b/packages/webaudio/webaudio.mjs @@ -39,7 +39,7 @@ Pattern.prototype._wave = function (type) { const f = getFrequency(e); osc.frequency.value = f; // expects frequency.. const begin = t ?? e.whole.begin.valueOf() + lookahead; - const end = begin + e.duration; + const end = begin + e.valueOf(); osc.start(begin); osc.stop(end); // release? return osc; @@ -49,7 +49,7 @@ Pattern.prototype.adsr = function (a = 0.01, d = 0.05, s = 1, r = 0.01) { return this.withAudioNode((t, e, node) => { const velocity = e.context?.velocity || 1; const begin = t ?? e.whole.begin.valueOf() + lookahead; - const end = begin + e.duration + lookahead; + const end = begin + e.duration.valueOf() + lookahead; const envelope = adsr(a, d, s, r, velocity, begin, end); node?.connect(envelope); return envelope; diff --git a/repl/src/CodeMirror.jsx b/repl/src/CodeMirror.jsx index b58ad75a..a659e3ee 100644 --- a/repl/src/CodeMirror.jsx +++ b/repl/src/CodeMirror.jsx @@ -44,8 +44,8 @@ export const markEvent = (editor) => (time, event) => { //Tone.Transport.schedule(() => { // problem: this can be cleared by scheduler... setTimeout(() => { marks.forEach((mark) => mark.clear()); - // }, '+' + event.duration * 0.5); - }, event.duration /* * 0.9 */ * 1000); + // }, '+' + event.duration.valueOf() * 0.5); + }, event.duration.valueOf() /* * 0.9 */ * 1000); }; let parenMark; diff --git a/repl/src/static.mjs b/repl/src/static.mjs index 0fc70537..5ae319ae 100644 --- a/repl/src/static.mjs +++ b/repl/src/static.mjs @@ -45,7 +45,7 @@ async function playStatic(code) { if (!onTrigger) { if (defaultSynth) { const note = getPlayableNoteValue(event); - defaultSynth.triggerAttackRelease(note, event.duration, time, velocity); + defaultSynth.triggerAttackRelease(note, event.duration.valueOf(), time, velocity); } else { throw new Error('no defaultSynth passed to useRepl.'); } diff --git a/repl/src/useRepl.mjs b/repl/src/useRepl.mjs index d48aa141..63ea65bb 100644 --- a/repl/src/useRepl.mjs +++ b/repl/src/useRepl.mjs @@ -44,7 +44,7 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }) { if (!onTrigger) { if (defaultSynth) { const note = getPlayableNoteValue(event); - defaultSynth.triggerAttackRelease(note, event.duration, time, velocity); + defaultSynth.triggerAttackRelease(note, event.duration.valueOf(), time, velocity); } else { throw new Error('no defaultSynth passed to useRepl.'); }