From ad2a00e9c71718764e51a9fceb7c489dd5eb3393 Mon Sep 17 00:00:00 2001 From: ergz Date: Sun, 1 Oct 2023 02:04:18 -0700 Subject: [PATCH] basic octave selection done --- basic.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/basic.js b/basic.js index 1c1ca62..9733b75 100644 --- a/basic.js +++ b/basic.js @@ -43,12 +43,34 @@ window.onload = function () { } } + function handleOctaveSelectionChange() { + let selectedRadioButton = document.querySelector( + "input[name='octavechoice']:checked" + ); + if (selectedRadioButton) { + selectedOctave = selectedRadioButton.value; + if (osc) { + osc.frequency.setValueAtTime( + octavehz(parseFloat(freq.value), parseFloat(selectedOctave)), + audioContext.currentTime + ); + } + console.log(selectedWave); + } else { + console.log("No radio button is selected."); + } + } + document .querySelectorAll("input[name='wavechoice']") .forEach((radioButton) => { radioButton.addEventListener("change", handleWaveformSelectionChange); }); + document.querySelectorAll("input[name='octavechoice']").forEach((rb) => { + rb.addEventListener("change", handleOctaveSelectionChange); + }); + document.getElementById("start").addEventListener("click", () => { if (!osc) { osc = audioContext.createOscillator();