2024-07-22 01:41:17 +02:00
|
|
|
"use client";
|
|
|
|
import { Button, ButtonGroup, Grid, Input, Slider, Stack } from "@mui/material";
|
|
|
|
import React from "react";
|
|
|
|
import { StripBusOutput, StripBusOutputEvent } from "./StripBusOutput";
|
|
|
|
|
2024-08-06 02:51:59 +02:00
|
|
|
export interface BusProps {
|
|
|
|
values?: Partial<BusState>;
|
2024-07-30 02:39:44 +02:00
|
|
|
onChange: (event: BusEvent) => any;
|
2024-07-22 01:41:17 +02:00
|
|
|
}
|
|
|
|
|
2024-08-06 02:51:59 +02:00
|
|
|
export interface BusState {
|
2024-07-22 01:41:17 +02:00
|
|
|
gain: number;
|
|
|
|
muted: boolean;
|
2024-08-06 02:51:59 +02:00
|
|
|
selected: boolean;
|
2024-07-22 01:41:17 +02:00
|
|
|
}
|
|
|
|
|
2024-08-06 02:51:59 +02:00
|
|
|
export type BusEvent = BusMuted | BusGainChanged | BusSelectToggle;
|
2024-07-22 01:41:17 +02:00
|
|
|
|
2024-08-06 02:51:59 +02:00
|
|
|
export interface BusGainChanged {
|
2024-07-22 01:41:17 +02:00
|
|
|
type: "StripGainChanged";
|
|
|
|
gain: number;
|
|
|
|
}
|
2024-08-06 02:51:59 +02:00
|
|
|
export interface BusMuted {
|
2024-07-22 01:41:17 +02:00
|
|
|
type: "StripMuted";
|
|
|
|
muted: boolean;
|
|
|
|
}
|
2024-08-06 02:51:59 +02:00
|
|
|
export interface BusSelectToggle {
|
|
|
|
type: "BusSelectToggle";
|
|
|
|
selected: boolean;
|
|
|
|
}
|
2024-07-22 01:41:17 +02:00
|
|
|
|
2024-08-06 02:51:59 +02:00
|
|
|
export class Bus extends React.Component<BusProps, BusState> {
|
|
|
|
constructor(props: BusProps) {
|
2024-07-22 01:41:17 +02:00
|
|
|
super(props);
|
2024-08-06 02:51:59 +02:00
|
|
|
const { values: initialValues } = props;
|
|
|
|
const defaultValues: BusState = {
|
|
|
|
gain: 0,
|
|
|
|
selected: false,
|
|
|
|
muted: false,
|
|
|
|
};
|
|
|
|
const getValue = (name: keyof typeof defaultValues) => {
|
|
|
|
if (initialValues === undefined) return defaultValues[name];
|
|
|
|
return initialValues[name] !== undefined
|
|
|
|
? defaultValues[name]
|
|
|
|
: initialValues[name];
|
2024-07-22 01:41:17 +02:00
|
|
|
};
|
2024-08-06 02:51:59 +02:00
|
|
|
this.state = Object.fromEntries(
|
|
|
|
Object.entries(defaultValues).map(([name]) => [
|
|
|
|
name,
|
|
|
|
getValue(name as keyof typeof defaultValues) as any,
|
|
|
|
])
|
|
|
|
) as BusState;
|
2024-07-22 01:41:17 +02:00
|
|
|
}
|
2024-08-06 02:51:59 +02:00
|
|
|
onResetDefaults(e: React.MouseEvent) {}
|
2024-07-22 01:41:17 +02:00
|
|
|
onKeyDown(event: React.KeyboardEvent) {
|
2024-07-30 02:39:44 +02:00
|
|
|
console.log(event);
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
2024-07-30 02:39:44 +02:00
|
|
|
onStripWheel(event: React.WheelEvent) {
|
|
|
|
console.log(event);
|
|
|
|
}
|
2024-07-22 01:41:17 +02:00
|
|
|
onMuteToggle() {
|
|
|
|
this.setState(
|
|
|
|
(state) => ({ muted: !state.muted }),
|
|
|
|
() => {
|
|
|
|
this.props.onChange({ type: "StripMuted", muted: this.state.muted });
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2024-08-06 02:51:59 +02:00
|
|
|
onSelectToggle() {
|
|
|
|
this.setState(
|
|
|
|
(state) => ({ selected: !state.selected }),
|
|
|
|
() => {
|
|
|
|
this.props.onChange({
|
|
|
|
type: "BusSelectToggle",
|
|
|
|
selected: this.state.selected,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2024-07-22 01:41:17 +02:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<>
|
2024-08-06 02:51:59 +02:00
|
|
|
<Stack alignItems={"center"} direction={"row"} spacing={0}>
|
|
|
|
<Input
|
|
|
|
inputProps={{
|
|
|
|
"aria-labelledby": "input-slider",
|
|
|
|
itemType: "number",
|
|
|
|
}}
|
|
|
|
value={this.state.gain}
|
|
|
|
onWheel={(ev) => this.onStripWheel(ev)}
|
|
|
|
size="small"
|
|
|
|
sx={{ width: "50px" }}
|
|
|
|
/>
|
|
|
|
<Slider
|
|
|
|
sx={{
|
|
|
|
margin: "5px",
|
|
|
|
marginInline: "15px",
|
|
|
|
}}
|
|
|
|
// orientation="vertical"
|
|
|
|
defaultValue={0.0}
|
|
|
|
step={0.1}
|
|
|
|
min={-60}
|
|
|
|
max={12}
|
|
|
|
value={this.state.gain}
|
|
|
|
onChange={(ev) =>
|
|
|
|
this.onChange(
|
|
|
|
ev as unknown as React.ChangeEvent<HTMLInputElement>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
onKeyDown={(ev) => this.onKeyDown(ev)}
|
|
|
|
/>
|
2024-07-22 01:41:17 +02:00
|
|
|
|
2024-08-06 02:51:59 +02:00
|
|
|
<ButtonGroup>
|
|
|
|
<Button
|
|
|
|
onClick={() => this.onMuteToggle()}
|
|
|
|
variant={this.state.muted ? "contained" : "outlined"}
|
|
|
|
color={"error"}
|
|
|
|
>
|
|
|
|
Mute
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
onClick={() => this.onSelectToggle()}
|
|
|
|
sx={{}}
|
|
|
|
variant={this.state.selected ? "contained" : "outlined"}
|
|
|
|
color={"warning"}
|
|
|
|
>
|
|
|
|
S
|
|
|
|
</Button>
|
|
|
|
</ButtonGroup>
|
|
|
|
</Stack>
|
|
|
|
{/* <Stack>
|
2024-07-22 01:41:17 +02:00
|
|
|
<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)}
|
|
|
|
default={{ enabled: this.state.buses[i] }}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</ButtonGroup>
|
2024-07-30 02:39:44 +02:00
|
|
|
</Stack> */}
|
2024-07-22 01:41:17 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|