module Test.AbcPerformance exposing (tests) import Test exposing (..) import Expect exposing (..) import Abc exposing (ParseError, parse, parseKeySignature, parseError) import Abc.ParseTree exposing (..) import AbcPerformance exposing (..) import Music.Notation exposing (NoteTime, MidiPitch) import Melody exposing (..) import RepeatTypes exposing (..) import Debug exposing (..) {- get the melody line -} getMelodyLine : String -> Result ParseError MelodyLine getMelodyLine s = parse s |> melodyFromAbcResult {- get notes from the first bar -} getFirstBarNotes : String -> List NoteEvent getFirstBarNotes s = let melodyResult = getMelodyLine s in case melodyResult of Ok res -> let maybeFirstBar = List.head res in case maybeFirstBar of Just abar -> abar.notes _ -> [] Err errs -> [] {- show bar 1 and assert we have some notes -} showBar1Notes : String -> Expectation showBar1Notes s = let bar1Notes = getFirstBarNotes s in Expect.false "non empty bar" (List.isEmpty bar1Notes) {- assert the notes match the target from bar 1 in the melody line -} assertBar1Notes : String -> List NoteEvent -> Expectation assertBar1Notes s target = Expect.equal target (getFirstBarNotes s) tests : Test tests = describe "ABC Performance melody line" [ test "sequence" <| \() -> (assertBar1Notes sequence sequenceM) , test "chord" <| \() -> (assertBar1Notes chord chordM) , test "triplet" <| \() -> (assertBar1Notes triplet tripletM) , test "broken rhythm up" <| \() -> (assertBar1Notes brokenRhythmUp brokenRhythmUpM) , test "broken rhythm down" <| \() -> (assertBar1Notes brokenRhythmDown brokenRhythmDownM) , test "tied sequence" <| \() -> (assertBar1Notes sequenceTied sequenceTiedM) , test "sequence with accidental" <| \() -> (assertBar1Notes sequenceAccidental sequenceAccidentalM) , test "triplet with accidental" <| \() -> (assertBar1Notes tripletAccidental tripletAccidentalM) , test "broken rhythm with accidental" <| \() -> (assertBar1Notes brokenRhythmAccidental brokenRhythmAccidentalM) , test "broken rhythm with internal accidental" <| \() -> (assertBar1Notes brokenRhythmInternalAccidental brokenRhythmInternalAccidentalM) ] -- each test should just investigate a single bar -- music sources sequence = "K: D\r\n| def |\r\n" chord = "K: D\r\n| [def]2 |\r\n" triplet = "K: D\r\n| (3def |\r\n" brokenRhythmUp = "K: D\r\n| d