diff --git a/README.md b/README.md index fb3f374..c0ef129 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,4 @@ This template should help get you started developing with Tauri, React and Types - Check end to end behavioour -- Make phone version \ No newline at end of file +- Make phone version (avoid slider move when scrolling horizontaly) \ No newline at end of file diff --git a/src/features/dsp408/components/GainSection/GainSection.css b/src/features/dsp408/components/GainSection/GainSection.css index c83072b..205cf88 100644 --- a/src/features/dsp408/components/GainSection/GainSection.css +++ b/src/features/dsp408/components/GainSection/GainSection.css @@ -1,3 +1,24 @@ +/* ---------- Page wrapper ---------- */ + +.gain-page { + display: contents; /* invisible on desktop; a flex column on phones */ +} + +.gain-tabs, +.gain-rotate-hint { + display: none; /* phones only */ +} + +.gain-panel__btns { + display: contents; /* desktop: buttons stay direct children of the panel */ +} + +.gain-panel__btn-short { + display: none; +} + +/* ---------- Fader strip ---------- */ + .gain-section { container-type: size; @@ -5,6 +26,7 @@ left: 0; right: 0; bottom: 0; + z-index: 20; height: var(--dsp-control-heigth); @@ -13,12 +35,9 @@ justify-content: center; box-sizing: border-box; - background: var(--bg-panel); - - z-index: 20; - border-top: var(--border-width) solid var(--border-hairline); + user-select: none; -webkit-user-select: none; } @@ -33,39 +52,50 @@ .gain-panel { position: relative; + flex: 0 0 auto; height: 100%; aspect-ratio: 1 / 4; - flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; + gap: 2cqh; + padding-bottom: 2cqh; + box-sizing: border-box; + + background: var(--bg-void); border: var(--border-width) solid var(--border-hairline); border-radius: var(--radius-md); - box-sizing: border-box; - gap: 2cqh; - background: var(--bg-void); - padding-bottom: 2cqh; } .gain-panel__title { flex: 0 0 auto; width: 100%; - text-align: center; + min-width: 0; + + padding-block: 2cqh; + font-family: var(--font-ui); font-size: 4cqh; font-weight: var(--font-weight-semibold); - padding-top: 2cqh; - padding-bottom: 2cqh; - border-bottom: var(--border-width) solid var(--border-hairline); + text-align: center; - min-width: 0; + border-bottom: var(--border-width) solid var(--border-hairline); overflow: hidden; text-overflow: ellipsis; } +.gain-panel .gain-panel__btn { + width: 85%; + min-height: 0; + padding: 2cqh 0; + font-size: 4cqh; +} + +/* ---------- Graphs ---------- */ + .gain-linear-graph-section { flex: 0 0 calc(100% - var(--dsp-control-heigth)); min-height: 0; @@ -94,17 +124,6 @@ border-radius: var(--radius-md); } -.gain-graph-title { - flex: 0 0 auto; - - text-align: center; - padding: 1cqh; - - font-family: var(--font-ui); - font-size: 2.5cqh; - font-weight: var(--font-weight-semibold); -} - .gain-graph-panel > .container { flex: 1; min-height: 0; @@ -112,42 +131,49 @@ .gain-graph-title-row { flex: 0 0 auto; + min-width: 0; display: flex; flex-direction: column; align-items: stretch; - gap: 0.75cqh; - padding: 1cqh 1.5cqh; - min-width: 0; + padding: 1cqh 1.5cqh; overflow: hidden; } -/* First row: title left, Show stages right */ +/* Title left, "Show stages" right */ .gain-graph-title-line { display: flex; align-items: center; justify-content: space-between; + gap: 1cqh; width: 100%; min-width: 0; - gap: 1cqh; +} + +.gain-graph-title { + flex: 0 0 auto; + padding: 1cqh; + + font-family: var(--font-ui); + font-size: 2.5cqh; + font-weight: var(--font-weight-semibold); + text-align: center; } .gain-graph-title-line .gain-graph-title { flex: 1 1 auto; min-width: 0; - padding: 0; text-align: left; + white-space: nowrap; overflow: hidden; text-overflow: ellipsis; - white-space: nowrap; } -/* Compact button on the right */ .gain-stages-toggle { flex: 0 0 auto; @@ -157,11 +183,11 @@ padding: 0.4cqh 1cqh; font-size: 1.8cqh; line-height: 1.2; - white-space: nowrap; } -/* Channel Selector */ +/* ---------- Channel selector ---------- */ + .magnitude-selector { width: 100%; min-width: 0; @@ -169,7 +195,6 @@ display: flex; align-items: center; flex-wrap: nowrap; - gap: 0.5cqh; overflow: hidden; @@ -183,24 +208,21 @@ display: flex; align-items: center; - gap: 0.6cqh; - font-family: var(--font-ui); - font-size: 1.8cqh; - padding: 0.4cqh 1cqh; + font-family: var(--font-ui); + font-size: 1.8cqh; + white-space: nowrap; + background: var(--bg-void); color: var(--text-muted); - border: var(--border-width) solid var(--border-hairline); border-radius: var(--radius-sm); - cursor: pointer; opacity: 0.5; - - white-space: nowrap; + cursor: pointer; overflow: hidden; } @@ -211,19 +233,384 @@ } .magnitude-selector__swatch { + flex: 0 0 auto; width: 1.2cqh; height: 1.2cqh; - border-radius: 50%; background: var(--chip-color); - - flex: 0 0 auto; } .magnitude-selector__label { min-width: 0; - + white-space: nowrap; overflow: hidden; text-overflow: ellipsis; - white-space: nowrap; } + +/* ---------- Phone (shared) ---------- + Landscape: tabs (Faders / Input curve / Output curve), one view at a time. + Portrait: faders only + a hint to rotate for the graphs. */ + +@media (max-width: 768px), (max-height: 500px) and (pointer: coarse) { + .gain-page { + flex: 1 1 0; + min-height: 0; + width: 100%; + + display: flex; + flex-direction: column; + background: var(--bg-panel); + } + + /* ----- Tabs ----- */ + + .gain-tabs { + flex: 0 0 auto; + display: flex; + gap: var(--space-1); + padding: var(--space-1) var(--space-2); + border-bottom: var(--border-width) solid var(--border-hairline); + } + + .gain-page .gain-tabs__tab { + flex: 1 1 0; + min-width: 0; + min-height: 0; + height: 34px; + padding: 0 var(--space-2); + + font-family: var(--font-ui); + font-size: var(--font-xs); + font-weight: var(--font-weight-semibold); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + + background: var(--bg-void); + color: var(--text-muted); + border: var(--border-width) solid var(--border-hairline); + border-radius: var(--radius-sm); + cursor: pointer; + } + + .gain-page .gain-tabs__tab[aria-selected='true'] { + background: var(--bg-raised); + color: var(--text-primary); + border-color: var(--accent-brand); + } + + /* ----- Which view is visible ----- */ + + .gain-page[data-view='faders'] .gain-linear-graph-section, + .gain-page:not([data-view='faders']) .gain-section, + .gain-page[data-view='input'] .gain-graph-panel[data-panel='output'], + .gain-page[data-view='output'] .gain-graph-panel[data-panel='input'] { + display: none; + } + + /* ----- Curve views: graph fills everything ----- */ + + .gain-linear-graph-section { + flex: 1 1 0; + min-height: 0; + flex-direction: column; + gap: 0; + padding: var(--space-1); + } + + .gain-graph-panel { + flex: 1 1 0; + height: auto; + } + + /* Compact header: chips scroll on the left, "Show stages" on the right */ + .gain-graph-title-row { + flex-direction: row; + align-items: center; + gap: var(--space-2); + padding: var(--space-1) var(--space-2); + } + + .gain-graph-title-line { + order: 2; + flex: 0 0 auto; + width: auto; + } + + .gain-graph-title-line .gain-graph-title { + display: none; /* the tab already says which graph this is */ + } + + .gain-stages-toggle { + min-height: 0; + height: 32px; + padding: 0 var(--space-3); + font-size: var(--font-xs); + } + + .magnitude-selector { + order: 1; + flex: 1 1 auto; + width: auto; + gap: var(--space-1); + + overflow-x: auto; + overflow-y: hidden; + scrollbar-width: none; + -webkit-overflow-scrolling: touch; + } + + .magnitude-selector::-webkit-scrollbar { + display: none; + } + + .magnitude-selector__chip { + flex: 0 0 auto; + min-height: 0; + height: 32px; + padding: 0 var(--space-3); + gap: var(--space-2); + font-size: var(--font-xs); + } + + .magnitude-selector__swatch { + width: 10px; + height: 10px; + } + + /* ----- Faders view: mixer strips, swipe sideways, snap per group ----- */ + + .gain-section { + position: relative; + z-index: auto; + flex: 1 1 0; + height: auto; + min-height: 0; + + align-items: stretch; + justify-content: flex-start; + border-top: none; + } + + .gain-panels { + display: flex; + width: 100%; + gap: var(--space-3); + padding: var(--space-2); + box-sizing: border-box; + + overflow-x: auto; + overflow-y: hidden; + scroll-snap-type: x proximity; + overscroll-behavior-x: contain; + -webkit-overflow-scrolling: touch; + } + + .gain-section .channel-group { + flex: 0 0 auto; + margin: 0; + padding: 30px var(--space-2) var(--space-2); + scroll-snap-align: start; + } + + .gain-section .channel-group__label { + top: 7px; + font-size: var(--font-sm); + } + + .gain-section .channel-group__items { + height: auto; + align-self: stretch; + } + + .gain-panel { + flex: 0 0 auto; + width: clamp(64px, 10vw, 80px); + height: auto; /* stretches to the row */ + aspect-ratio: auto; + gap: var(--space-2); + padding-bottom: var(--space-2); + } + + .gain-panel__title { + padding-block: var(--space-2); + font-size: var(--font-xs); + } + + /* The fader (element right after the title) takes all remaining height. + pan-x: vertical drags move the fader, horizontal swipes still scroll the strip. */ + .gain-panel__title + * { + flex: 1 1 0; + min-height: 0; + width: 100%; + } + + /* Applied to the thumb/track too: a swipe that starts on them must scroll the + strip, not drag the fader. */ + .gain-panel__title + *, + .gain-panel__title + * * { + touch-action: pan-x !important; + } + + /* Centered when everything fits, left-aligned and scrollable when it doesn't + (auto margins collapse to 0 on overflow, unlike justify-content: center) */ + .gain-panels > .channel-group:first-child { + margin-left: auto; + } + + .gain-panels > .channel-group:last-child { + margin-right: auto; + } + + .gain-panel__btns { + display: flex; + flex-direction: column; + gap: var(--space-2); + width: calc(100% - var(--space-3)); + } + + .gain-panel .gain-panel__btns .gain-panel__btn { + flex: 1 1 auto; + width: 100%; + min-height: 44px; + padding: 0; + font-size: var(--font-xs); + } +} + +/* ---------- Portrait phone: faders only, 2 rows (Input on top, Output below) ---------- */ + +@media (max-width: 768px) and (orientation: portrait) { + .gain-tabs { + display: none; + } + + .gain-rotate-hint { + flex: 0 0 auto; + display: block; + padding: var(--space-2) var(--space-3); + + font-family: var(--font-ui); + font-size: var(--font-xs); + text-align: center; + color: var(--text-muted); + + border-bottom: var(--border-width) solid var(--border-hairline); + } + + /* Whatever tab was active in landscape, portrait always shows the faders */ + .gain-page[data-view] .gain-linear-graph-section { + display: none; + } + + .gain-page[data-view] .gain-section { + display: flex; + } + + /* Two rows: each group is a row that scrolls sideways on its own */ + .gain-panels { + flex-direction: column; + gap: var(--space-2); + overflow: hidden; + scroll-snap-type: none; + } + + /* Each row is its own size container: everything sized in cqh inside + (fader thumb, track, readout) scales to the row height, like in landscape, + instead of to the whole screen. */ + .gain-section .channel-group { + container-type: size; + flex: 1 1 0; + min-height: 0; + width: 100%; + box-sizing: border-box; + padding: 28px var(--space-2) var(--space-2); + scroll-snap-align: none; + } + + .gain-section .channel-group__label { + top: 6px; + font-size: var(--font-xs); + } + + .gain-section .channel-group__items { + flex: 1 1 auto; + width: 100%; + min-width: 0; + gap: var(--space-1); + + overflow-x: auto; + overflow-y: hidden; + scroll-snap-type: x proximity; + overscroll-behavior-x: contain; + -webkit-overflow-scrolling: touch; + } + + .gain-section .channel-group__items > :first-child { + margin-left: auto; + } + + .gain-section .channel-group__items > :last-child { + margin-right: auto; + } + + /* Same strip as landscape: narrow, compact, buttons stacked */ + .gain-panel { + width: clamp(60px, 17vw, 72px); + gap: var(--space-1); + padding-bottom: var(--space-1); + scroll-snap-align: start; + } + + .gain-panel__title { + padding-block: var(--space-1); + font-size: 11px; + } + + .gain-panel__btns { + gap: var(--space-1); + } + + .gain-panel .gain-panel__btns .gain-panel__btn { + min-height: 36px; + font-size: 11px; + } +} + +/* ---------- Landscape phone: thinner strips, buttons stacked ---------- */ + +@media (max-height: 500px) and (pointer: coarse) { + .gain-panels { + padding: var(--space-1) var(--space-2); + } + + .gain-section .channel-group { + padding-top: 24px; + } + + .gain-section .channel-group__label { + top: 4px; + font-size: var(--font-xs); + } + + .gain-panel { + width: clamp(56px, 7.5vw, 76px); + gap: var(--space-1); + padding-bottom: var(--space-1); + } + + .gain-panel__title { + padding-block: var(--space-1); + font-size: 11px; + } + + .gain-panel__btns { + gap: var(--space-1); + } + + .gain-panel .gain-panels .gain-panel__btn, + .gain-panel .gain-panel__btns .gain-panel__btn { + min-height: 36px; + font-size: 11px; + } +} \ No newline at end of file diff --git a/src/features/dsp408/components/GainSection/GainSection.tsx b/src/features/dsp408/components/GainSection/GainSection.tsx index 858888e..7997160 100644 --- a/src/features/dsp408/components/GainSection/GainSection.tsx +++ b/src/features/dsp408/components/GainSection/GainSection.tsx @@ -19,6 +19,34 @@ import { getPeqCurvePoints } from '../../utils/graph/peq'; import { getCrossoverCurvePoints } from '../../utils/graph/crossover'; import { ChannelCurves, formatY, ResponseGraph } from './GainGraph'; +// ---- Helpers ------------------------------------------------------------ + +type GainView = 'faders' | 'input' | 'output'; + +const GAIN_VIEWS: { id: GainView; label: string }[] = [ + { id: 'faders', label: 'Faders' }, + { id: 'input', label: 'Input curve' }, + { id: 'output', label: 'Output curve' }, +]; + +function toggleInSet(set: Set, value: T): Set { + const next = new Set(set); + if (next.has(value)) next.delete(value); + else next.add(value); + return next; +} + +function withLiveValue( + prev: Partial>, + key: K, + value: number | null +): Partial> { + const next = { ...prev }; + if (value === null) delete next[key]; + else next[key] = value; + return next; +} + // ---- Curve construction ----------------------------------------------- function getGainCurvePoints(freqs: number[], gainDb: number): CurvePoint[] { @@ -131,15 +159,9 @@ function GainPanel({ await setInverse(channel, !inverted); }; - const handleLiveValue = (value: number) => { - onLiveGain(value); - }; - const commitGain = async (value: number) => { const success = await setGain(channel, value); - if (success) { - onLiveGain(null); - } + if (success) onLiveGain(null); return success; }; @@ -154,42 +176,29 @@ function GainPanel({ unit=" dB" value={gain} formatValue={(v, d) => (v > 0 ? `+${v.toFixed(d)}` : v.toFixed(d))} - onInput={handleLiveValue} + onInput={onLiveGain} onChange={commitGain} /> - - +
+ + + +
); } @@ -241,7 +250,11 @@ function GainSection({ setInverse: (channel: Channel, inverted: boolean) => Promise; }) { const [selectedInputs, setSelectedInputs] = useState>(new Set(INPUT_ORDER)); - const [selectedOutputs, setSelectedOutputs] = useState>(new Set(OUTPUT_ORDER)); + const [selectedOutputs, setSelectedOutputs] = useState>( + new Set(OUTPUT_ORDER) + ); + + const [view, setView] = useState('faders'); const [showInputStages, setShowInputStages] = useState(false); const [showOutputStages, setShowOutputStages] = useState(false); @@ -251,70 +264,54 @@ function GainSection({ {} ); - const setLiveInputGain = (channel: InputChannel, value: number | null) => { - setLiveInputGains((prev) => { - if (value === null) { - const next = { ...prev }; - delete next[channel]; - return next; - } - return { ...prev, [channel]: value }; - }); - }; + const setLiveInputGain = (channel: InputChannel, value: number | null) => + setLiveInputGains((prev) => withLiveValue(prev, channel, value)); - const setLiveOutputGain = (channel: OutputChannel, value: number | null) => { - setLiveOutputGains((prev) => { - if (value === null) { - const next = { ...prev }; - delete next[channel]; - return next; - } - return { ...prev, [channel]: value }; - }); - }; + const setLiveOutputGain = (channel: OutputChannel, value: number | null) => + setLiveOutputGains((prev) => withLiveValue(prev, channel, value)); - const inputLabels: Record = INPUT_ORDER.reduce( - (acc, channel) => ({ - ...acc, - [channel]: dsp.state.current_config.input_states[channel].name, - }), - {} as Record - ); + const inputStates = dsp.state.current_config.input_states; + const outputStates = dsp.state.current_config.output_states; - const outputLabels: Record = OUTPUT_ORDER.reduce( - (acc, channel) => ({ - ...acc, - [channel]: dsp.state.current_config.output_states[channel].name, - }), - {} as Record - ); + const inputLabels = Object.fromEntries( + INPUT_ORDER.map((channel) => [channel, inputStates[channel].name]) + ) as Record; - const toggleInput = (channel: InputChannel) => { - setSelectedInputs((prev) => { - const next = new Set(prev); - next.has(channel) ? next.delete(channel) : next.add(channel); - return next; - }); - }; - - const toggleOutput = (channel: OutputChannel) => { - setSelectedOutputs((prev) => { - const next = new Set(prev); - next.has(channel) ? next.delete(channel) : next.add(channel); - return next; - }); - }; + const outputLabels = Object.fromEntries( + OUTPUT_ORDER.map((channel) => [channel, outputStates[channel].name]) + ) as Record; return ( - <> +
+ {/* Phone only (hidden on desktop by CSS): one view at a time */} +
+ {GAIN_VIEWS.map((v) => ( + + ))} +
+ + {/* Portrait phone only (CSS): graphs need the width of landscape */} +
+ Rotate your phone to landscape to see the response graphs. +
+
-
+
Input Response
-
+
Output Response
- setSelectedOutputs((prev) => toggleInSet(prev, c))} />
- +
); } -export default GainSection; +export default GainSection; \ No newline at end of file