mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-13 06:19:33 -04:00
41 lines
1.0 KiB
React
41 lines
1.0 KiB
React
import React, { useState } from 'react';
|
|
|
|
import { SelectInputDuplicate } from '@src/repl/components/panel/SettingsTab';
|
|
import { getAudioDevices } from '@strudel/webaudio';
|
|
|
|
const initdevices = new Map();
|
|
|
|
// Allows the user to select an audio interface for Strudel to play through
|
|
export function AudioDeviceSelector({ audioDeviceName, onChange, isDisabled }) {
|
|
const [devices, setDevices] = useState(initdevices);
|
|
const devicesInitialized = devices.size > 0;
|
|
|
|
const onClick = () => {
|
|
if (devicesInitialized) {
|
|
return;
|
|
}
|
|
getAudioDevices().then((devices) => {
|
|
setDevices(devices);
|
|
});
|
|
};
|
|
const onDeviceChange = (deviceName) => {
|
|
if (!devicesInitialized) {
|
|
return;
|
|
}
|
|
onChange(deviceName);
|
|
};
|
|
const options = new Map();
|
|
Array.from(devices.keys()).forEach((deviceName) => {
|
|
options.set(deviceName, deviceName);
|
|
});
|
|
return (
|
|
<SelectInputDuplicate
|
|
isDisabled={isDisabled}
|
|
options={options}
|
|
onClick={onClick}
|
|
value={audioDeviceName}
|
|
onChange={onDeviceChange}
|
|
/>
|
|
);
|
|
}
|