diff --git a/README.md b/README.md index b671d68..aa974a0 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ OpenStand is an **early but usable** practice tool. What works today: - **A real-looking lead sheet.** Chord symbols in a handwritten jazz hand (Petaluma), rehearsal marks, repeat signs, endings, segno and coda, correct flat/sharp spelling in every key, and the current bar marked with a highlighter stroke as it plays. - **Practice controls:** tempo (40–300 BPM, changes instantly), transpose to any key while playing, number of choruses, and a count-in in the tune's meter (4/4 "1 . 2 . 1 2 3 4", 6/8 two pulses then six eighths). Keyboard shortcuts: Space to play/stop, ↑/↓ for ±5 BPM, →/← to transpose by a half step, and L to clear the loop. Shortcuts are inactive while editing a chart or focusing a form control. - **Practice modes:** loop any bars or a rehearsal section, go round all 12 keys (or step up a half or whole tone each chorus), and speed up a few BPM every chorus. +- **Transposing instruments:** read the chart in Bb or Eb while the band plays in concert pitch. - **Chord and scale helper:** keyboard, guitar diagrams and fitting scales for any chord. - **Style lab:** change a style's drums (a main groove, a variation the band switches to, and a fill for the end of the form), bass line and chord rhythm on a grid (each with an optional second pattern the band switches to) and hear it while the band plays. Save your styles and pick them from the style menu, share one as a link, or send it to the project as a new style. - **Mixer** with per-instrument volume and mute, a master volume and an output level meter. diff --git a/src/App.tsx b/src/App.tsx index e2580b0..4ab722d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -12,6 +12,7 @@ import { loadMyStyles, myStyleId, removeMyStyle, saveMyStyle } from './library/m import type { Chart as ChartData } from './music/chart' import { keyPrefersFlats, noteName, parseChord, transposeChord, type Chord } from './music/chords' import { emptyChart } from './music/edit' +import { isInstrumentId, viewOffset, type InstrumentId } from './music/instrument' import { EXAMPLES, type Tune } from './music/songs' import { getStyle, STYLES, type StyleDefinition } from './styles' import { labFromStyle, styleFromLab, styleSource, labId, STEPS_PER_BEAT, type LabStyle } from './styles/lab' @@ -65,6 +66,7 @@ const LAST_TUNE = 'openstand:last-tune' const LAB_KEY = 'openstand:style-lab' const MASTER_KEY = 'openstand:master-volume' const LATENCY_KEY = 'openstand:latency-offset' +const INSTRUMENT_KEY = 'openstand:instrument' const LAB_STYLE = 'lab' // style id used while the lab is open function loadLab(): LabStyle | null { @@ -161,6 +163,14 @@ export default function App() { styleRef.current = styleId }, [styleId]) const [transpose, setTranspose] = useState(0) + const [instrument, setInstrument] = useState(() => { + try { + const saved = localStorage.getItem(INSTRUMENT_KEY) + return isInstrumentId(saved) ? saved : 'C' + } catch { + return 'C' + } + }) const [bpm, setBpm] = useState(EXAMPLES[0].chart.bpm) const [importOpen, setImportOpen] = useState(false) const [shareState, setShareState] = useState<'idle' | 'copied' | 'failed'>('idle') @@ -214,11 +224,12 @@ export default function App() { // During practice the chorus decides the key on the stand and the tempo const chorus = position ? Math.min(position.chorus, choruses - 1) : 0 const shownTranspose = playing ? chorusTranspose(transpose, practice.keyStep, chorus) : transpose - const shownKeyPc = (chart.key + shownTranspose + 12) % 12 + const viewTranspose = shownTranspose + viewOffset(instrument) + const shownKeyPc = (chart.key + viewTranspose + 12) % 12 const liveBpm = clampBpm(bpm + practice.ramp * (playing ? chorus : 0)) const shownChord = selectedChord - ? transposeChord(selectedChord, shownTranspose) - : (playing ? playingChord(chart, position, shownTranspose) : null) ?? firstChord(chart, shownTranspose) + ? transposeChord(selectedChord, viewTranspose) + : (playing ? playingChord(chart, position, viewTranspose) : null) ?? firstChord(chart, viewTranspose) useEffect(() => { // The effect may run twice (StrictMode); a discarded player must not update the UI @@ -275,6 +286,14 @@ export default function App() { playerRef.current?.setLatencyOffset(latencyOffset) }, [latencyOffset, readiness.kind]) + useEffect(() => { + try { + localStorage.setItem(INSTRUMENT_KEY, instrument) + } catch { + // Storage may be disabled in private browsing + } + }, [instrument]) + // Tempo changes only the playback rate; the arrangement is not regenerated useEffect(() => { playerRef.current?.setRate(liveBpm / BASE_BPM) @@ -690,7 +709,7 @@ export default function App() { = 0 ? position.measure : null} beatInBar={position?.beatInBar ?? 0} barBeats={position?.barBeats ?? 4} @@ -700,7 +719,7 @@ export default function App() { onChordClick={ !draft && !picking ? (c) => { - setSelectedChord(transposeChord(c, -shownTranspose)) + setSelectedChord(transposeChord(c, -viewTranspose)) setChordsOpen(true) } : undefined @@ -780,6 +799,8 @@ export default function App() { }} keyPc={keyPc} onKey={(pc) => changeArrangement({ transpose: offsetToKey(chart.key, pc) })} + instrument={instrument} + onInstrument={setInstrument} bpm={bpm} bpmRange={BPM_RANGE} onBpm={setBpm} @@ -792,7 +813,7 @@ export default function App() { chord={shownChord} keyPc={shownKeyPc} following={selectedChord === null} - onFollowChange={(follow) => setSelectedChord(follow ? null : transposeChord(shownChord, -shownTranspose))} + onFollowChange={(follow) => setSelectedChord(follow ? null : transposeChord(shownChord, -viewTranspose))} open={chordsOpen} onOpenChange={setChordsOpen} /> diff --git a/src/index.css b/src/index.css index ca1add8..66aab9a 100644 --- a/src/index.css +++ b/src/index.css @@ -624,7 +624,7 @@ button:disabled { position: relative; display: flex; align-items: center; - gap: 28px; + gap: 20px; height: var(--transport-h); padding: 0 20px; border-top: 1px solid var(--line); @@ -635,7 +635,7 @@ button:disabled { display: flex; align-items: center; gap: 14px; - min-width: 250px; + min-width: 200px; } .play { @@ -699,15 +699,26 @@ button:disabled { .controls { display: flex; align-items: center; - gap: 24px; + gap: 18px; flex: 1; } .control { + position: relative; display: grid; gap: 7px; } +.control-hint { + position: absolute; + top: calc(100% + 2px); + left: 0; + font-size: 11px; + line-height: 1; + color: var(--muted); + white-space: nowrap; +} + .select { appearance: none; height: 32px; @@ -798,7 +809,7 @@ input[type='range']::-moz-range-thumb { } .control-tempo input[type='range'] { - width: 132px; + width: 96px; } .band-toggle { @@ -1361,10 +1372,20 @@ input.fader::-moz-range-thumb { /* ---------- Narrow screens ---------- */ @media (max-width: 1100px) { - .topbar-tag { + .topbar-tag, + .control-tempo input[type='range'] { display: none; } + .transport, + .controls { + gap: 12px; + } + + .transport-main { + min-width: 0; + } + .stage { padding: 24px; } @@ -1535,9 +1556,15 @@ input.fader::-moz-range-thumb { order: 3; flex-basis: 100%; flex-wrap: wrap; + align-items: start; gap: 10px 16px; } + .control-hint { + position: static; + margin-top: -2px; + } + .control-tempo input[type='range'] { display: none; } diff --git a/src/music/instrument.ts b/src/music/instrument.ts new file mode 100644 index 0000000..908a31c --- /dev/null +++ b/src/music/instrument.ts @@ -0,0 +1,24 @@ +// Transposing instruments: written pitch is offset above concert pitch so Bb and Eb +// players can read in their written key while the band plays in concert pitch. + +export type InstrumentId = 'C' | 'Bb' | 'Eb' + +export interface Instrument { + id: InstrumentId + label: string + offset: number // semitones added to concert pitch to get written pitch +} + +export const INSTRUMENTS: readonly Instrument[] = [ + { id: 'C', label: 'C (concert)', offset: 0 }, + { id: 'Bb', label: 'Bb instrument', offset: 2 }, + { id: 'Eb', label: 'Eb instrument', offset: 9 }, +] + +export function isInstrumentId(value: string | null | undefined): value is InstrumentId { + return INSTRUMENTS.some((i) => i.id === value) +} + +export function viewOffset(id: InstrumentId | string): number { + return INSTRUMENTS.find((i) => i.id === id)?.offset ?? 0 +} diff --git a/src/ui/Transport.tsx b/src/ui/Transport.tsx index b65528f..3c10f16 100644 --- a/src/ui/Transport.tsx +++ b/src/ui/Transport.tsx @@ -1,5 +1,6 @@ import type { ReactNode } from 'react' import { keyPrefersFlats, noteName } from '../music/chords' +import { INSTRUMENTS, type InstrumentId } from '../music/instrument' import { STYLES } from '../styles' const RING = 2 * Math.PI * 27 // circumference of the loading ring @@ -17,6 +18,8 @@ interface TransportProps { onStyle: (id: string) => void keyPc: number onKey: (pc: number) => void + instrument: InstrumentId + onInstrument: (id: InstrumentId) => void bpm: number bpmRange: [number, number] onBpm: (bpm: number) => void @@ -30,6 +33,7 @@ export function Transport(props: TransportProps) { const { readiness, playing, bpm, bpmRange, choruses } = props const loading = readiness.kind === 'loading' const clampBpm = (v: number) => Math.max(bpmRange[0], Math.min(bpmRange[1], v)) + const concertKey = noteName(props.keyPc, keyPrefersFlats(props.keyPc)) return (
@@ -76,7 +80,7 @@ export function Transport(props: TransportProps) { -