2024-07-22 01:41:17 +02:00
|
|
|
"use client";
|
2024-08-06 02:51:59 +02:00
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Button,
|
|
|
|
ButtonGroup,
|
|
|
|
Grid,
|
|
|
|
Input,
|
|
|
|
Slider,
|
|
|
|
Stack,
|
|
|
|
} from "@mui/material";
|
2024-07-22 01:41:17 +02:00
|
|
|
import React from "react";
|
|
|
|
import { StripBusOutput, StripBusOutputEvent } from "./StripBusOutput";
|
|
|
|
|
|
|
|
export interface StripProps {
|
|
|
|
physicalBuses: number;
|
|
|
|
virtualBuses: number;
|
2024-08-06 02:51:59 +02:00
|
|
|
values?: Partial<StripState>;
|
2024-07-30 02:39:44 +02:00
|
|
|
onChange: (event: StripEvent) => any;
|
2024-07-22 01:41:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface StripState {
|
|
|
|
gain: number;
|
2024-08-06 02:51:59 +02:00
|
|
|
outputBuses: boolean[];
|
2024-07-22 01:41:17 +02:00
|
|
|
muted: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type StripEvent = StripBusOutputChanged | StripMuted | StripGainChanged;
|
|
|
|
|
|
|
|
export interface StripBusOutputChanged extends StripBusOutputEvent {
|
|
|
|
type: "StripBusOutputChanged";
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface StripGainChanged {
|
|
|
|
type: "StripGainChanged";
|
|
|
|
gain: number;
|
|
|
|
}
|
|
|
|
export interface StripMuted {
|
|
|
|
type: "StripMuted";
|
|
|
|
muted: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Strip extends React.Component<StripProps, StripState> {
|
|
|
|
constructor(props: StripProps) {
|
|
|
|
super(props);
|
2024-08-06 02:51:59 +02:00
|
|
|
const { values: initialValues } = props;
|
|
|
|
const defaultValues: StripState = {
|
|
|
|
gain: 0,
|
|
|
|
outputBuses: [...Array(props.physicalBuses + props.virtualBuses)].map(
|
|
|
|
(_v, k) => false
|
2024-07-22 01:41:17 +02:00
|
|
|
),
|
2024-08-06 02:51:59 +02:00
|
|
|
muted: false,
|
2024-07-22 01:41:17 +02:00
|
|
|
};
|
2024-08-06 02:51:59 +02:00
|
|
|
const getValue = (name: keyof typeof defaultValues) => {
|
|
|
|
if (initialValues === undefined) return defaultValues[name];
|
|
|
|
return initialValues[name] !== undefined
|
|
|
|
? defaultValues[name]
|
|
|
|
: initialValues[name];
|
|
|
|
};
|
|
|
|
this.state = Object.fromEntries(
|
|
|
|
Object.entries(defaultValues).map(([name]) => [
|
|
|
|
name,
|
|
|
|
getValue(name as keyof typeof defaultValues) as any,
|
|
|
|
])
|
|
|
|
) as StripState;
|
|
|
|
}
|
|
|
|
onResetDefaults(e: React.MouseEvent) {
|
|
|
|
e.stopPropagation();
|
|
|
|
this.setState({ gain: 0 });
|
2024-07-22 01:41:17 +02:00
|
|
|
}
|
|
|
|
onKeyDown(event: React.KeyboardEvent) {
|
2024-07-30 02:39:44 +02:00
|
|
|
console.log(event);
|
2024-08-06 02:51:59 +02:00
|
|
|
|
2024-07-22 01:41:17 +02:00
|
|
|
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onChange(event: React.ChangeEvent<HTMLInputElement>) {
|
|
|
|
const multiplier = (event as unknown as React.KeyboardEvent).shiftKey
|
|
|
|
? 2
|
|
|
|
: 1;
|
|
|
|
const changedGain =
|
|
|
|
parseFloat((event.target as HTMLInputElement).value) * multiplier;
|
|
|
|
this.setState({
|
|
|
|
gain: changedGain,
|
|
|
|
});
|
|
|
|
this.props.onChange({
|
|
|
|
type: "StripGainChanged",
|
|
|
|
gain: changedGain,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
onBusChange(event: StripBusOutputEvent) {
|
2024-08-06 02:51:59 +02:00
|
|
|
const buses = this.state.outputBuses;
|
2024-07-22 01:41:17 +02:00
|
|
|
buses[
|
|
|
|
event.isVirtual ? this.props.physicalBuses + event.busId : event.busId
|
|
|
|
] = event.enabled;
|
|
|
|
this.setState({
|
2024-08-06 02:51:59 +02:00
|
|
|
outputBuses: buses,
|
2024-07-22 01:41:17 +02:00
|
|
|
});
|
|
|
|
this.props.onChange({
|
|
|
|
type: "StripBusOutputChanged",
|
|
|
|
busId: event.busId,
|
|
|
|
isVirtual: event.isVirtual,
|
|
|
|
enabled: event.enabled,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
onStripWheel(event: React.WheelEvent) {
|
|
|
|
console.log(event);
|
|
|
|
}
|
|
|
|
onMuteToggle() {
|
|
|
|
this.setState(
|
|
|
|
(state) => ({ muted: !state.muted }),
|
|
|
|
() => {
|
|
|
|
this.props.onChange({ type: "StripMuted", muted: this.state.muted });
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<>
|
2024-08-06 02:51:59 +02:00
|
|
|
<Stack direction={"row"}>
|
|
|
|
<Stack alignItems={"center"} style={{ maxWidth: "min-content" }}>
|
2024-07-22 01:41:17 +02:00
|
|
|
<Input
|
|
|
|
inputProps={{
|
|
|
|
"aria-labelledby": "input-slider",
|
|
|
|
itemType: "number",
|
|
|
|
}}
|
|
|
|
value={this.state.gain}
|
|
|
|
onWheel={(ev) => this.onStripWheel(ev)}
|
|
|
|
size="small"
|
2024-08-06 02:51:59 +02:00
|
|
|
sx={{ marginInline: "5px" }}
|
2024-07-22 01:41:17 +02:00
|
|
|
/>
|
|
|
|
<Slider
|
|
|
|
sx={{
|
|
|
|
margin: "5px",
|
2024-08-06 02:51:59 +02:00
|
|
|
marginBlock: "15px",
|
2024-07-22 01:41:17 +02:00
|
|
|
}}
|
|
|
|
orientation="vertical"
|
|
|
|
defaultValue={0.0}
|
|
|
|
step={0.1}
|
|
|
|
min={-60}
|
|
|
|
max={12}
|
|
|
|
value={this.state.gain}
|
|
|
|
aria-label="Temperature"
|
|
|
|
onChange={(ev) =>
|
|
|
|
this.onChange(
|
|
|
|
ev as unknown as React.ChangeEvent<HTMLInputElement>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
onKeyDown={(ev) => this.onKeyDown(ev)}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
onClick={() => this.onMuteToggle()}
|
|
|
|
variant={this.state.muted ? "contained" : "outlined"}
|
|
|
|
color={"error"}
|
2024-08-06 02:51:59 +02:00
|
|
|
style={{ paddingInline: "0px", maxWidth: "5px" }}
|
|
|
|
size="large"
|
2024-07-22 01:41:17 +02:00
|
|
|
>
|
|
|
|
Mute
|
|
|
|
</Button>
|
|
|
|
</Stack>
|
|
|
|
<Stack>
|
|
|
|
<ButtonGroup orientation="vertical">
|
|
|
|
{[
|
|
|
|
...Array(this.props.physicalBuses + this.props.virtualBuses),
|
|
|
|
].map((_v, i) => (
|
|
|
|
<StripBusOutput
|
|
|
|
key={`${i < this.props.physicalBuses ? "a" : "b"}${
|
|
|
|
i < this.props.physicalBuses
|
|
|
|
? i
|
|
|
|
: i - this.props.physicalBuses
|
|
|
|
}`}
|
|
|
|
id={
|
|
|
|
i < this.props.physicalBuses
|
|
|
|
? i
|
|
|
|
: i - this.props.physicalBuses
|
|
|
|
}
|
|
|
|
isVirtual={i < this.props.physicalBuses ? false : true}
|
|
|
|
onChange={(ev) => this.onBusChange(ev)}
|
2024-08-06 02:51:59 +02:00
|
|
|
default={{ enabled: this.state.outputBuses[i] }}
|
2024-07-22 01:41:17 +02:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</ButtonGroup>
|
|
|
|
</Stack>
|
2024-08-06 02:51:59 +02:00
|
|
|
</Stack>
|
2024-07-22 01:41:17 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|