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 @@ -48,6 +48,7 @@ OpenStand is an **early but usable** practice tool. What works today:
- **Drums** pick grooves by position in the form: a set-up on the first bar, two-bar figures in the middle, a fill on the last bar
- Every chorus is played a little differently
- **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.
- **Plain chord font option for easier reading on small screens.**
- **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.
- **Switch a tune between major and minor (same tonic) with one click.**
Expand Down
30 changes: 28 additions & 2 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 { CHORD_FONT_KEY, loadChordFont, type ChordFont } from './music/chordText'
import { isInstrumentId, viewOffset, type InstrumentId } from './music/instrument'
import { EXAMPLES, type Tune } from './music/songs'
import { getStyle, STYLES, type StyleDefinition } from './styles'
Expand Down Expand Up @@ -209,6 +210,7 @@ export default function App() {
const [editBar, setEditBar] = useState(0)
const [irealState, setIrealState] = useState<'idle' | 'copied' | 'failed'>('idle')
const [mode, setMode] = useState<ModeOption>('original')
const [chordFont, setChordFont] = useState<ChordFont>(loadChordFont)

const tune = tunes.find((t) => t.id === songId) ?? tunes[0] ?? EXAMPLES[0]
const baseChart = draft?.chart ?? tune.chart
Expand Down Expand Up @@ -300,6 +302,19 @@ export default function App() {
}
}, [instrument])

useEffect(() => {
try {
localStorage.setItem(CHORD_FONT_KEY, chordFont)
} catch {
// Storage may be disabled in private browsing
}
if (chordFont === 'Plain') {
document.documentElement.dataset.chordFont = 'plain'
} else {
delete document.documentElement.dataset.chordFont
}
}, [chordFont])

