Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <kbd>Space</kbd> to play/stop, <kbd>↑</kbd>/<kbd>↓</kbd> for ±5 BPM, <kbd>→</kbd>/<kbd>←</kbd> to transpose by a half step, and <kbd>L</kbd> 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.
Expand Down
33 changes: 27 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -161,6 +163,14 @@ export default function App() {
styleRef.current = styleId
}, [styleId])
const [transpose, setTranspose] = useState(0)
const [instrument, setInstrument] = useState<InstrumentId>(() => {
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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -690,7 +709,7 @@ export default function App() {
<Chart
chart={chart}
style={style}
transpose={draft ? 0 : shownTranspose}
transpose={draft ? 0 : viewTranspose}
activeMeasure={position && position.measure >= 0 ? position.measure : null}
beatInBar={position?.beatInBar ?? 0}
barBeats={position?.barBeats ?? 4}
Expand All @@ -700,7 +719,7 @@ export default function App() {
onChordClick={
!draft && !picking
? (c) => {
setSelectedChord(transposeChord(c, -shownTranspose))
setSelectedChord(transposeChord(c, -viewTranspose))
setChordsOpen(true)
}
: undefined
Expand Down Expand Up @@ -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}
Expand All @@ -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}
/>
Expand Down
37 changes: 32 additions & 5 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -635,7 +635,7 @@ button:disabled {
display: flex;
align-items: center;
gap: 14px;
min-width: 250px;
min-width: 200px;
}

.play {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -798,7 +809,7 @@ input[type='range']::-moz-range-thumb {
}

.control-tempo input[type='range'] {
width: 132px;
width: 96px;
}

.band-toggle {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions src/music/instrument.ts
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 21 additions & 1 deletion src/ui/Transport.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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 (
<section className="transport" aria-label="Playback">
Expand Down Expand Up @@ -76,7 +80,7 @@ export function Transport(props: TransportProps) {
</select>
</label>

<label className="control">
<label className="control control-key">
<span className="label">Key</span>
<select className="select" value={props.keyPc} onChange={(e) => props.onKey(Number(e.target.value))}>
{Array.from({ length: 12 }, (_, pc) => (
Expand All @@ -85,6 +89,22 @@ export function Transport(props: TransportProps) {
</option>
))}
</select>
{props.instrument !== 'C' && <span className="control-hint">Band plays in {concertKey}</span>}
</label>

<label className="control">
<span className="label">Reads in</span>
<select
className="select"
value={props.instrument}
onChange={(e) => props.onInstrument(e.target.value as InstrumentId)}
>
{INSTRUMENTS.map((i) => (
<option key={i.id} value={i.id}>
{i.label}
</option>
))}
</select>
</label>

<div className="control control-tempo">
Expand Down
66 changes: 66 additions & 0 deletions tests/instrument.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { describe, expect, test } from 'vitest'
import { chordLabel, keyPrefersFlats, parseChord, spellRoot, transposeChord } from '../src/music/chords'
import { INSTRUMENTS, isInstrumentId, viewOffset } from '../src/music/instrument'

const writtenSymbol = (symbol: string, id: 'C' | 'Bb' | 'Eb', concertKeyPc = 0) => {
const chord = transposeChord(parseChord(symbol)!, viewOffset(id))
const writtenKeyPc = (concertKeyPc + viewOffset(id) + 12) % 12
return `${spellRoot(chord.root, writtenKeyPc)}${chord.suffix}`
}

describe('transposing instruments', () => {
test('INSTRUMENTS table defines C, Bb (+2) and Eb (+9)', () => {
expect(INSTRUMENTS).toEqual([
{ id: 'C', label: 'C (concert)', offset: 0 },
{ id: 'Bb', label: 'Bb instrument', offset: 2 },
{ id: 'Eb', label: 'Eb instrument', offset: 9 },
])
expect(viewOffset('C')).toBe(0)
expect(viewOffset('Bb')).toBe(2)
expect(viewOffset('Eb')).toBe(9)
expect(viewOffset('unknown')).toBe(0)
expect(isInstrumentId('C')).toBe(true)
expect(isInstrumentId('Bb')).toBe(true)
expect(isInstrumentId('Eb')).toBe(true)
expect(isInstrumentId('F')).toBe(false)
expect(isInstrumentId(null)).toBe(false)
})

test('concert Bb7 reads as C7 on Bb and G7 on Eb', () => {
expect(writtenSymbol('Bb7', 'C', 10)).toBe('Bb7')
expect(writtenSymbol('Bb7', 'Bb', 10)).toBe('C7')
expect(writtenSymbol('Bb7', 'Eb', 10)).toBe('G7')
})

test('concert Dm7 reads as Em7 on Bb and Bm7 on Eb', () => {
expect(writtenSymbol('Dm7', 'C', 0)).toBe('Dm7')
expect(writtenSymbol('Dm7', 'Bb', 0)).toBe('Em7')
expect(writtenSymbol('Dm7', 'Eb', 0)).toBe('Bm7')
})

test('written key determines flat or sharp spelling', () => {
// Concert Eb (3): Bb instrument reads in F (5, flats); Eb instrument reads in C (0)
const fKey = (3 + viewOffset('Bb')) % 12
expect(fKey).toBe(5)
expect(keyPrefersFlats(fKey)).toBe(true)

// Concert F (5): Bb instrument reads in G (7, sharps); Eb instrument reads in D (2, sharps)
const gKey = (5 + viewOffset('Bb')) % 12
const dKey = (5 + viewOffset('Eb')) % 12
expect(gKey).toBe(7)
expect(dKey).toBe(2)
expect(keyPrefersFlats(gKey)).toBe(false)
expect(keyPrefersFlats(dKey)).toBe(false)

// Concert E-7 A7 in key of F becomes F#-7 B7 on Bb, C#-7 F#7 on Eb
expect(writtenSymbol('E-7', 'Bb', 5)).toBe('F#-7')
expect(writtenSymbol('A7', 'Bb', 5)).toBe('B7')
expect(writtenSymbol('E-7', 'Eb', 5)).toBe('C#-7')
expect(writtenSymbol('A7', 'Eb', 5)).toBe('F#7')

// Slash chord bass note also transposes by the instrument offset
const slash = parseChord('Bb7/D')!
expect(chordLabel(transposeChord(slash, viewOffset('Bb')), false)).toBe('C7/E')
expect(chordLabel(transposeChord(slash, viewOffset('Eb')), false)).toBe('G7/B')
})
})
Loading