summaryrefslogtreecommitdiffstats
path: root/player.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@spork.org>2025-07-28 16:29:50 -0400
committerBrian Cully <bjc@spork.org>2025-07-28 16:29:50 -0400
commit21e0744d3d21ecae21e61718de4ac353ce19c28a (patch)
treeed876f0c4a1f93b5e0f8b2b29b516bbfc489fba9 /player.mjs
parent9620d3750c54b21c3da0460cea117b57fbeb9eac (diff)
downloadchords-21e0744d3d21ecae21e61718de4ac353ce19c28a.tar.gz
chords-21e0744d3d21ecae21e61718de4ac353ce19c28a.zip
add realtime note selection
Diffstat (limited to 'player.mjs')
-rw-r--r--player.mjs18
1 files changed, 13 insertions, 5 deletions
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 = [];
}
}