summaryrefslogtreecommitdiffstats
path: root/player.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@spork.org>2025-07-28 15:36:21 -0400
committerBrian Cully <bjc@spork.org>2025-07-28 15:36:21 -0400
commit9620d3750c54b21c3da0460cea117b57fbeb9eac (patch)
tree387b04a089a7fa1c8b5ab381616fa81561c55e7a /player.mjs
parentd9be9dc9a0b72b08d5bfaf3803bb4c2ba1fb84d1 (diff)
downloadchords-9620d3750c54b21c3da0460cea117b57fbeb9eac.tar.gz
chords-9620d3750c54b21c3da0460cea117b57fbeb9eac.zip
get volume control working
Diffstat (limited to 'player.mjs')
-rw-r--r--player.mjs20
1 files changed, 11 insertions, 9 deletions
diff --git a/player.mjs b/player.mjs
index 988d5d6..c8707b2 100644
--- a/player.mjs
+++ b/player.mjs
@@ -12,8 +12,6 @@ const tromboneWave = new PeriodicWave(audioCtx, {
imag: Trombone.imag
});
-const globalGain = new GainNode(audioCtx, { gain: 0.06 })
-
export default class extends HTMLElement {
static name = 'x-player'
static register() {
@@ -21,10 +19,12 @@ export default class extends HTMLElement {
customElements.define(this.name, this);
}
+ // A4
+ aFreq = 440;
+
// oscillatornodes
notes = [];
getOffsets = () => [];
- detuneParams = [];
constructor() {
super();
@@ -32,14 +32,18 @@ export default class extends HTMLElement {
}
connectedCallback() {
+ this.globalGain = audioCtx.createGain();
+ this.globalGain.connect(audioCtx.destination);
+ this.globalGain.gain.setValueAtTime(this.volume, audioCtx.currentTime);
+
this.querySelector('.volume').onchange = e => {
console.debug('vol changed', e, this.volume);
- globalGain.setValueAtTime(0.1, audioCtx.currentTime);
- globalGain.value = this.volume;
+ this.globalGain.gain.setValueAtTime(this.volume, audioCtx.currentTime);
}
}
get volume() {
+ console.debug('Player#volume', this.querySelector('.volume').value)
return Number(this.querySelector('.volume').value);
}
@@ -74,13 +78,11 @@ export default class extends HTMLElement {
for (let i = 0; i < this.offsets.length; i++) {
if (!this.notes[i]) {
const note = new OscillatorNode(audioCtx, {
- frequency: 440, // a above middle c (c4)
- // detune: o,
- // type: 'sine',
+ frequency: this.aFreq,
type: 'custom',
periodicWave: tromboneWave,
});
- note.connect(globalGain).connect(audioCtx.destination);
+ note.connect(this.globalGain);
note.start();
this.notes[i] = note;
}