From 69554c0762d1d21ca43926ea3559d5550be5a24a Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Fri, 29 Dec 2023 22:27:01 -0500 Subject: [PATCH] merged with vanilla updates --- website/src/repl/Repl.jsx | 17 +++++++++++++++-- website/src/repl/panel/AudioDeviceSelector.jsx | 7 ++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/website/src/repl/Repl.jsx b/website/src/repl/Repl.jsx index c89ec817..052911e9 100644 --- a/website/src/repl/Repl.jsx +++ b/website/src/repl/Repl.jsx @@ -8,6 +8,7 @@ import { code2hash, getDrawContext, logger, silence } from '@strudel.cycles/core import cx from '@src/cx.mjs'; import { transpiler } from '@strudel.cycles/transpiler'; import { getAudioContext, initAudioOnFirstClick, webaudioOutput } from '@strudel.cycles/webaudio'; +import { defaultAudioDeviceName, getAudioDevices, setAudioDevice } from './panel/AudioDeviceSelector'; import { StrudelMirror, defaultSettings } from '@strudel/codemirror'; import { createContext, useCallback, useEffect, useRef, useState } from 'react'; import { @@ -44,7 +45,6 @@ if (typeof window !== 'undefined') { } export function Repl({ embedded = false }) { - const isEmbedded = embedded || isIframe; const { panelPosition, isZen } = useSettings(); @@ -59,7 +59,6 @@ export function Repl({ embedded = false }) { }); }; const editor = new StrudelMirror({ - defaultOutput: webaudioOutput, getTime: () => getAudioContext().currentTime, transpiler, @@ -122,6 +121,20 @@ export function Repl({ embedded = false }) { editorRef.current?.updateSettings(editorSettings); }, [_settings]); + // on first load, set stored audio device if possible + useEffect(() => { + const { audioDeviceName } = _settings; + if (audioDeviceName !== defaultAudioDeviceName) { + getAudioDevices().then((devices) => { + const deviceID = devices.get(audioDeviceName); + if (deviceID == null) { + return; + } + setAudioDevice(deviceID); + }); + } + }, []); + // // UI Actions // diff --git a/website/src/repl/panel/AudioDeviceSelector.jsx b/website/src/repl/panel/AudioDeviceSelector.jsx index d39e58d2..7a3e5547 100644 --- a/website/src/repl/panel/AudioDeviceSelector.jsx +++ b/website/src/repl/panel/AudioDeviceSelector.jsx @@ -1,6 +1,7 @@ import React, { useState } from 'react'; import { getAudioContext, initializeAudioOutput } from '@strudel.cycles/webaudio'; import { SelectInput } from './SelectInput'; +import { logger } from '@strudel.cycles/core'; const initdevices = new Map(); export const defaultAudioDeviceName = 'System Standard'; @@ -22,7 +23,11 @@ export const setAudioDevice = async (id) => { // reset the audio context and dont set the sink id if it is invalid AKA System Standard selection const audioCtx = getAudioContext(!isValidID); if (isValidID) { - await audioCtx.setSinkId(id); + try { + await audioCtx.setSinkId(id); + } catch { + logger('failed to set audio interface', 'warning'); + } } initializeAudioOutput(); };