Replace toScaleDegree with parseSpelledPitchOrScaleDegree to support chord charts written in key signature or numbers.
This commit is contained in:
@@ -186,12 +186,12 @@ proc parseChord*(
|
|||||||
|
|
||||||
let bass =
|
let bass =
|
||||||
if m.get.captures.contains(4) and m.get.captures[4].len > 0:
|
if m.get.captures.contains(4) and m.get.captures[4].len > 0:
|
||||||
some(toScaleDegree(ctx.curKey, parseSpelledPitch(m.get.captures[4])))
|
some(parseSpelledPitchOrScaleDegree(ctx.curKey, m.get.captures[4]))
|
||||||
else: none[ScaleDegree]()
|
else: none[ScaleDegree]()
|
||||||
|
|
||||||
return some(ChordChartChord(
|
return some(ChordChartChord(
|
||||||
original: some(chordValue),
|
original: some(chordValue),
|
||||||
root: toScaleDegree(ctx.curKey, parseSpelledPitch(m.get.captures[0])),
|
root: parseSpelledPitchOrScaleDegree(ctx.curKey, m.get.captures[0]),
|
||||||
flavor: flavor,
|
flavor: flavor,
|
||||||
bass: bass))
|
bass: bass))
|
||||||
|
|
||||||
|
|||||||
@@ -314,6 +314,16 @@ func toScaleDegree*(k: Key, sp: SpelledPitch): ScaleDegree =
|
|||||||
]#
|
]#
|
||||||
|
|
||||||
|
|
||||||
|
func parseSpelledPitchOrScaleDegree*(key: Key, str: string): ScaleDegree =
|
||||||
|
try:
|
||||||
|
let pitch =parseSpelledPitch(str)
|
||||||
|
return toScaleDegree(key, pitch)
|
||||||
|
except:
|
||||||
|
try: return parseScaleDegree(str)
|
||||||
|
except:
|
||||||
|
raise newException(ValueError,
|
||||||
|
str & " is not a recognized pitch or scale degree")
|
||||||
|
|
||||||
|
|
||||||
func transpose*(k: Key, steps: int): Key =
|
func transpose*(k: Key, steps: int): Key =
|
||||||
Key(
|
Key(
|
||||||
|
|||||||
Reference in New Issue
Block a user