diff options
| -rw-r--r-- | player.mjs | 20 | ||||
| -rw-r--r-- | scale.mjs | 10 |
2 files changed, 11 insertions, 19 deletions
@@ -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; } @@ -9,25 +9,15 @@ export function naturalNotesBetween(a, b) { } export function chromaticNotesBetween(a, b) { - console.log('chromaticNotesBetween', a, b); const [aNote, bNote] = [a, b].map(x => Note.fromString(x)); - console.log(' -- aNote', aNote); - console.log(' -- bNote', bNote); const aIndex = Note.noteRange.findIndex(x => aNote.toString() == x.toString()); const bIndex = Note.noteRange.findIndex(x => bNote.toString() == x.toString()); - console.log(' -- aNote', aIndex); - console.log(' -- bNote', bIndex); return aIndex - bIndex; } export function toCents([aNote, aChord], [bNote, bChord]) { - console.debug('toCents', [aNote, aChord], [bNote, bChord]); - console.debug('- a', [aNote, aChord]); - console.debug('- b', [bNote, bChord]); const offset = (aNote.distanceTo(bNote)) * 100; - console.debug('- offset', offset); const scale = (bChord - aChord) * 1200; - console.debug('- scale', scale); return scale + offset; } |
