Better support for transposition and Nashville numbers.

- Non-diatonic pitches are supported using Nashville numbers (#5).
- When using Nashville numbers chord variants with non-diatonic roots
  are now recognized (e.g. b7)
- Pitch rendering is now aware of key centers. For example, F# is F#
  rendered as F# when in the key of G but Gb when in the key of Ab.
This commit is contained in:
2024-01-10 08:23:19 -06:00
parent 5b1238f038
commit 8271129b90
4 changed files with 88 additions and 39 deletions

View File

@@ -113,9 +113,9 @@ func scaleDegree(root: ChordChartPitch, p: ChordChartPitch): string =
else: raise newException(Exception, "Impossible")
func format(ctx: FormatContext, chord: ChordChartChord, useNumber = false): string =
if not useNumber and chord.original.isSome: return chord.original.get
##if not useNumber and chord.original.isSome: return chord.original.get
elif useNumber:
if useNumber:
result = "<span class=root>" &
ctx.currentKey.scaleDegree(chord.rootPitch) & "</span>"
@@ -127,11 +127,15 @@ func format(ctx: FormatContext, chord: ChordChartChord, useNumber = false): stri
ctx.currentKey.scaleDegree(chord.bassPitch.get) & "</span>"
else:
result = $chord.rootPitch
if chord.flavor.isSome: result &= chord.flavor.get
if chord.bassPitch.isSome: result &= "/" & $chord.bassPitch.get
#debug "transposed " & $ctx.sourceKey & " -> " & $ctx.currentKey &
# " (distance " & $distance & ")\p\tchord: " & $chord & " to " & result
result = "<span class=root>" &
renderPitchInKey(chord.rootPitch, ctx.currentKey) & "</span>"
if chord.flavor.isSome:
result &= "<span class=flavor>" & chord.flavor.get & "</span>"
if chord.bassPitch.isSome:
result &= "<span class=bass>/" &
renderPitchInKey(chord.bassPitch.get, ctx.currentKey) & "</span>"
proc transpose(ctx: FormatContext, chord: ChordChartChord): ChordChartChord =
result = chord