"use client"; import { Button, ButtonGroup, Grid, Input, Slider, Stack } from "@mui/material"; import React from "react"; import { StripBusOutput, StripBusOutputEvent } from "./StripBusOutput"; export interface StripProps { physicalBuses: number; virtualBuses: number; default?: Partial; onChange: (event: StripEvent) => any; } export interface StripState { gain: number; buses: boolean[]; 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 { constructor(props: StripProps) { super(props); const buses = (props.default && props.default.buses) || []; this.state = { gain: props.default && props.default.gain !== undefined ? props.default.gain : 0, buses: [...Array(props.physicalBuses + props.virtualBuses)].map((_v, k) => buses[k] === undefined ? false : buses[k] ), muted: props.default && props.default.muted !== undefined ? props.default.muted : false, }; } onKeyDown(event: React.KeyboardEvent) { if (event.key === "ArrowLeft" || event.key === "ArrowRight") { event.preventDefault(); } } onChange(event: React.ChangeEvent) { 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) { const buses = this.state.buses; buses[ event.isVirtual ? this.props.physicalBuses + event.busId : event.busId ] = event.enabled; this.setState({ buses, }); 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 ( <> this.onStripWheel(ev)} size="small" sx={{ width: "50px" }} /> this.onChange( ev as unknown as React.ChangeEvent ) } onKeyDown={(ev) => this.onKeyDown(ev)} /> {[ ...Array(this.props.physicalBuses + this.props.virtualBuses), ].map((_v, i) => ( this.onBusChange(ev)} default={{ enabled: this.state.buses[i] }} /> ))} ); } }