Skip to content

Commit

Permalink
Merge pull request #177 from alda-lang/bugfix-voice-parsing
Browse files Browse the repository at this point in the history
bugfix re: voice parsing
  • Loading branch information
daveyarwood committed Jan 28, 2016
2 parents 368816b + e1c4292 commit 137ac22
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 38 deletions.
42 changes: 22 additions & 20 deletions server/grammar/events.bnf
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
<part> = <ows> events <ows>
<events> = event? (<ows> event)*
<part> = <ows> events <ows>
<events> = event? (<ows> event)*
<events-inside-voice> = event-inside-voice? (<ows> event-inside-voice)*

(* notes, chords & other events *)

<event> = single-event | repeat | voices
<single-event> = chord | note | rest | octave-change |
<event> = single-event | repeat | voices
<event-inside-voice> = single-event | repeat
<single-event> = chord | note | rest | octave-change |
clj-expr-cached | marker | at-marker | barline |
event-sequence | cram

repeat = single-event <ows> <"*"> <ows> positive-number <ows>
repeat = single-event <ows> <"*"> <ows> positive-number <ows>

(* chords, notes, rests *)

chord = (note | rest) subchord+
<subchord> = <"/"> <ows> (octave-change | clj-expr-cached)*
chord = (note | rest) subchord+
<subchord> = <"/"> <ows> (octave-change | clj-expr-cached)*
<ows> (note | rest) <ows>
note = pitch duration? <ows> slur?
rest = <"r"> duration? <ows>
note = pitch duration? <ows> slur?
rest = <"r"> duration? <ows>

(* pitch *)

pitch = #"[a-g]" accidental*
<accidental> = flat | sharp | natural
flat = "-"
sharp = "+"
natural = "="
pitch = #"[a-g]" accidental*
<accidental> = flat | sharp | natural
flat = "-"
sharp = "+"
natural = "="

(* octaves *)

<octave-change> = (octave-set | octave-up | octave-down) <ows>
octave-set = <"o"> number
octave-up = <">">
octave-down = <"<">
<octave-change> = (octave-set | octave-up | octave-down) <ows>
octave-set = <"o"> number
octave-up = <">">
octave-down = <"<">

(* markers *)

marker = <"%"> name <ows>
at-marker = <"@"> name <ows>
marker = <"%"> name <ows>
at-marker = <"@"> name <ows>

2 changes: 1 addition & 1 deletion server/grammar/voices.bnf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
voices = voice+ (<voice-zero> | <#"\z">)
voice = voice-number <ows> events
voice = voice-number <ows> events-inside-voice
voice-number = <"V"> #"[1-9]\d*" <":"> <ows>
<voice-zero> = <"V0:"> <ows>

54 changes: 37 additions & 17 deletions server/test/alda/parser/events_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,43 @@

(deftest voice-tests
(testing "voices"
(is (= (parse-with-context :music-data "V1: a b c")
'((alda.lisp/voices
(alda.lisp/voice 1
(alda.lisp/note (alda.lisp/pitch :a))
(alda.lisp/note (alda.lisp/pitch :b))
(alda.lisp/note (alda.lisp/pitch :c)))))))
(is (= (parse-with-context :music-data "V1: a b c
V2: d e f")
'((alda.lisp/voices
(alda.lisp/voice 1
(alda.lisp/note (alda.lisp/pitch :a))
(alda.lisp/note (alda.lisp/pitch :b))
(alda.lisp/note (alda.lisp/pitch :c)))
(alda.lisp/voice 2
(alda.lisp/note (alda.lisp/pitch :d))
(alda.lisp/note (alda.lisp/pitch :e))
(alda.lisp/note (alda.lisp/pitch :f)))))))))
(is (= (parse-with-context :part "piano: V1: a b c")
'(alda.lisp/part {:names ["piano"]}
(alda.lisp/voices
(alda.lisp/voice 1
(alda.lisp/note (alda.lisp/pitch :a))
(alda.lisp/note (alda.lisp/pitch :b))
(alda.lisp/note (alda.lisp/pitch :c)))))))
(is (= (parse-with-context :part "piano:
V1: a b c
V2: d e f")
'(alda.lisp/part {:names ["piano"]}
(alda.lisp/voices
(alda.lisp/voice 1
(alda.lisp/note (alda.lisp/pitch :a))
(alda.lisp/note (alda.lisp/pitch :b))
(alda.lisp/note (alda.lisp/pitch :c)))
(alda.lisp/voice 2
(alda.lisp/note (alda.lisp/pitch :d))
(alda.lisp/note (alda.lisp/pitch :e))
(alda.lisp/note (alda.lisp/pitch :f)))))))
(is (= (parse-with-context :part "piano:
V1: [a b c] *8
V2: [d e f] *8")
'(alda.lisp/part {:names ["piano"]}
(alda.lisp/voices
(alda.lisp/voice 1
(alda.lisp/times 8
(do
(alda.lisp/note (alda.lisp/pitch :a))
(alda.lisp/note (alda.lisp/pitch :b))
(alda.lisp/note (alda.lisp/pitch :c)))))
(alda.lisp/voice 2
(alda.lisp/times 8
(do
(alda.lisp/note (alda.lisp/pitch :d))
(alda.lisp/note (alda.lisp/pitch :e))
(alda.lisp/note (alda.lisp/pitch :f)))))))))))

(deftest marker-tests
(testing "markers"
Expand Down

0 comments on commit 137ac22

Please sign in to comment.