diff --git a/.gitignore b/.gitignore index 04f33cc..11b90e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ pco_chords -src/notation +src/pco_chordspkg/notation .*.sw? diff --git a/src/pco_chordspkg/notation.nim b/src/pco_chordspkg/notation.nim index 2cfad4c..80440c4 100644 --- a/src/pco_chordspkg/notation.nim +++ b/src/pco_chordspkg/notation.nim @@ -387,3 +387,63 @@ when isMainModule: assert "#5" == $toScaleDegree( Key(tonic: parseSpelledPitch("Eb"), mode: Ionian), parseSpelledPitch("B")) + + assert toSpelledPitch(Pitch.F + 2) == + SpelledPitch(note: Note.G, alteration: naNatural) + + let pitchCases = [ + (Pitch.Af, SpelledPitch(note: Note.A, alteration: naFlat)), + (Pitch.A, SpelledPitch(note: Note.A, alteration: naNatural)), + (Pitch.Bf, SpelledPitch(note: Note.B, alteration: naFlat)), + (Pitch.B, SpelledPitch(note: Note.B, alteration: naNatural)), + (Pitch.C, SpelledPitch(note: Note.C, alteration: naNatural)), + (Pitch.Df, SpelledPitch(note: Note.D, alteration: naFlat)), + (Pitch.D, SpelledPitch(note: Note.D, alteration: naNatural)), + (Pitch.Ef, SpelledPitch(note: Note.E, alteration: naFlat)), + (Pitch.E, SpelledPitch(note: Note.E, alteration: naNatural)), + (Pitch.F, SpelledPitch(note: Note.F, alteration: naNatural)), + (Pitch.Gf, SpelledPitch(note: Note.G, alteration: naFlat)), + (Pitch.G, SpelledPitch(note: Note.G, alteration: naNatural)), + ] + for (pitch, expected) in pitchCases: + assert toSpelledPitch(pitch) == expected + + let spelledPitchCases = [ + ("Ab", Pitch.Af), + ("G#", Pitch.Af), + ("A", Pitch.A), + ("G##", Pitch.A), + ("Bbb", Pitch.A), + ("Bb", Pitch.Bf), + ("A#", Pitch.Bf), + ("Cbb", Pitch.Bf), + ("B", Pitch.B), + ("Cb", Pitch.B), + ("A##", Pitch.B), + ("C", Pitch.C), + ("B#", Pitch.C), + ("Dbb", Pitch.C), + ("Db", Pitch.Df), + ("C#", Pitch.Df), + ("B##", Pitch.Df), + ("D", Pitch.D), + ("C##", Pitch.D), + ("Ebb", Pitch.D), + ("Eb", Pitch.Ef), + ("D#", Pitch.Ef), + ("Fbb", Pitch.Ef), + ("E", Pitch.E), + ("Fb", Pitch.E), + ("D##", Pitch.E), + ("F", Pitch.F), + ("E#", Pitch.F), + ("Gbb", Pitch.F), + ("Gb", Pitch.Gf), + ("F#", Pitch.Gf), + ("E##", Pitch.Gf), + ("G", Pitch.G), + ("F##", Pitch.G), + ("Abb", Pitch.G), + ] + for (spelled, expected) in spelledPitchCases: + assert parseSpelledPitch(spelled).toPitch == expected