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.
- **Switch a tune between major and minor (same tonic) with one click.**
- **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.
Expand Down
36 changes: 28 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { Player } from './audio/player'
import { arrange, BASE_BPM, CHANNELS, type Part } from './engine/arrange'
import { warmUpMidi } from './engine/warmup'
Expand Down Expand Up @@ -26,7 +26,8 @@ import { Popover } from './ui/Popover'
import { NO_PRACTICE, type PracticeSettings } from './music/practice'
import { Practice } from './ui/Practice'
import { StyleLab } from './ui/StyleLab'
import { Transport, type Readiness } from './ui/Transport'
import { switchMode } from './music/mode'
import { Transport, type ModeOption, type Readiness } from './ui/Transport'
import { handlePracticeShortcut, type PracticeShortcuts } from './ui/shortcuts'

interface Position {
Expand Down Expand Up @@ -207,9 +208,14 @@ export default function App() {
const [draft, setDraft] = useState<Draft | null>(null)
const [editBar, setEditBar] = useState(0)
const [irealState, setIrealState] = useState<'idle' | 'copied' | 'failed'>('idle')
const [mode, setMode] = useState<ModeOption>('original')

const tune = tunes.find((t) => t.id === songId) ?? tunes[0] ?? EXAMPLES[0]
const chart = draft?.chart ?? tune.chart
const baseChart = draft?.chart ?? tune.chart
const chart = useMemo(
() => (!draft && mode !== 'original' ? switchMode(baseChart, mode) : baseChart),
[baseChart, draft, mode],
)
// The lab's style is rebuilt from the grid each time it is needed
// Saved styles are chosen as "my:<id>"
const styleFor = (id: string, current: LabStyle | null, mine: LabStyle[]): StyleDefinition => {
Expand Down Expand Up @@ -299,12 +305,12 @@ export default function App() {
playerRef.current?.setRate(liveBpm / BASE_BPM)
}, [liveBpm])

const start = async (opts: ArrangeOptions, fromSeconds = 0) => {
const start = async (opts: ArrangeOptions, fromSeconds = 0, chartToUse = chart) => {
const player = playerRef.current
if (!player) return
setNotice(null)
const { loop, keyStep } = opts.practice
const { midi, timeline } = arrange(chart, resolveStyle(opts.styleId), opts.transpose, opts.choruses, { loop, keyStep })
const { midi, timeline } = arrange(chartToUse, resolveStyle(opts.styleId), opts.transpose, opts.choruses, { loop, keyStep })
timelineRef.current = timeline
try {
await player.play(midi, fromSeconds)
Expand Down Expand Up @@ -336,6 +342,16 @@ export default function App() {
if (playing && player) void start(next, loopChanged ? 0 : player.position)
}

const changeMode = (nextMode: ModeOption) => {
setMode(nextMode)
setSelectedChord(null)
const nextChart = !draft && nextMode !== 'original' ? switchMode(baseChart, nextMode) : baseChart
const player = playerRef.current
if (playing && player) {
void start({ styleId, transpose, choruses, practice }, player.position, nextChart)
}
}

const changePractice = (next: PracticeSettings) => {
// Going round the keys needs enough choruses to get back home
const keysNeeded = next.keyStep ? 12 / gcd(next.keyStep, 12) : 0
Expand Down Expand Up @@ -392,6 +408,7 @@ export default function App() {
setSongId(next.id)
setStyleId(labRef.current ? LAB_STYLE : next.chart.style)
setTranspose(0)
setMode('original')
setBpm(next.chart.bpm)
setPractice((p) => ({ ...p, loop: null }))
setPicking(null)
Expand Down Expand Up @@ -660,13 +677,13 @@ export default function App() {
<Popover id="share" className="share" label="Share">
{() => (
<div className="share-panel">
<button className="share-option" onClick={() => void copy(() => shareUrl(chart), setShareState)}>
<button className="share-option" onClick={() => void copy(() => shareUrl(baseChart), setShareState)}>
<span className="share-name">
{shareState === 'copied' ? 'Link copied' : shareState === 'failed' ? 'Copy failed' : 'Copy OpenStand link'}
</span>
<span className="share-desc">Opens this chart in OpenStand. Nothing is uploaded.</span>
</button>
<button className="share-option" onClick={() => void copy(() => irealLink([chart]), setIrealState)}>
<button className="share-option" onClick={() => void copy(() => irealLink([baseChart]), setIrealState)}>
<span className="share-name">
{irealState === 'copied' ? 'Link copied' : irealState === 'failed' ? 'Copy failed' : 'Copy iReal Pro link'}
</span>
Expand Down Expand Up @@ -763,7 +780,7 @@ export default function App() {
setTimeout(() => setLabSaved('idle'), 2200)
}}
saveState={labSaved}
onShare={() => void copy(() => styleShareUrl(lab, chart), setLabShare)}
onShare={() => void copy(() => styleShareUrl(lab, baseChart), setLabShare)}
shareState={labShare}
onDelete={() => {
const id = myStyleId(lab)
Expand Down Expand Up @@ -799,6 +816,9 @@ export default function App() {
}}
keyPc={keyPc}
onKey={(pc) => changeArrangement({ transpose: offsetToKey(chart.key, pc) })}
mode={mode}
originalMinor={tune.chart.minor}
onMode={changeMode}
instrument={instrument}
onInstrument={setInstrument}
bpm={bpm}
Expand Down
166 changes: 166 additions & 0 deletions src/music/mode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// Transformation between parallel major and minor modes around the same tonic.
//
// Each chord is mapped by its interval distance (in semitones) from the tonic key
// and its chord quality. Non-diatonic chords, secondary dominants, and N.C. bars
// remain untouched.

import type { Chart } from './chart'
import { parseChord, spellRoot, type Chord, type Quality } from './chords'

export interface ChordTransformationRule {
/** Semitone distance from tonic (0 = I / i, 2 = ii, etc.) */
interval: number
/** Allowed chord qualities to match */
qualities: Quality[]
/** Root pitch shift in semitones (e.g. -1 to lower iii to bIII) */
rootShift: number
/**
* New chord suffix, or a function returning the new suffix.
* If the function returns null, the chord is left untouched.
*/
suffix: string | ((chord: Chord) => string | null)
/** Human-readable explanation for musicians */
description?: string
}

/**
* Diatonic transformation rules when switching from Major to Minor.
*
* Major scale degrees:
* 0 (I): maj7 -> min7 (-7), maj6 -> min6 (-6), maj -> min (-); dom7 unchanged (blues)
* 2 (ii): min7 -> half-diminished (h7); min triad unchanged
* 4 (iii): min7 -> bIII maj7 (^7), root shifts down 1 semitone
* 5 (IV): maj7 -> min7 (-7), maj6 -> min6 (-6), maj -> min (-); dom7 unchanged
* 7 (V): dom7 -> dom7 add b9 tension (7b9); existing tensions left untouched; maj/maj7 -> dom7 (7)
* 9 (vi): min7 -> bVI maj7 (^7), root shifts down 1 semitone
* 11 (vii): half -> bVII dom7 (7), root shifts down 1 semitone
*/
export const MAJOR_TO_MINOR_RULES: readonly ChordTransformationRule[] = [
// 0 (I): maj7/maj/maj6 -> min7/min/min6; dom7 stays same (blues)
{ interval: 0, qualities: ['maj7'], rootShift: 0, suffix: '-7', description: 'I maj7 -> i min7' },
{ interval: 0, qualities: ['maj6'], rootShift: 0, suffix: '-6', description: 'I maj6 -> i min6' },
{ interval: 0, qualities: ['maj'], rootShift: 0, suffix: '-', description: 'I maj -> i min' },
// 2 (ii): min7 -> half (m7b5); min triad stays min
{ interval: 2, qualities: ['min7'], rootShift: 0, suffix: 'h7', description: 'ii min7 -> ii half-diminished' },
// 4 (iii): min7 -> shift root to 3 (bIII), maj7
{ interval: 4, qualities: ['min7'], rootShift: -1, suffix: '^7', description: 'iii min7 -> bIII maj7' },
// 5 (IV): maj7/maj/maj6 -> min7/min/min6; dom7 stays same
{ interval: 5, qualities: ['maj7'], rootShift: 0, suffix: '-7', description: 'IV maj7 -> iv min7' },
{ interval: 5, qualities: ['maj6'], rootShift: 0, suffix: '-6', description: 'IV maj6 -> iv min6' },
{ interval: 5, qualities: ['maj'], rootShift: 0, suffix: '-', description: 'IV maj -> iv min' },
// 7 (V): dom7 -> dom7 'b9' (keep existing tensions); maj/maj7 -> dom7
{
interval: 7,
qualities: ['dom7'],
rootShift: 0,
suffix: (chord) => (chord.tensions.length > 0 ? chord.suffix : '7b9'),
description: 'V dom7 -> V7b9 (keep existing tensions)',
},
{ interval: 7, qualities: ['maj7', 'maj'], rootShift: 0, suffix: '7', description: 'V maj/maj7 -> V dom7' },
// 9 (vi): min7 -> shift root to 8 (bVI), maj7
{ interval: 9, qualities: ['min7'], rootShift: -1, suffix: '^7', description: 'vi min7 -> bVI maj7' },
// 11 (vii): half -> shift root to 10 (bVII), dom7
{ interval: 11, qualities: ['half'], rootShift: -1, suffix: '7', description: 'vii half -> bVII dom7' },
]

/**
* Diatonic transformation rules when switching from Minor to Major.
*
* Natural/Harmonic minor scale degrees:
* 0 (i): min7 -> maj7 (^7), min6 -> maj6 (6), min -> maj; dom7 unchanged
* 2 (ii): half -> min7 (-7)
* 3 (bIII): maj7 -> iii min7 (-7), root shifts up 1 semitone
* 5 (iv): min7 -> maj7 (^7), min6 -> maj6 (6), min -> maj; dom7 unchanged
* 7 (V): dom7 with b9 -> dom7 (removes b9/b13 tensions)
* 8 (bVI): maj7 -> vi min7 (-7), root shifts up 1 semitone
* 10 (bVII): dom7 -> vii half (h7), root shifts up 1 semitone
*/
export const MINOR_TO_MAJOR_RULES: readonly ChordTransformationRule[] = [
// 0 (i): min7 -> maj7, min6 -> maj6, min -> maj
{ interval: 0, qualities: ['min7'], rootShift: 0, suffix: '^7', description: 'i min7 -> I maj7' },
{ interval: 0, qualities: ['min6'], rootShift: 0, suffix: '6', description: 'i min6 -> I maj6' },
{ interval: 0, qualities: ['min'], rootShift: 0, suffix: '', description: 'i min -> I maj' },
// 2 (ii): half -> min7
{ interval: 2, qualities: ['half'], rootShift: 0, suffix: '-7', description: 'ii half-diminished -> ii min7' },
// 3 (bIII): maj7 -> shift root to 4 (iii), min7
{ interval: 3, qualities: ['maj7'], rootShift: 1, suffix: '-7', description: 'bIII maj7 -> iii min7' },
// 5 (iv): min7 -> maj7, min6 -> maj6, min -> maj
{ interval: 5, qualities: ['min7'], rootShift: 0, suffix: '^7', description: 'iv min7 -> IV maj7' },
{ interval: 5, qualities: ['min6'], rootShift: 0, suffix: '6', description: 'iv min6 -> IV maj6' },
{ interval: 5, qualities: ['min'], rootShift: 0, suffix: '', description: 'iv min -> IV maj' },
// 7 (V): dom7 b9 -> dom7 (remove b9/b13 from tensions)
{
interval: 7,
qualities: ['dom7'],
rootShift: 0,
suffix: (chord) => {
if (chord.tensions.includes('b9') || chord.tensions.includes('b13') || /b(9|13)/.test(chord.suffix)) {
const stripped = chord.suffix.replace(/b9/g, '').replace(/b13/g, '')
return stripped || '7'
}
return chord.suffix
},
description: 'V dom7 b9 -> V dom7 (removes b9/b13)',
},
// 8 (bVI): maj7 -> shift root to 9 (vi), min7
{ interval: 8, qualities: ['maj7'], rootShift: 1, suffix: '-7', description: 'bVI maj7 -> vi min7' },
// 10 (bVII): dom7 -> shift root to 11 (vii), half
{ interval: 10, qualities: ['dom7'], rootShift: 1, suffix: 'h7', description: 'bVII dom7 -> vii half-diminished' },
]

/**
* Transforms a single chord symbol string according to mode switching rules.
* Preserves unparsed symbols, non-matching (non-diatonic) chords, and slash bass notes (shifted by rootShift).
*/
export function transformChordSymbol(
symbol: string | null,
key: number,
target: 'major' | 'minor',
): string | null {
if (symbol === null) return null
const parsed = parseChord(symbol)
if (!parsed) return symbol

const interval = ((parsed.root - key) % 12 + 12) % 12
const rules = target === 'minor' ? MAJOR_TO_MINOR_RULES : MINOR_TO_MAJOR_RULES
const rule = rules.find((r) => r.interval === interval && r.qualities.includes(parsed.quality))
if (!rule) return symbol

const newSuffix = typeof rule.suffix === 'function' ? rule.suffix(parsed) : rule.suffix
if (newSuffix === null) return symbol

const newRoot = (parsed.root + rule.rootShift + 120) % 12
const rootName = spellRoot(newRoot, key)
let result = rootName + newSuffix

if (parsed.bass !== parsed.root) {
const newBass = (parsed.bass + rule.rootShift + 120) % 12
const bassName = spellRoot(newBass, key)
result += `/${bassName}`
}

return result
}

/**
* Switches a chart between parallel major and minor modes around the same tonic key.
* Returns a new chart copy with transformed chord symbols, or the original chart if it is already in the target mode.
*/
export function switchMode(chart: Chart, target: 'major' | 'minor'): Chart {
const isMinor = Boolean(chart.minor)
if ((target === 'minor' && isMinor) || (target === 'major' && !isMinor)) {
return chart
}

return {
...chart,
minor: target === 'minor',
bars: chart.bars.map((bar) => ({
...bar,
chords: bar.chords.map((chord) => ({
...chord,
symbol: chord.symbol ? transformChordSymbol(chord.symbol, chart.key, target) : null,
})),
})),
}
}
17 changes: 17 additions & 0 deletions src/ui/Transport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { STYLES } from '../styles'
const RING = 2 * Math.PI * 27 // circumference of the loading ring

export type Readiness = { kind: 'loading'; progress: number } | { kind: 'ready' } | { kind: 'error'; message: string }
export type ModeOption = 'original' | 'major' | 'minor'

interface TransportProps {
readiness: Readiness
Expand All @@ -18,6 +19,9 @@ interface TransportProps {
onStyle: (id: string) => void
keyPc: number
onKey: (pc: number) => void
mode: ModeOption
originalMinor?: boolean
onMode: (mode: ModeOption) => void
instrument: InstrumentId
onInstrument: (id: InstrumentId) => void
bpm: number
Expand Down Expand Up @@ -92,6 +96,19 @@ export function Transport(props: TransportProps) {
{props.instrument !== 'C' && <span className="control-hint">Band plays in {concertKey}</span>}
</label>

<label className="control">
<span className="label">Mode</span>
<select
className="select"
value={props.mode}
onChange={(e) => props.onMode(e.target.value as ModeOption)}
>
<option value="original">Original</option>
<option value="major">{props.originalMinor ? 'Major' : 'Major (original)'}</option>
<option value="minor">{props.originalMinor ? 'Minor (original)' : 'Minor'}</option>
</select>
</label>

<label className="control">
<span className="label">Reads in</span>
<select
Expand Down
Loading
Loading