// Tempo changes only the playback rate; the arrangement is not regenerated
useEffect(() => {
playerRef.current?.setRate(liveBpm / BASE_BPM)
Expand Down Expand Up @@ -649,15 +664,15 @@ export default function App() {
})()

return (
<div className="app">
<div className="app" data-chord-font={chordFont === 'Plain' ? 'plain' : undefined}>
<header className="topbar">
<a className="wordmark" href="/" aria-label="OpenStand home">
<svg viewBox="0 0 32 32" aria-hidden="true">
<path d="M6 4h20l-2 11H8z" />
<path d="M5 15h22" />
<path d="M16 15v12M16 27l-6 3M16 27l6 3" />
</svg>
OpenStand
<span className="wordmark-name">OpenStand</span>
</a>
<span className="topbar-tag">Practice with a band in your browser</span>
<span className="topbar-spacer" />
Expand Down Expand Up @@ -694,6 +709,16 @@ export default function App() {
</Popover>
</>
)}
<button
type="button"
className="topbar-button topbar-chord-font"
aria-pressed={chordFont === 'Plain'}
aria-label="Plain chords"
title="Plain chords"
onClick={() => setChordFont((f) => (f === 'Plain' ? 'Handwritten' : 'Plain'))}
>
Aa
</button>
<button className="tunes-toggle" aria-expanded={libraryOpen} onClick={() => setLibraryOpen(!libraryOpen)}>
Tunes
</button>
Expand Down Expand Up @@ -732,6 +757,7 @@ export default function App() {
barBeats={position?.barBeats ?? 4}
range={picking && picking !== 'first' ? [picking.from, picking.from] : draft ? null : practice.loop}
selectedBar={draft ? editBar : null}
plain={chordFont === 'Plain'}
onBarClick={draft ? setEditBar : picking ? pickBar : undefined}
onChordClick={
!draft && !picking
Expand Down
109 changes: 107 additions & 2 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ button:disabled {
border-color: var(--ink-2);
}

.topbar-chord-font {
font-family: var(--sans);
font-weight: 600;
letter-spacing: -0.02em;
padding: 0 9px;
}

.topbar-link svg {
width: 15px;
height: 15px;
Expand Down Expand Up @@ -618,6 +625,26 @@ button:disabled {
color: var(--danger);
}

/* Plain chord font (sans-serif) */
[data-chord-font='plain'] .chord,
[data-chord-font='plain'] .chord-accidental,
[data-chord-font='plain'] .chord-quality,
[data-chord-font='plain'] .chord-ext,
[data-chord-font='plain'] .chord-bass {
font-family: var(--sans);
font-weight: 600;
}

[data-chord-font='plain'] .chord-accidental {
font-size: 0.65em;
translate: 0 -0.4em;
}

[data-chord-font='plain'] .chord-ext {
font-size: 0.55em;
translate: 0 -0.6em;
}

/* ---------- Transport ---------- */

.transport {
Expand Down Expand Up @@ -703,6 +730,13 @@ button:disabled {
flex: 1;
}

/* Practice, Chords and Mixer stay together on one row */
.transport-band {
display: flex;
align-items: center;
gap: 20px;
}

.control {
position: relative;
display: grid;
Expand Down Expand Up @@ -1371,12 +1405,45 @@ input.fader::-moz-range-thumb {

/* ---------- Narrow screens ---------- */

@media (max-width: 1100px) {
.topbar-tag,
/* Key, Mode, Reads in, Tempo and the band buttons need about 1430px; below that, save room */
@media (max-width: 1500px) {
.control-tempo input[type='range'] {
display: none;
}

.transport,
.controls,
.transport-band {
gap: 12px;
}

.transport-main {
min-width: 0;
}
}

@media (max-width: 1240px) {
:root {
--transport-h: auto;
}

.transport {
flex-wrap: wrap;
row-gap: 8px;
padding-block: 10px;
}

/* On the second row the band buttons sit at the right, so their panels open away from Play */
.transport-band {
margin-left: auto;
}
}

@media (max-width: 1100px) {
.topbar-tag {
display: none;
}

.transport,
.controls {
gap: 12px;
Expand Down Expand Up @@ -1422,6 +1489,10 @@ input.fader::-moz-range-thumb {
padding: 0 9px;
}

.topbar-chord-font {
padding: 0 7px;
}

.wordmark {
margin-right: auto;
}
Expand Down Expand Up @@ -1629,6 +1700,31 @@ input.fader::-moz-range-thumb {
}
}

@media (max-width: 500px) {
.topbar {
gap: 4px;
padding: 0 8px;
}

.topbar-link,
.topbar-button,
.tunes-toggle,
.share .band-toggle {
padding: 0 7px;
}

.topbar-chord-font {
padding: 0 5px;
}
}

/* On the narrowest phones the logo mark alone is enough */
@media (max-width: 360px) {
.wordmark-name {
display: none;
}
}

@media (prefers-reduced-motion: reduce) {
* {
transition: none !important;
Expand Down Expand Up @@ -1717,6 +1813,15 @@ input.fader::-moz-range-thumb {
.bar-highlight {
display: none !important;
}

[data-chord-font='plain'] .chord,
[data-chord-font='plain'] .chord-accidental,
[data-chord-font='plain'] .chord-quality,
[data-chord-font='plain'] .chord-ext,
[data-chord-font='plain'] .chord-bass {
font-family: var(--sans);
font-weight: 600;
}
}

/* ---------- Style lab ---------- */
Expand Down
90 changes: 90 additions & 0 deletions src/music/chordText.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { parseChord, spellRoot, type Chord } from './chords'

export type ChordFont = 'Handwritten' | 'Plain'

export const CHORD_FONT_KEY = 'openstand:chord-font'

export function isChordFont(value: unknown): value is ChordFont {
return value === 'Handwritten' || value === 'Plain'
}

export function loadChordFont(): ChordFont {
try {
if (typeof localStorage === 'undefined') return 'Handwritten'
const saved = localStorage.getItem(CHORD_FONT_KEY)
return isChordFont(saved) ? saved : 'Handwritten'
} catch {
return 'Handwritten'
}
}

export interface ChordParts {
root: string
accidental: string
quality: string
extensions: string
bass: string
}

export function accidentalPlain(a: string): string {
return a === 'b' ? '♭' : a === '#' ? '♯' : ''
}

export function typesetPlain(suffix: string): { quality: string; extensions: string } {
const s = suffix
.replace('ø', 'h')
.replace('Δ', '^')
.replace(/^(min|mi|m)(?!aj)/, '-')
.replace(/^maj7?/, '^7')
.replace(/^dim/, 'o')
.replace(/^aug/, '+')

const match = /^([-^ho+])?(\d+)?(.*)$/.exec(s) ?? ['', '', '', s]
const markerType = match[1] ?? ''
const num = match[2] ?? ''
const rawExt = match[3] ?? ''

let extensions = rawExt
.replace(/\^7?/g, 'Δ7')
.replace(/b/g, '♭')
.replace(/#/g, '♯')

let quality = ''
if (markerType === 'h') {
quality = num ? 'm' + num : 'm7'
extensions = '♭5' + extensions
} else if (markerType === '^') {
quality = 'Δ' + (num || '7')
} else if (markerType === '-') {
quality = 'm' + num
} else if (markerType === 'o') {
quality = '°' + num
} else if (markerType === '+') {
quality = '+' + num
} else {
quality = num
}

return { quality, extensions }
}

export function plainChordParts(chord: Chord, keyPc = 0): ChordParts {
const name = spellRoot(chord.root, keyPc)
const root = name[0] ?? ''
const accidental = accidentalPlain(name[1] ?? '')
const { quality, extensions } = typesetPlain(chord.suffix)
let bass = ''
if (chord.bass !== chord.root) {
const bassName = spellRoot(chord.bass, keyPc)
bass = (bassName[0] ?? '') + accidentalPlain(bassName[1] ?? '')
}
return { root, accidental, quality, extensions, bass }
}

export function plainChordText(chord: Chord | string, keyPc = 0): string {
const c = typeof chord === 'string' ? parseChord(chord) : chord
if (!c) return typeof chord === 'string' ? chord : ''
const parts = plainChordParts(c, keyPc)
const bassPart = parts.bass ? `/${parts.bass}` : ''
return `${parts.root}${parts.accidental}${parts.quality}${parts.extensions}${bassPart}`
}
9 changes: 6 additions & 3 deletions src/ui/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface ChartProps {
barBeats: number
range?: [number, number] | null // looped bars
selectedBar?: number | null // the bar being edited
plain?: boolean
onBarClick?: (index: number) => void
onChordClick?: (chord: Chord) => void
header?: ReactNode // replaces the title block, e.g. with inputs in the editor
Expand Down Expand Up @@ -74,11 +75,12 @@ interface BarProps {
showTime: TimeSignature | null
inRange: boolean
selected: boolean
plain?: boolean
onClick?: (index: number) => void
onChordClick?: (chord: Chord) => void
}

function Bar({ placed, prev, keyPc, active, progress, showTime, inRange, selected, onClick, onChordClick }: BarProps) {
function Bar({ placed, prev, keyPc, active, progress, showTime, inRange, selected, plain, onClick, onChordClick }: BarProps) {
const { bar, chords, column, closesRow, index } = placed
const classes = ['bar']
if (bar.spacer) classes.push('bar-spacer')
Expand Down Expand Up @@ -148,7 +150,7 @@ function Bar({ placed, prev, keyPc, active, progress, showTime, inRange, selecte
{active && <span className="bar-highlight" style={{ transform: `scaleX(${progress})` }} />}
{chords.map(({ chord, symbol }, j) =>
chord ? (
<ChordSymbol key={j} chord={chord} keyPc={keyPc} onSelect={onChordClick} />
<ChordSymbol key={j} chord={chord} keyPc={keyPc} plain={plain} onSelect={onChordClick} />
) : symbol === null ? (
<span key={j} className="chord chord-nc">
N.C.
Expand All @@ -170,7 +172,7 @@ function Bar({ placed, prev, keyPc, active, progress, showTime, inRange, selecte
}

export function Chart(props: ChartProps) {
const { chart, style, transpose, activeMeasure, beatInBar, barBeats, range, selectedBar, onBarClick, onChordClick, header } = props
const { chart, style, transpose, activeMeasure, beatInBar, barBeats, range, selectedBar, plain, onBarClick, onChordClick, header } = props
const keyPc = (chart.key + transpose + 12) % 12
const layout = useMemo(() => rows(chart, transpose), [chart, transpose])
const keyName = prettyKey(noteName(keyPc, keyPrefersFlats(keyPc))) + (chart.minor ? '−' : '')
Expand Down Expand Up @@ -199,6 +201,7 @@ export function Chart(props: ChartProps) {
showTime={placed.index === 0 ? chart.time : (placed.bar.time ?? null)}
inRange={!!range && placed.index >= Math.min(...range) && placed.index <= Math.max(...range)}
selected={selectedBar === placed.index}
plain={plain}
onClick={onBarClick}
onChordClick={onChordClick}
/>
Expand Down
Loading
Loading