diff options
| author | Brian Cully <bjc@spork.org> | 2025-07-28 16:29:50 -0400 |
|---|---|---|
| committer | Brian Cully <bjc@spork.org> | 2025-07-28 16:29:50 -0400 |
| commit | 21e0744d3d21ecae21e61718de4ac353ce19c28a (patch) | |
| tree | ed876f0c4a1f93b5e0f8b2b29b516bbfc489fba9 /player.mjs | |
| parent | 9620d3750c54b21c3da0460cea117b57fbeb9eac (diff) | |
| download | chords-21e0744d3d21ecae21e61718de4ac353ce19c28a.tar.gz chords-21e0744d3d21ecae21e61718de4ac353ce19c28a.zip | |
add realtime note selection
Diffstat (limited to 'player.mjs')
| -rw-r--r-- | player.mjs | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -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 = []; } } |
