Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
73bdb97881 | |||
a57aed0715 | |||
2712f9ff52 | |||
8271129b90 |
@ -1,6 +1,6 @@
|
||||
# Package
|
||||
|
||||
version = "0.5.0"
|
||||
version = "0.5.5"
|
||||
author = "Jonathan Bernard"
|
||||
description = "Chord chart formatter compatible with Planning Center Online"
|
||||
license = "MIT"
|
||||
@ -12,3 +12,9 @@ bin = @["pco_chords"]
|
||||
# Dependencies
|
||||
|
||||
requires "nim >= 1.6.6", "docopt", "zero_functional"
|
||||
|
||||
# Dependencies from git.jdbernard.com/jdb/nim-package
|
||||
requires "update_nim_package_version"
|
||||
|
||||
task updateVersion, "Update the version of this tool.":
|
||||
exec "update_nim_package_version pco_chords 'src/pco_chordspkg/cliconstants.nim'"
|
||||
|
@ -38,7 +38,12 @@ when isMainModule:
|
||||
if args["--transpose"]: parseInt($args["--transpose"])
|
||||
else: 0
|
||||
|
||||
let outputHtml = ast.toHtml(transpose, args["--number-chart"])
|
||||
let outputHtml =
|
||||
if args["--large-print"]:
|
||||
ast.toHtml(transpose, args["--number-chart"],
|
||||
stylesheets = @[LARGE_PRINT_STYLESHEET])
|
||||
else:
|
||||
ast.toHtml(transpose, args["--number-chart"])
|
||||
|
||||
if args["--output"]: writeFile($args["--output"], outputHtml)
|
||||
else: stdout.write(outputHtml)
|
||||
|
@ -23,7 +23,7 @@ type
|
||||
ccnkRedefineKey,
|
||||
ccnkNone
|
||||
|
||||
ChordChartPitch* = enum Af, A, Bf, B, C, Df, D, Ef, E, F, Fs, G
|
||||
ChordChartPitch* = enum Af, A, Bf, B, C, Df, D, Ef, E, F, Gf, G
|
||||
|
||||
ChordChartChord* = object
|
||||
original*: Option[string]
|
||||
@ -78,19 +78,59 @@ iterator pairs*(ccmd: ChordChartMetadata): tuple[key, value: string] =
|
||||
func kind*(ccn: ChordChartNode): ChordChartNodeKind = ccn.kind
|
||||
|
||||
func `$`*(pitch: ChordChartPitch): string =
|
||||
case pitch
|
||||
of Af: "Ab"
|
||||
of A: "A"
|
||||
of Bf: "Bb"
|
||||
of B: "B"
|
||||
of C: "C"
|
||||
of Df: "Db"
|
||||
of D: "D"
|
||||
of Ef: "Eb"
|
||||
of E: "E"
|
||||
of F: "F"
|
||||
of Fs: "F#"
|
||||
of G: "G"
|
||||
["A♭", "A", "B♭", "B", "C", "D♭", "D", "E♭", "E", "F", "G♭", "G"][ord(pitch)]
|
||||
|
||||
func renderPitchInKey*(
|
||||
pitch: ChordChartPitch,
|
||||
key: ChordChartPitch,
|
||||
useSharps: Option[bool] = none[bool]()): string =
|
||||
|
||||
var scaleNames: array[(ord(high(ChordChartPitch)) + 1), string]
|
||||
if useSharps.isNone:
|
||||
scaleNames = case key
|
||||
of A, B, D, E, G:
|
||||
["G#", "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G"]
|
||||
of Af, Bf, C, Df, Ef, F:
|
||||
["A♭", "A", "B♭", "B", "C", "D♭", "D", "E♭", "E", "F", "G♭", "G"]
|
||||
of Gf:
|
||||
["A♭", "A", "B♭", "C♭", "C", "D♭", "D", "E♭", "E", "F", "G♭", "G"]
|
||||
|
||||
elif useSharps.isSome and useSharps.get:
|
||||
scaleNames = case key
|
||||
of A, B, C, D, E, G:
|
||||
["G#", "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G"]
|
||||
of Af:
|
||||
["G#", "A", "A#", "B", "B#", "C#", "D", "D#", "E", "E#", "F#", "F𝄪"]
|
||||
of Bf:
|
||||
["G#", "G𝄪", "A#", "B", "B#", "C#", "C𝄪", "D#", "E", "E#", "F#", "F𝄪"]
|
||||
of Df:
|
||||
["G#", "A", "A#", "B", "B#", "C#", "D", "D#", "E", "E#", "F#", "G"]
|
||||
of Ef:
|
||||
["G#", "A", "A#", "B", "B#", "C#", "C𝄪", "D#", "E", "E#", "F#", "F𝄪"]
|
||||
of Gf:
|
||||
["G#", "A", "A#", "B", "C", "C#", "D", "D#", "E", "E#", "F#", "G"]
|
||||
of F:
|
||||
["G#", "G𝄪", "A#", "B", "B#", "C#", "C𝄪", "D#", "D𝄪", "E#", "F#", "F𝄪"]
|
||||
|
||||
else: # useSharps.isSome and not useSharps.get
|
||||
scaleNames = case key
|
||||
of C, Af, Bf, Df, Ef, F:
|
||||
["A♭", "A", "B♭", "B", "C", "D♭", "D", "E♭", "E", "F", "G♭", "G"]
|
||||
of A:
|
||||
["A♭", "B𝄫", "B♭", "C♭", "C", "D♭", "E𝄫", "E♭", "F♭", "F", "G♭", "G"]
|
||||
of B:
|
||||
["A♭", "A", "B♭", "C♭", "C", "D♭", "D", "E♭", "F♭", "F", "G♭", "G"]
|
||||
of D:
|
||||
["A♭", "B𝄫", "B♭", "C♭", "C", "D♭", "E𝄫", "E♭", "F♭", "F", "G♭", "A𝄫"]
|
||||
of E:
|
||||
["A♭", "B𝄫", "B♭", "C♭", "C", "D♭", "D", "E♭", "F♭", "F", "G♭", "G"]
|
||||
of G:
|
||||
["A♭", "B𝄫", "B♭", "C♭", "D𝄫", "D♭", "E𝄫", "E♭", "F♭", "F", "G♭", "A𝄫"]
|
||||
of Gf:
|
||||
["A♭", "A", "B♭", "C♭", "C", "D♭", "D", "E♭", "E", "F", "G♭", "G"]
|
||||
|
||||
|
||||
return scaleNames[ord(pitch)]
|
||||
|
||||
func `+`*(pitch: ChordChartPitch, steps: int): ChordChartPitch =
|
||||
cast[ChordChartPitch]((ord(pitch) + steps) mod 12)
|
||||
@ -193,29 +233,34 @@ proc parsePitch*(ctx: ParserContext, keyValue: string): ChordChartPitch =
|
||||
of "gs", "gis", "g#", "ab", "a♭", "af", "aes": return ChordChartPitch.Af
|
||||
of "g𝄪", "a", "a♮", "b𝄫": return ChordChartPitch.A
|
||||
of "as", "ais", "a#", "bf", "bb", "b♭", "bes", "c𝄫": return ChordChartPitch.Bf
|
||||
of "a𝄪", "b", "cb", "ces", "cf": return ChordChartPitch.B
|
||||
of "a𝄪", "b", "c♭", "cb", "ces", "cf": return ChordChartPitch.B
|
||||
of "bs", "bis", "b#", "c", "d𝄫": return ChordChartPitch.C
|
||||
of "b𝄪", "cs", "cis", "c#", "df", "db", "des": return ChordChartPitch.Df
|
||||
of "b𝄪", "cs", "cis", "c#", "d♭", "df", "db", "des": return ChordChartPitch.Df
|
||||
of "c𝄪", "d", "e𝄫": return ChordChartPitch.D
|
||||
of "ds", "dis", "d#", "ef", "eb", "ees", "f𝄫": return ChordChartPitch.Ef
|
||||
of "d𝄪", "e", "fes", "ff": return ChordChartPitch.E
|
||||
of "ds", "dis", "d#", "ef", "e♭", "eb", "ees", "f𝄫": return ChordChartPitch.Ef
|
||||
of "d𝄪", "e", "f♭", "fes", "ff": return ChordChartPitch.E
|
||||
of "es", "eis", "e#", "f", "g𝄫": return ChordChartPitch.F
|
||||
of "e𝄪", "fs", "fis", "f#", "gf", "gb", "ges": return ChordChartPitch.Fs
|
||||
of "e𝄪", "fs", "fis", "f#", "g♭", "gf", "gb", "ges": return ChordChartPitch.Gf
|
||||
of "f𝄪", "g", "a𝄫": return ChordChartPitch.G
|
||||
of "1": return ctx.curKeyCenter
|
||||
of "2": return ctx.curKeyCenter + 2
|
||||
of "3": return ctx.curKeyCenter + 4
|
||||
of "4": return ctx.curKeyCenter + 5
|
||||
of "5": return ctx.curKeyCenter + 7
|
||||
of "6": return ctx.curKeyCenter + 9
|
||||
of "7": return ctx.curKeyCenter + 11
|
||||
of "#7", "1", "𝄫2": return ctx.curKeyCenter
|
||||
of "𝄪7", "#1", "b2", "♭2": return ctx.curKeyCenter + 1
|
||||
of "𝄪1", "2", "𝄫3": return ctx.curKeyCenter + 2
|
||||
of "#2", "b3", "♭3", "𝄫4": return ctx.curKeyCenter + 3
|
||||
of "𝄪2", "3", "b4", "♭4": return ctx.curKeyCenter + 4
|
||||
of "#3", "4", "𝄫5": return ctx.curKeyCenter + 5
|
||||
of "𝄪3", "#4", "b5", "♭5": return ctx.curKeyCenter + 6
|
||||
of "𝄪4", "5", "𝄫6": return ctx.curKeyCenter + 7
|
||||
of "#5", "b6", "♭6": return ctx.curKeyCenter + 8
|
||||
of "𝄪5", "6", "𝄫7": return ctx.curKeyCenter + 9
|
||||
of "#6", "b7", "♭7", "𝄫1": return ctx.curKeyCenter + 10
|
||||
of "7", "b1", "♭1": return ctx.curKeyCenter + 11
|
||||
else: raise ctx.makeError(keyValue.strip & " is not a recognized key.")
|
||||
|
||||
# see regexr.com/70nv1
|
||||
let CHORD_REGEX =
|
||||
"([A-G1-7][b#♭♮𝄫𝄪]?)" & # chord root
|
||||
"(([mM1-9#b♭♮𝄫𝄪Δ+oøoø][0-9]?|min|maj|aug|dim|sus|6\\/9|\\([1-9#b♭]+\\))*)" & # chord flavor/type
|
||||
"(\\/([A-G1-7][b#♭♮𝄫𝄪]?))?" # optional bass
|
||||
"([b#♭♮𝄫𝄪]?[A-G1-7][b#♭♮𝄫𝄪]?)" & # chord root
|
||||
"((min|maj|aug|dim|sus|6\\/9|[mM1-9#b♭♮𝄫𝄪Δ+oøoø°𝆩][0-9]?|\\([1-9#b♭]+\\))*)" & # chord flavor/type
|
||||
"(\\/([b#♭♮𝄫𝄪]?[A-G1-7][b#♭♮𝄫𝄪]?))?" # optional bass
|
||||
let CHORD_PAT = re(CHORD_REGEX)
|
||||
|
||||
proc parseChord*(
|
||||
@ -299,13 +344,46 @@ let PAGE_BREAK_PAT = re"\s*PAGE_BREAK\s*$"
|
||||
let TRANSPOSE_PAT = re"\s*TRANSPOSE KEY ([+-]\d+)\s*$"
|
||||
let REDEFINE_KEY_PAT = re"\s*REDEFINE KEY ([+-]\d+)\s*$"
|
||||
#let NOTE_PAT = re"^(.*)({{[^}]+}}|{[^}]+})(.*)$"
|
||||
let NOTE_START_PAT = re"{{"
|
||||
let NOTE_END_PAT = re"}}"
|
||||
let NOTE_START_PAT = re"\{\{"
|
||||
let NOTE_END_PAT = re"\}\}"
|
||||
let SPACE_PAT = re"\s"
|
||||
let CHORD_IN_LYRICS_PAT = re"(\w+)(\[.+)"
|
||||
let CHORD_AND_LYRICS_PAT = re"^\[([^\]]+)\]([^\s\[]+)(.*)$"
|
||||
let BRACED_CHORD_PAT = re"^\[([^\]]+)\]$"
|
||||
let NAKED_CHORDS_ONLY_PAT = re("^(" & CHORD_REGEX & "\\s*\\|*\\s*)+$")
|
||||
let NAKED_CHORDS_ONLY_PAT = re("^\\s*(" & CHORD_REGEX & "\\s*\\|*\\s*)+$")
|
||||
|
||||
proc readNote(ctx: var ParserContext, firstLine: string): tuple[pre, note, post: string] =
|
||||
let startLineNum = ctx.curLineNum
|
||||
|
||||
result = ("", "", "")
|
||||
|
||||
let startMatch = firstLine.find(NOTE_START_PAT)
|
||||
var endMatch = firstLine.find(NOTE_END_PAT)
|
||||
|
||||
if startMatch.isNone: return
|
||||
|
||||
if startMatch.get.matchBounds.a > 0:
|
||||
result.pre = firstLine[0..<startMatch.get.matchBounds.a]
|
||||
|
||||
if endMatch.isSome:
|
||||
result.note = firstLine[(startMatch.get.matchBounds.b + 1)..<endMatch.get.matchBounds.a]
|
||||
result.post = firstLine[(endMatch.get.matchBounds.b + 1)..^1]
|
||||
else:
|
||||
# if we don't find the end of the note, then we need to read more lines
|
||||
# until we do
|
||||
result.note = firstLine[(startMatch.get.matchBounds.b + 1)..^1]
|
||||
|
||||
while ctx.lines.len > ctx.curLineNum and ctx.hasNextLine:
|
||||
let line = ctx.nextLine
|
||||
endMatch = line.find(NOTE_END_PAT)
|
||||
if endMatch.isSome:
|
||||
result.note &= line[0..<endMatch.get.matchBounds.a]
|
||||
result.post = line[(endMatch.get.matchBounds.b + 1)..^1]
|
||||
return
|
||||
else: result.note &= line
|
||||
|
||||
raise ctx.makeError("a note section was started on line " &
|
||||
$startLineNum & " and never closed")
|
||||
|
||||
proc parseLineParts(ctx: ParserContext, parts: varargs[string]): seq[ChordChartNode] =
|
||||
result = @[]
|
||||
@ -349,10 +427,11 @@ proc parseLineParts(ctx: ParserContext, parts: varargs[string]): seq[ChordChartN
|
||||
chord: none[ChordChartChord](),
|
||||
word: some(p)))
|
||||
|
||||
proc parseLine(ctx: ParserContext, line: string): ChordChartNode =
|
||||
proc parseLine(lentCtx: var ParserContext, line: string): ChordChartNode =
|
||||
let ctx = lentCtx
|
||||
result = ChordChartNode(kind: ccnkLine)
|
||||
|
||||
let m = line.match(NAKED_CHORDS_ONLY_PAT)
|
||||
var m = line.match(NAKED_CHORDS_ONLY_PAT)
|
||||
if m.isSome:
|
||||
result.line = line.splitWhitespace --> map(
|
||||
ChordChartNode(
|
||||
@ -361,49 +440,28 @@ proc parseLine(ctx: ParserContext, line: string): ChordChartNode =
|
||||
spaceBefore: false, #FIXME
|
||||
chord: ctx.parseChord(it.strip),
|
||||
word: none[string]()))
|
||||
return
|
||||
|
||||
m = line.match(NOTE_START_PAT)
|
||||
if m.isSome:
|
||||
let (pre, note, post) = lentCtx.readNote(line)
|
||||
result.line = ctx.parseLineParts(pre) &
|
||||
@[ChordChartNode(
|
||||
kind: ccnkNote,
|
||||
inclInLyrics: true,
|
||||
note: note)] &
|
||||
ctx.parseLineParts(post)
|
||||
return
|
||||
|
||||
else: result.line = ctx.parseLineParts(line.splitWhitespace)
|
||||
|
||||
proc readNote(ctx: var ParserContext, endPat: Regex): string =
|
||||
let startLineNum = ctx.curLineNum
|
||||
result = ""
|
||||
|
||||
while ctx.lines.len > ctx.curLineNum and ctx.hasNextLine:
|
||||
let line = ctx.nextLine
|
||||
let m = line.find(endPat)
|
||||
if m.isSome:
|
||||
result &= line[0..<m.get.matchBounds.a]
|
||||
ctx.pushPartialsToParse(line[m.get.matchBounds.b..^1])
|
||||
break
|
||||
else: result &= line
|
||||
|
||||
if not ctx.hasNextLine:
|
||||
raise ctx.makeError("a note section was started on line " &
|
||||
$startLineNum & " and never closed")
|
||||
|
||||
proc parseBody(ctx: var ParserContext): seq[ChordChartNode] =
|
||||
result = @[]
|
||||
while ctx.hasNextLine:
|
||||
var line = ctx.nextLine
|
||||
|
||||
var m = line.find(NOTE_START_PAT)
|
||||
if m.isSome:
|
||||
if m.get.matchBounds.a > 0:
|
||||
# if this is not the first character of the line then let's split the
|
||||
# line and continue to parse
|
||||
ctx.pushPartialsToParse(
|
||||
line[0..<m.get.matchBounds.a],
|
||||
line[m.get.matchBounds.a..^1])
|
||||
continue
|
||||
|
||||
else:
|
||||
# if this is the first character of the line, then let's parse the note
|
||||
result.add(ChordChartNode(
|
||||
kind: ccnkNote,
|
||||
inclInLyrics: m.get.match.len < 2,
|
||||
note: ctx.readNote(NOTE_END_PAT)))
|
||||
|
||||
m = line.match(TRANSPOSE_PAT)
|
||||
var m = line.match(TRANSPOSE_PAT)
|
||||
if m.isSome:
|
||||
addToCurSection(ChordChartNode(
|
||||
kind: ccnkTransposeKey,
|
||||
@ -413,7 +471,7 @@ proc parseBody(ctx: var ParserContext): seq[ChordChartNode] =
|
||||
m = line.match(REDEFINE_KEY_PAT)
|
||||
if m.isSome:
|
||||
let newKeyInt = (
|
||||
cast[int](ctx.curKeyCenter) +
|
||||
ord(ctx.curKeyCenter) +
|
||||
parseInt(m.get.captures[0])
|
||||
) mod 12
|
||||
|
||||
@ -430,6 +488,7 @@ proc parseBody(ctx: var ParserContext): seq[ChordChartNode] =
|
||||
m = line.match(PAGE_BREAK_PAT)
|
||||
if m.isSome:
|
||||
result.add(ChordChartNode(kind: ccnkPageBreak))
|
||||
ctx.curSection = EMPTY_CHORD_CHART_NODE
|
||||
continue
|
||||
|
||||
m = line.match(SECTION_LINE_PAT)
|
||||
|
@ -1,4 +1,4 @@
|
||||
const PCO_CHORDS_VERSION* = "0.5.0"
|
||||
const PCO_CHORDS_VERSION* = "0.5.5"
|
||||
|
||||
const USAGE* = """Usage:
|
||||
pco_chords [options]
|
||||
@ -23,6 +23,7 @@ Options:
|
||||
--help Print this usage information
|
||||
--debug Enable debug logging.
|
||||
--echo-args Echo the input parameters.
|
||||
--large-print Use the large type styling.
|
||||
"""
|
||||
|
||||
const ONLINE_HELP* = """
|
||||
|
@ -22,10 +22,8 @@ const DEFAULT_STYLESHEET* = """
|
||||
|
||||
html { font-family: sans-serif; }
|
||||
|
||||
.page-contents {
|
||||
column-width: 336px;
|
||||
column-width: 3.5in;
|
||||
}
|
||||
.one-column .page-contents { column-count: 1; }
|
||||
.two-column .page-contents { column-count: 2; }
|
||||
|
||||
.column-break { margin-bottom: auto; }
|
||||
|
||||
@ -49,10 +47,12 @@ h3 .section-text {
|
||||
margin: 0 0.5em;
|
||||
}
|
||||
|
||||
.artist { font-style: italic; }
|
||||
|
||||
.line {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-end;
|
||||
align-items: end;
|
||||
|
||||
margin-left: 0.5em;
|
||||
margin-bottom: 0.5em;
|
||||
@ -65,16 +65,25 @@ h3 .section-text {
|
||||
}
|
||||
|
||||
.word.space-after { margin-right: 0.5em; }
|
||||
.word.no-chord { align-self: flex-end; }
|
||||
|
||||
.chord {
|
||||
font-weight: 600;
|
||||
margin-right: 0.5em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.chord > * {
|
||||
display: inline-block;
|
||||
height: 1.2em;
|
||||
}
|
||||
|
||||
.chord .flavor {
|
||||
font-variant-position: super;
|
||||
}
|
||||
|
||||
.note { margin-right: 1em; }
|
||||
|
||||
.song-order h3 {
|
||||
font-style: italic;
|
||||
font-weight: normal;
|
||||
@ -88,9 +97,100 @@ h3 .section-text {
|
||||
@media screen {
|
||||
body { margin: 1em; }
|
||||
}
|
||||
</style>
|
||||
"""
|
||||
|
||||
@media print {
|
||||
.page-contents { column-count: 2; }
|
||||
const LARGE_PRINT_STYLESHEET* = """
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html {
|
||||
font-family: sans-serif;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.one-column .page-contents { column-count: 1; }
|
||||
.two-column .page-contents { column-count: 2; }
|
||||
|
||||
.column-break { margin-bottom: auto; }
|
||||
|
||||
h2 { font-size: 1.25em; }
|
||||
|
||||
section {
|
||||
break-inside: avoid;
|
||||
padding-top: 1em;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.125rem;
|
||||
margin-bottom: 0.5em;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
h3 .section-text {
|
||||
font-style: italic;
|
||||
font-size: 1em;
|
||||
font-weight: normal;
|
||||
margin: 0 0.5em;
|
||||
}
|
||||
|
||||
.artist { font-style: italic; }
|
||||
|
||||
.line {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: baseline;
|
||||
|
||||
margin-left: 0.5em;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
.word {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.word.space-after { margin-right: 0.5em; }
|
||||
.word.no-chord { align-self: flex-end; }
|
||||
|
||||
.lyric {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.chord {
|
||||
font-style: italic;
|
||||
font-weight: 500;
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
.chord > * {
|
||||
display: inline-block;
|
||||
height: 1.2em;
|
||||
}
|
||||
|
||||
.chord .flavor {
|
||||
font-variant-position: super;
|
||||
}
|
||||
|
||||
.note { margin-right: 1em; }
|
||||
|
||||
.song-order h3 {
|
||||
font-style: italic;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.song-order li {
|
||||
list-style: none;
|
||||
margin-left: 1em;
|
||||
}
|
||||
|
||||
@media screen {
|
||||
body { margin: 1em; }
|
||||
}
|
||||
</style>
|
||||
"""
|
||||
@ -113,9 +213,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 +227,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
|
||||
@ -187,6 +291,7 @@ proc toHtml(ctx: var FormatContext, node: ChordChartNode, indent: string): strin
|
||||
result &= "<span class='word"
|
||||
#if node.spaceBefore: result&=" space-before"
|
||||
if node.spaceAfter: result&=" space-after"
|
||||
if node.chord.isNone: result&=" no-chord"
|
||||
result &= "'>"
|
||||
|
||||
if node.chord.isSome:
|
||||
@ -211,10 +316,7 @@ proc toHtml(ctx: var FormatContext, node: ChordChartNode, indent: string): strin
|
||||
|
||||
of ccnkTransposeKey:
|
||||
ctx.currentKey = ctx.currentKey + node.transposeSteps
|
||||
let headingVal = indent & "<h4 class=note>Key Change: " & $ctx.currentKey & "</h4>"
|
||||
if ctx.currentSection.kind == ccnkNone: result &= headingVal
|
||||
else:
|
||||
result &= "</section><section>" & headingVal & "</section><section>"
|
||||
result &= indent & "<h4 class=note>Key Change: " & $ctx.currentKey & "</h4>"
|
||||
|
||||
of ccnkRedefineKey:
|
||||
let oldKey = ctx.currentKey
|
||||
@ -250,7 +352,7 @@ proc toHtml*(
|
||||
result = """<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>""" & cc.metadata.title & "</title>\p"
|
||||
<title>""" & cc.metadata.title & " — " & $ctx.currentKey & "</title>\p"
|
||||
|
||||
for ss in stylesheets:
|
||||
if ss.startsWith("<style>"): result &= ss
|
||||
@ -262,7 +364,12 @@ proc toHtml*(
|
||||
elif fileExists(sc): result &= "<script>\p" & readFile(sc) & "\p</script>"
|
||||
else: warn "cannot read script file '" & sc & "'"
|
||||
|
||||
result &= " </head>\p <body>"
|
||||
result &= " </head>\p"
|
||||
|
||||
if cc.metadata.contains("columns") and cc.metadata["columns"] == "1":
|
||||
result &= " <body class='one-column'>"
|
||||
else:
|
||||
result &= " <body class='two-column'>"
|
||||
|
||||
var indent = " "
|
||||
|
||||
@ -279,6 +386,9 @@ proc toHtml*(
|
||||
|
||||
result &= indent & "<h2>" & metadataPieces.join(" | ") & "</h2>\p"
|
||||
|
||||
if cc.metadata.contains("artist"):
|
||||
result &= indent & "<div class=artist>" & cc.metadata["artist"] & "</div>\p"
|
||||
|
||||
result &= "<div class=page-contents>"
|
||||
result &= join(cc.nodes --> map(ctx.toHtml(it, indent & " ")), "\p")
|
||||
|
||||
|
Reference in New Issue
Block a user