From 97ef8a749109e1c6a2416277e907efee7aab5d0b Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Tue, 3 Jun 2025 01:13:11 -0500 Subject: [PATCH] Fix parsing of G#. Tweak large print stylesheet. --- pco_chords.nimble | 2 +- src/pco_chordspkg/cliconstants.nim | 2 +- src/pco_chordspkg/html.nim | 9 ++++--- src/pco_chordspkg/notation.nim | 40 ++++++++++++++++++++++++------ 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/pco_chords.nimble b/pco_chords.nimble index b13a6ea..d5b1ce4 100644 --- a/pco_chords.nimble +++ b/pco_chords.nimble @@ -1,6 +1,6 @@ # Package -version = "0.6.0" +version = "0.6.1" author = "Jonathan Bernard" description = "Chord chart formatter compatible with Planning Center Online" license = "MIT" diff --git a/src/pco_chordspkg/cliconstants.nim b/src/pco_chordspkg/cliconstants.nim index d56d722..5c6564a 100644 --- a/src/pco_chordspkg/cliconstants.nim +++ b/src/pco_chordspkg/cliconstants.nim @@ -1,4 +1,4 @@ -const PCO_CHORDS_VERSION* = "0.6.0" +const PCO_CHORDS_VERSION* = "0.6.1" const USAGE* = """Usage: pco_chords [options] diff --git a/src/pco_chordspkg/html.nim b/src/pco_chordspkg/html.nim index 9062d84..17319da 100644 --- a/src/pco_chordspkg/html.nim +++ b/src/pco_chordspkg/html.nim @@ -112,9 +112,11 @@ const LARGE_PRINT_STYLESHEET* = """ html { font-family: sans-serif; - font-size: 1.5em; + font-size: 1.3em; + font-variant: small-caps; } +.page-contents { line-height: 1.1; } .one-column .page-contents { column-count: 1; } .two-column .page-contents { column-count: 2; } @@ -157,7 +159,7 @@ h3 .section-text { align-items: flex-start; } -.word.space-after { margin-right: 0.5em; } +.word.space-after { margin-right: 0.3em; } .word.no-chord { align-self: flex-end; } .lyric { @@ -165,8 +167,9 @@ h3 .section-text { } .chord { + font-size: 125%; font-style: italic; - font-weight: 500; + font-weight: 700; margin-right: 0.5em; } diff --git a/src/pco_chordspkg/notation.nim b/src/pco_chordspkg/notation.nim index 13d3665..540c399 100644 --- a/src/pco_chordspkg/notation.nim +++ b/src/pco_chordspkg/notation.nim @@ -270,23 +270,49 @@ func ionianPitch*(key: Key, degreeNumber: int): Pitch = cast[Pitch]((ord(key.tonic.toPitch) + MajorIntervals[degreeNumber - 1]) mod 12) -func spellPitch*(key: Key, sd: ScaleDegree): SpelledPitch = +func spellPitch*(k: Key, sd: ScaleDegree): SpelledPitch = ## Given a key and scale degree, spell it correctly in that key. For example, ## the ♭7 in C major is spelled B♭, the ♭7 in key of Db Locrian is spelled ## B𝄫, and the ♭7 in F# major is E. - result.note = key.tonic.note + (sd.number - 1) - let resultingPitch = ord(ionianPitch(key, sd.number)) + ord(sd.alteration) + result.note = k.tonic.note + (sd.number - 1) + let resultingPitch = ord(ionianPitch(k, sd.number)) + ord(sd.alteration) result.alteration = cast[NoteAlteration]( resultingPitch - ord(result.note.toPitch)) + #[ + debugEcho "Spelling " & $sd & " in the key of " & $k & ":\n" & + "\tsd.alteration: " & $ord(sd.alteration) & + "\tkey.tonic.note: " & $k.tonic.note & + "\tsd.number - 1: " & $(sd.number - 1) & + "\tionianPitch: " & $ionianPitch(k, sd.number) & + "\tord(ionianPitch): " & $ord(ionianPitch(k, sd.number)) & + "\talteration: " & $ord(sd.alteration) & + "\tresultingPitch: " & $resultingPitch & + "\tresult.note: " & $(result.note) & + "\tresult.alteration: " & $ord(result.alteration) + ]# -func toScaleDegree*(key: Key, sp: SpelledPitch): ScaleDegree = +func toScaleDegree*(k: Key, sp: SpelledPitch): ScaleDegree = ## Determine the ScaleDegree of a pitch according to how it is spelled and ## the key it is in. For example, Pitch.B will be the ♮2 in the key of A ## major, the ♭2 in the key of A# major, or the #1 in the key of B♭ major. - result.number = sp.note - key.tonic.note + 1 - result.alteration = cast[NoteAlteration]( - ord(sp.toPitch) - ord(ionianPitch(key, result.number))) + result.number = sp.note - k.tonic.note + 1 + var distance = ord(sp.toPitch) - ord(ionianPitch(k, result.number)) + if distance < -2: distance += 12 + elif distance > 2: distance -= 12 + result.alteration = cast[NoteAlteration](distance) + #[ + debugEcho "toScaleDegree: " & $sp & " in the key of " & $k & ":\n" & + "\tsp.note: " & $sp.note & + "\tkey.tonic.note: " & $k.tonic.note & + "\tresult.number: " & $result.number & + "\tsp.toPitch: " & $sp.toPitch & + "\tionianPitch: " & $ionianPitch(k, result.number) & + "\tord(sp.toPitch): " & $ord(sp.toPitch) & + "\tord(ionianPitch): " & $ord(ionianPitch(k, result.number)) & + "\tresult.alteration: " & $ord(result.alteration) + ]# + func transpose*(k: Key, steps: int): Key =