From b3522fea6ab216e14577f9534013e8991b5df9e5 Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Sat, 30 Dec 2023 22:40:27 -0500 Subject: [PATCH] prevent selection while playing to avoid artifacts --- packages/superdough/superdough.mjs | 10 +++++--- .../src/repl/panel/AudioDeviceSelector.jsx | 24 +++++++++++++++---- website/src/repl/panel/Panel.jsx | 2 +- website/src/repl/panel/SelectInput.jsx | 5 ++-- website/src/repl/panel/SettingsTab.jsx | 3 ++- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index 8b152a43..41b24d94 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -28,9 +28,13 @@ export const resetLoadedSounds = () => soundMap.set({}); let audioContext; -export const getAudioContext = (reset) => { - if (!audioContext || reset) { - audioContext = new AudioContext(); +export const setDefaultAudioContext = () => { + audioContext = new AudioContext(); +}; + +export const getAudioContext = () => { + if (!audioContext) { + setDefaultAudioContext(); } return audioContext; }; diff --git a/website/src/repl/panel/AudioDeviceSelector.jsx b/website/src/repl/panel/AudioDeviceSelector.jsx index 7a3e5547..05d44247 100644 --- a/website/src/repl/panel/AudioDeviceSelector.jsx +++ b/website/src/repl/panel/AudioDeviceSelector.jsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { getAudioContext, initializeAudioOutput } from '@strudel.cycles/webaudio'; +import { getAudioContext, initializeAudioOutput, setDefaultAudioContext } from '@strudel.cycles/webaudio'; import { SelectInput } from './SelectInput'; import { logger } from '@strudel.cycles/core'; @@ -19,21 +19,27 @@ export const getAudioDevices = async () => { }; export const setAudioDevice = async (id) => { + const audioCtx = getAudioContext(); + if (audioCtx.sinkId === id) { + console.log(audioCtx.sinkId, id); + return; + } const isValidID = (id ?? '').length > 0; - // reset the audio context and dont set the sink id if it is invalid AKA System Standard selection - const audioCtx = getAudioContext(!isValidID); if (isValidID) { try { await audioCtx.setSinkId(id); } catch { logger('failed to set audio interface', 'warning'); } + } else { + // reset the audio context and dont set the sink id if it is invalid AKA System Standard selection + setDefaultAudioContext(); } initializeAudioOutput(); }; // Allows the user to select an audio interface for Strudel to play through -export function AudioDeviceSelector({ audioDeviceName, onChange }) { +export function AudioDeviceSelector({ audioDeviceName, onChange, isDisabled }) { const [devices, setDevices] = useState(initdevices); const devicesInitialized = devices.size > 0; @@ -57,5 +63,13 @@ export function AudioDeviceSelector({ audioDeviceName, onChange }) { Array.from(devices.keys()).forEach((deviceName) => { options.set(deviceName, deviceName); }); - return ; + return ( + + ); } diff --git a/website/src/repl/panel/Panel.jsx b/website/src/repl/panel/Panel.jsx index eac31720..d809f720 100644 --- a/website/src/repl/panel/Panel.jsx +++ b/website/src/repl/panel/Panel.jsx @@ -114,7 +114,7 @@ export function Panel({ context }) { {activeFooter === 'console' && } {activeFooter === 'sounds' && } {activeFooter === 'reference' && } - {activeFooter === 'settings' && } + {activeFooter === 'settings' && } {activeFooter === 'files' && } diff --git a/website/src/repl/panel/SelectInput.jsx b/website/src/repl/panel/SelectInput.jsx index b550c7c6..a28c3936 100644 --- a/website/src/repl/panel/SelectInput.jsx +++ b/website/src/repl/panel/SelectInput.jsx @@ -1,8 +1,9 @@ import React from 'react'; -// value: ?ID, options: Map, onChange: ID => null, onClick: event => void -export function SelectInput({ value, options, onChange, onClick }) { +// value: ?ID, options: Map, onChange: ID => null, onClick: event => void, isDisabled: boolean +export function SelectInput({ value, options, onChange, onClick, isDisabled }) { return (