From 21e0744d3d21ecae21e61718de4ac353ce19c28a Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 28 Jul 2025 16:29:50 -0400 Subject: add realtime note selection --- player.mjs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'player.mjs') diff --git a/player.mjs b/player.mjs index c8707b2..02feb6c 100644 --- a/player.mjs +++ b/player.mjs @@ -73,8 +73,7 @@ export default class extends HTMLElement { } } - start() { - console.debug('Player#start', this); + update() { for (let i = 0; i < this.offsets.length; i++) { if (!this.notes[i]) { const note = new OscillatorNode(audioCtx, { @@ -83,21 +82,30 @@ export default class extends HTMLElement { periodicWave: tromboneWave, }); note.connect(this.globalGain); - note.start(); + if (this.isPlaying) { + note.start(); + } this.notes[i] = note; } const note = this.notes[i]; note.detune.setValueAtTime(this.offsets[i], audioCtx.currentTime); } for (let j = this.notes.length-1; j >= this.offsets.length; j--) { - this.notes[j].stop(); + const note = this.notes[j]; + if (note && this.isPlaying) { + note.stop(); + } delete this.notes[j]; } } + start() { + console.debug('Player#start', this); + this.notes.forEach(n => n.start()); + } + stop() { console.debug('Player#stop', this); this.notes.forEach(n => n.stop()); - this.notes = []; } } -- cgit v1.3