summaryrefslogtreecommitdiffstats
path: root/player.mjs
diff options
context:
space:
mode:
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 = [];
}
}