diff --git a/package-lock.json b/package-lock.json index 39b5c85..2bf405c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", + "@fontsource/roboto": "^5.0.14", "@mui/material": "^5.15.20", "next": "14.2.4", "next-pwa": "^5.6.0", @@ -1966,6 +1967,12 @@ "resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.2.tgz", "integrity": "sha512-J4yDIIthosAsRZ5CPYP/jQvUAQtlZTTD/4suA08/FEnlxqW3sKS9iAhgsa9VYLZ6vDHn/ixJgIqRQPotoBjxIw==" }, + "node_modules/@fontsource/roboto": { + "version": "5.0.14", + "resolved": "https://registry.npmjs.org/@fontsource/roboto/-/roboto-5.0.14.tgz", + "integrity": "sha512-zHAxlTTm9RuRn9/StwclFJChf3z9+fBrOxC3fw71htjHP1BgXNISwRjdJtAKAmMe5S2BzgpnjkQR93P9EZYI/Q==", + "license": "Apache-2.0" + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.14", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", diff --git a/package.json b/package.json index 8e9aecb..ad64dcb 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", + "@fontsource/roboto": "^5.0.14", "@mui/material": "^5.15.20", "next": "14.2.4", "next-pwa": "^5.6.0", diff --git a/src/app/component/Bus.tsx b/src/app/component/Bus.tsx index 79736ac..2e67d30 100644 --- a/src/app/component/Bus.tsx +++ b/src/app/component/Bus.tsx @@ -2,6 +2,7 @@ import { Button, ButtonGroup, Grid, Input, Slider, Stack } from "@mui/material"; import React from "react"; import { StripBusOutput, StripBusOutputEvent } from "./StripBusOutput"; +import { EventCounter } from "@/utils/EventCounter"; export interface BusProps { values?: Partial; @@ -30,28 +31,36 @@ export interface BusSelectToggle { } export class Bus extends React.Component { + private eventCounter = new EventCounter<"onSliderResetDefaults">(); + private defaultValues: BusState = { + gain: 0, + selected: false, + muted: false, + }; constructor(props: BusProps) { super(props); 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]; + const getValue = (name: keyof typeof this.defaultValues) => { + if (initialValues === undefined) return this.defaultValues[name]; return initialValues[name] !== undefined - ? defaultValues[name] + ? this.defaultValues[name] : initialValues[name]; }; this.state = Object.fromEntries( - Object.entries(defaultValues).map(([name]) => [ + Object.entries(this.defaultValues).map(([name]) => [ name, - getValue(name as keyof typeof defaultValues) as any, + getValue(name as keyof typeof this.defaultValues) as any, ]) ) as BusState; + this.eventCounter.on({ + callback: this.onResetDefaults.bind(this), + count: 2, + name: "onSliderResetDefaults", + }); + } + onResetDefaults() { + this.setState({ gain: this.defaultValues.gain }); } - onResetDefaults(e: React.MouseEvent) {} onKeyDown(event: React.KeyboardEvent) { console.log(event); @@ -59,12 +68,12 @@ export class Bus extends React.Component { 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; + onGainChange(event: Event | React.ChangeEvent) { + + let changedGain = + parseFloat((event.target as HTMLInputElement).value); + if(changedGain > 12) changedGain = 12 + else if(changedGain < -60) changedGain = -60; this.setState({ gain: changedGain, }); @@ -76,7 +85,12 @@ export class Bus extends React.Component { onStripWheel(event: React.WheelEvent) { console.log(event); } - onMuteToggle() { + onSliderClick(event: React.MouseEvent) { + this.stopPropagation(event); + this.eventCounter.emit("onSliderResetDefaults"); + } + onMuteToggle(event: React.MouseEvent) { + this.stopPropagation(event); this.setState( (state) => ({ muted: !state.muted }), () => { @@ -84,7 +98,8 @@ export class Bus extends React.Component { } ); } - onSelectToggle() { + onSelectToggle(event: React.MouseEvent) { + this.stopPropagation(event); this.setState( (state) => ({ selected: !state.selected }), () => { @@ -95,6 +110,10 @@ export class Bus extends React.Component { } ); } + stopPropagation(event: Event | React.MouseEvent) { + if (event instanceof Event) event.stopImmediatePropagation(); + else event.nativeEvent.stopImmediatePropagation(); + } render() { return ( <> @@ -103,9 +122,12 @@ export class Bus extends React.Component { inputProps={{ "aria-labelledby": "input-slider", itemType: "number", + style:{padding: 0} }} value={this.state.gain} - onWheel={(ev) => this.onStripWheel(ev)} + onWheel={(e) => this.onStripWheel(e)} + onClick={(e) => this.stopPropagation(e)} + onChange={(e) => this.onGainChange(e as unknown as Event)} size="small" sx={{ width: "50px" }} /> @@ -115,29 +137,31 @@ export class Bus extends React.Component { marginInline: "15px", }} // orientation="vertical" + color={ + (this.state.gain > 0 && this.state.gain < 12 && "warning") || + (this.state.gain >= 12 && "error") || + (this.state.gain < 0 && "info") || + "primary" + } defaultValue={0.0} step={0.1} min={-60} max={12} value={this.state.gain} - onChange={(ev) => - this.onChange( - ev as unknown as React.ChangeEvent - ) - } - onKeyDown={(ev) => this.onKeyDown(ev)} + onChange={(e) => this.onGainChange(e)} + onClick={(e) => this.onSliderClick(e)} /> - + {[ ...Array(this.props.physicalBuses + this.props.virtualBuses), ].map((_v, i) => ( @@ -176,10 +187,18 @@ export class Strip extends React.Component { : i - this.props.physicalBuses } isVirtual={i < this.props.physicalBuses ? false : true} - onChange={(ev) => this.onBusChange(ev)} + onChange={(e) => this.onBusChange(e)} default={{ enabled: this.state.outputBuses[i] }} /> ))} + diff --git a/src/app/component/StripBusOutput.tsx b/src/app/component/StripBusOutput.tsx index f674a05..6e2734f 100644 --- a/src/app/component/StripBusOutput.tsx +++ b/src/app/component/StripBusOutput.tsx @@ -30,6 +30,7 @@ export class StripBusOutput extends React.Component { }; } onClick(event: React.MouseEvent) { + event.nativeEvent.stopImmediatePropagation() this.setState( (state) => ({ enabled: !state.enabled }), () => { @@ -47,8 +48,8 @@ export class StripBusOutput extends React.Component { <>