From c8a80e5aaa56545dd66f34095a036aff55b69b64 Mon Sep 17 00:00:00 2001 From: Extremesecrecy <10959169+extremesecrecy@users.noreply.github.com> Date: Wed, 23 Jul 2025 19:08:50 -0700 Subject: [PATCH] Same Device Support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated the input and output device change handlers so new settings are validated through applyAlsaDevices, ensuring latency and OK status are refreshed Added a new “useSameDevice” flag in the Jack server settings dialog state to track whether input and output devices are locked together Initialized the flag based on whether the current configuration uses the same input and output device Updated device handlers to mirror the input device into the output device when the toggle is enabled Inserted a checkbox labeled “Use same device for input/output” into the dialog UI and hid the output selector when this option is active --- vite/src/pipedal/JackServerSettingsDialog.tsx | 94 ++++++++++++++----- 1 file changed, 69 insertions(+), 25 deletions(-) diff --git a/vite/src/pipedal/JackServerSettingsDialog.tsx b/vite/src/pipedal/JackServerSettingsDialog.tsx index a295bb5..c90166d 100644 --- a/vite/src/pipedal/JackServerSettingsDialog.tsx +++ b/vite/src/pipedal/JackServerSettingsDialog.tsx @@ -42,6 +42,8 @@ import Typography from '@mui/material/Typography'; import { PiPedalModel, PiPedalModelFactory } from './PiPedalModel'; import IconButtonEx from './IconButtonEx'; import RefreshIcon from '@mui/icons-material/Refresh'; +import Checkbox from '@mui/material/Checkbox'; +import FormControlLabel from '@mui/material/FormControlLabel'; import AlsaDeviceInfo from './AlsaDeviceInfo'; @@ -60,6 +62,7 @@ interface JackServerSettingsDialogState { jackServerSettings: JackServerSettings; alsaDevices?: AlsaDeviceInfo[]; okEnabled: boolean; + useSameDevice: boolean; } const styles = (theme: Theme) => @@ -249,11 +252,13 @@ const JackServerSettingsDialog = withStyles( this.model = PiPedalModelFactory.getInstance(); + const sameDevice = props.jackServerSettings.alsaInputDevice === props.jackServerSettings.alsaOutputDevice; this.state = { latencyText: getLatencyText(props.jackServerSettings), jackServerSettings: props.jackServerSettings.clone(), // invalid, but not nullish alsaDevices: undefined, - okEnabled: false + okEnabled: false, + useSameDevice: sameDevice }; } mounted: boolean = false; @@ -268,7 +273,8 @@ const JackServerSettingsDialog = withStyles( alsaDevices: devices, jackServerSettings: settings, latencyText: getLatencyText(settings), - okEnabled: isOkEnabled(settings,devices) + okEnabled: isOkEnabled(settings,devices), + useSameDevice: settings.alsaInputDevice === settings.alsaOutputDevice }); } else { this.setState({ alsaDevices: devices }); @@ -304,6 +310,11 @@ const JackServerSettingsDialog = withStyles( } } + if (this.state.useSameDevice) { + result.alsaOutputDevice = result.alsaInputDevice; + outDevice = inDevice; + } + if (!inDevice || !outDevice) { result.valid = false; return result; @@ -341,7 +352,8 @@ const JackServerSettingsDialog = withStyles( this.setState({ jackServerSettings: settings, latencyText: getLatencyText(settings), - okEnabled: isOkEnabled(settings,this.state.alsaDevices) + okEnabled: isOkEnabled(settings,this.state.alsaDevices), + useSameDevice: settings.alsaInputDevice === settings.alsaOutputDevice }); if (!this.state.alsaDevices) { this.requestAlsaInfo(); @@ -418,25 +430,43 @@ const JackServerSettingsDialog = withStyles( this.props.onApply(this.state.jackServerSettings.clone()); } }; - handleInputDeviceChanged(e: any) { - const d = e.target.value as string; - let s = this.state.jackServerSettings.clone(); - s.alsaInputDevice = d; - this.setState({ - jackServerSettings: s, - okEnabled: isOkEnabled(s, this.state.alsaDevices) - }); - } - - handleOutputDeviceChanged(e: any) { - const d = e.target.value as string; - let s = this.state.jackServerSettings.clone(); - s.alsaOutputDevice = d; - this.setState({ - jackServerSettings: s, - okEnabled: isOkEnabled(s, this.state.alsaDevices) - }); - } + handleInputDeviceChanged(e: any) { + const d = e.target.value as string; + let s = this.state.jackServerSettings.clone(); + s.alsaInputDevice = d; + if (this.state.useSameDevice) { + s.alsaOutputDevice = d; + } + this.setState({ + jackServerSettings: s, + okEnabled: isOkEnabled(s, this.state.alsaDevices) + }); + } + + handleOutputDeviceChanged(e: any) { + const d = e.target.value as string; + let s = this.state.jackServerSettings.clone(); + s.alsaOutputDevice = d; + if (this.state.useSameDevice) { + s.alsaInputDevice = d; + } + this.setState({ + jackServerSettings: s, + okEnabled: isOkEnabled(s, this.state.alsaDevices) + }); + } + handleUseSameDeviceChanged(e: any, checked: boolean) { + let s = this.state.jackServerSettings.clone(); + const useSame = checked; + if (useSame) { + s.alsaOutputDevice = s.alsaInputDevice; + } + this.setState({ + useSameDevice: useSame, + jackServerSettings: s, + okEnabled: isOkEnabled(s, this.state.alsaDevices) + }); + } render() { const classes = withStyles.getClasses(this.props); @@ -448,7 +478,10 @@ const JackServerSettingsDialog = withStyles( let selectedInputDevice = this.getSelectedDevice(this.state.jackServerSettings.alsaInputDevice); let selectedOutputDevice = this.getSelectedDevice(this.state.jackServerSettings.alsaOutputDevice); - + if (this.state.useSameDevice) { + selectedOutputDevice = selectedInputDevice; + } + let bufferSizes: number[] = getValidBufferSizesMultiple(selectedInputDevice, selectedOutputDevice); let bufferCounts = getValidBufferCountsMultiple(this.state.jackServerSettings.bufferSize, selectedInputDevice, selectedOutputDevice); let bufferSizeDisabled = !(selectedInputDevice || selectedOutputDevice); @@ -483,13 +516,14 @@ const JackServerSettingsDialog = withStyles( {/* Audio Output Device */} - + Output Device