From 81d889d66e9765d1f5ab6b2374143842c703891b Mon Sep 17 00:00:00 2001 From: Maksym Date: Thu, 8 Aug 2024 00:33:48 +0200 Subject: [PATCH] modified: src/app/component/Bus.tsx modified: src/app/component/BusesList.tsx modified: src/app/component/Strip.tsx modified: src/app/page.tsx --- src/app/component/Bus.tsx | 58 ++++++++++++++++++++++++++------ src/app/component/BusesList.tsx | 11 +++--- src/app/component/Strip.tsx | 59 ++++++++++++++++++++------------- src/app/page.tsx | 9 +++-- 4 files changed, 96 insertions(+), 41 deletions(-) diff --git a/src/app/component/Bus.tsx b/src/app/component/Bus.tsx index 1dedfb6..822b2c7 100644 --- a/src/app/component/Bus.tsx +++ b/src/app/component/Bus.tsx @@ -6,7 +6,9 @@ import { Input, Slider, Stack, + styled, TextField, + Typography, } from "@mui/material"; import React from "react"; import { StripBusOutput, StripBusOutputEvent } from "./StripBusOutput"; @@ -14,18 +16,17 @@ import { EventCounter } from "@/utils/EventCounter"; export interface BusProps { values?: Partial>; - showInputdB?: boolean; + width: number; name: string; onChange: (event: BusEvent) => any; } -type StateDefaultValueException = "showInputdB"; +type StateDefaultValueException = ""; export interface BusState { gain: number; muted: boolean; selected: boolean; - showInputdB: boolean; } export type BusEvent = BusMuted | BusGainChanged | BusSelectToggle; @@ -50,6 +51,25 @@ export class Bus extends React.Component { selected: false, muted: false, }; + slider = styled(Slider)(({ theme }) => ({ + "& .MuiSlider-valueLabel": { + top: 0, + fontFamily: '"Roboto","Helvetica","Arial",sans-serif', + fontWeight: 400, + fontSize: "0.75rem", + width:"4em", + letterSpacing: "0.03333em", + backgroundColor: "unset", + color: theme.palette.text.primary, + "&::before": { + display: "none", + }, + "& *": { + background: "transparent", + color: theme.palette.mode === "dark" ? "#fff" : "#000", + }, + }, + })); constructor(props: BusProps) { super(props); let { values: initialValues } = props; @@ -60,14 +80,13 @@ export class Bus extends React.Component { : initialValues[name]; }; this.state = { - ...Object.fromEntries( + ...(Object.fromEntries( Object.entries(this.defaultValues).map(([name]) => [ name, getValue(name as keyof typeof this.defaultValues) as any, ]) - ), - showInputdB: props.showInputdB !== undefined ? props.showInputdB : true, - } as BusState; + ) as Omit), + }; this.eventCounter.on({ callback: this.onResetDefaults.bind(this), count: 2, @@ -137,7 +156,7 @@ export class Bus extends React.Component { spacing={0} sx={{ width: "inherit" }} > - {this.state.showInputdB && ( + {this.props.width > 600 ? ( { variant="outlined" sx={{ minWidth: "100px", maxWidth: "100px" }} /> + ) : ( + {this.props.name} )} - + {this.state.gain}dB + + )} */} + `${e} dB`} // orientation="vertical" color={ (this.state.gain > 0 && this.state.gain < 12 && "warning") || @@ -172,6 +207,7 @@ export class Bus extends React.Component { min={-60} max={12} value={this.state.gain} + valueLabelDisplay={this.props.width > 600 ? "off" : "on"} onChange={(e) => this.onGainChange(e)} onClick={(e) => this.onSliderClick(e)} /> diff --git a/src/app/component/BusesList.tsx b/src/app/component/BusesList.tsx index 40ecfd4..42aa200 100644 --- a/src/app/component/BusesList.tsx +++ b/src/app/component/BusesList.tsx @@ -1,4 +1,4 @@ -import { Chip, Stack, Theme, Typography, useTheme, withTheme } from "@mui/material"; +import { Chip, Stack, StackOwnProps, Theme, Typography, useTheme, withTheme } from "@mui/material"; import React from "react"; import { Bus } from "./Bus"; import { range } from "@/utils/Range"; @@ -7,6 +7,7 @@ export interface BusesListProps { physical: number; virtual: number; width: number; + stackProps?: StackOwnProps } export interface BusesListState { } @@ -30,14 +31,14 @@ export class BusesList extends React.Component { key={name} > {/* */} - + ); } render(): React.ReactNode { - if (this.props.width > 600) { + if (this.props.width > 800) { return ( - 1200 ? 4 : 2}> + 1200 ? 4 : 2}> {range(this.props.physical).map(this.mapCallback.bind(this))} @@ -50,7 +51,7 @@ export class BusesList extends React.Component { ); } return ( - + {range(this.props.physical + this.props.virtual).map( this.mapCallback.bind(this) )} diff --git a/src/app/component/Strip.tsx b/src/app/component/Strip.tsx index c46de80..a8268e4 100644 --- a/src/app/component/Strip.tsx +++ b/src/app/component/Strip.tsx @@ -8,6 +8,7 @@ import { Slider, Stack, TextField, + Typography, } from "@mui/material"; import React from "react"; import { StripBusOutput, StripBusOutputEvent } from "./StripBusOutput"; @@ -17,17 +18,17 @@ export interface StripProps { physicalBuses: number; virtualBuses: number; values?: Partial; - showOutputdB?: boolean; + width: number; name: string; onChange: (event: StripEvent) => any; } -type StateDefaultValueException = "showOutputdB"; + +export type StateDefaultValueException = ""; export interface StripState { gain: number; outputBuses: boolean[]; muted: boolean; - showOutputdB: boolean; } export type StripEvent = StripBusOutputChanged | StripMuted | StripGainChanged; @@ -71,8 +72,6 @@ export class Strip extends React.Component { getValue(name as keyof typeof this.defaultValues) as any, ]) ) as Omit), - showOutputdB: - props.showOutputdB !== undefined ? props.showOutputdB : true, }; this.eventCounter.on({ callback: this.onResetDefaults.bind(this), @@ -143,27 +142,41 @@ export class Strip extends React.Component { render() { return ( <> - + - this.onStripWheel(e)} - onClick={(e) => this.stopPropagation(e)} - size="small" - type="number" - label={this.props.name} - // sx={{minWidth: "4em", maxWidth: "5em"}} - // fullWidth - /> + {this.props.width > 600 ? ( + this.onStripWheel(e)} + onClick={(e) => this.stopPropagation(e)} + size="small" + type="number" + label={this.props.name} + // sx={{minWidth: "4em", maxWidth: "5em"}} + // fullWidth + /> + ) : ( + <> + {this.props.name} + + {this.state.gain} dB + + + )} 0 && this.state.gain < 12 && "warning") || diff --git a/src/app/page.tsx b/src/app/page.tsx index 034f766..d8263ee 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -131,10 +131,11 @@ export default function Home() { {[...Array(amountOfStrips)].map((_v, stripId) => { const isPhysical = stripId < strips.physical; @@ -145,7 +146,9 @@ export default function Home() { 1098 ? 0.8 : 0) : 0 + } sx={{ minWidth: "fit-content" }} > {/* {`Strip #${ @@ -155,6 +158,7 @@ export default function Home() { onChange={(ev) => onStripEvent(ev)} physicalBuses={buses.physical} virtualBuses={buses.virtual} + width={width} name={ isPhysical ? `#${stripId + 1}` @@ -168,6 +172,7 @@ export default function Home() { Outputs