need to fix window message
This commit is contained in:
parent
6c9e0aaa1a
commit
2a2ddf205a
23 changed files with 126 additions and 161 deletions
41
website/src/repl/components/panel/AudioDeviceSelector.jsx
Normal file
41
website/src/repl/components/panel/AudioDeviceSelector.jsx
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import React, { useState } from 'react';
|
||||
import { getAudioDevices, setAudioDevice } from '../../util.mjs';
|
||||
import { SelectInput } from './SelectInput';
|
||||
|
||||
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;
|
||||
}
|
||||
const deviceID = devices.get(deviceName);
|
||||
onChange(deviceName);
|
||||
setAudioDevice(deviceID);
|
||||
};
|
||||
const options = new Map();
|
||||
Array.from(devices.keys()).forEach((deviceName) => {
|
||||
options.set(deviceName, deviceName);
|
||||
});
|
||||
return (
|
||||
<SelectInput
|
||||
isDisabled={isDisabled}
|
||||
options={options}
|
||||
onClick={onClick}
|
||||
value={audioDeviceName}
|
||||
onChange={onDeviceChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue