Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Repeated accidentals #47

Open
wants to merge 2 commits into
base: feature/improve-timesignature-and-key-api
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/MusicTheory/Notation.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module MusicTheory.Notation exposing
, chord
, chordNote
, doubleLine
, fromStaffs
, fromVoice
, length
, line
Expand All @@ -34,6 +35,7 @@ module MusicTheory.Notation exposing
, voiceDuration
, voiceElementDuration
, voiceMap
, withKey
)

import Libs.Ratio as Ratio exposing (Rational)
Expand Down Expand Up @@ -209,17 +211,33 @@ bass =
Bass


fromVoice : Voice a -> Notation a
fromVoice voice =
fromVoice : Clef -> Voice a -> Notation a
fromVoice clef voice =
{ title = Nothing
, composer = Nothing
, key = Key.cMajor
, timeSignature = TimeSignature.four TimeSignature.quarters
, tempo = Nothing
, staffs = [ staff treble [ voice ] ]
, staffs = [ staff clef [ voice ] ]
}


fromStaffs : List (Staff a) -> Notation a
fromStaffs staffs =
{ title = Nothing
, composer = Nothing
, key = Key.cMajor
, timeSignature = TimeSignature.four TimeSignature.quarters
, tempo = Nothing
, staffs = staffs
}


withKey : Key -> Notation a -> Notation a
withKey key notation =
{ notation | key = key }



-- ATTRIBUTES

Expand Down
47 changes: 46 additions & 1 deletion tests/Notation/AbcTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ all =
, note [] (cNatural five) sixteenthNote
]
]
|> fromVoice
|> fromVoice treble
|> Abc.fromNotation 4
|> Expect.equal expected
, test "multiple staffs to ABC notation" <|
Expand All @@ -201,4 +201,49 @@ all =
multipleLines
|> Abc.fromNotation 4
|> Expect.equal expected
, test "repeated accidentals" <|
\_ ->
let
voice1 =
[ bar []
[ line
[ note [] (cSharp five) quarterNote
, note [] (dNatural five) quarterNote
, rest [] quarterNote
, note [] (eNatural five) quarterNote
]
]
, bar [] [ rest [] wholeNote ]
]
|> line

voice2 =
[ bar []
[ line
[ rest [] eighthNote
, note [] (cNatural five) quarterNote
, note [] (dNatural five) eighthNote
, rest [] eighthNote
, note [] (eFlat five) (dotted quarterNote)
]
]
, bar []
[ note [] (fSharp three) quarterNote
, note [] (fNatural three) quarterNote
, note [] (fNatural three) quarterNote
, note [] (fSharp three) quarterNote
]
]
|> line

music =
fromStaffs [ { clef = treble, voices = [ voice1, voice2 ] } ]
|> withKey Key.gMajor

expected =
"M: 4/4\n%%score (0 1)\nV: 0 clef=treble\nV: 1 clef=treble\nK: G\n[V:0]^c2/1 d2/1 z2/1 =e2/1 | z8 |\n[V:1]z1/1 =c2/1 d1/1 z1/1 _e3/1 | F2 =F2 F2 ^F2 |"
in
music
|> Abc.fromNotation 4
|> Expect.equal expected
]