Skip to content

Commit

Permalink
Implemented notation for note sequences, chords, and simulaneous voices.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgre committed Feb 17, 2013
1 parent ea7ad1a commit c523816
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/ironlambda/score.clj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@
(ot/apply-at (metronome next-beat) play instrument metronome next-beat
(with-meta (next notes) (meta notes)) []))))

(defmethod notation ::Notes
[notes]
(apply str "(notes"
(concat (map (fn [{:keys [pitch duration]}] (str " " (notation pitch) " " duration)) notes)
[")"])))

(derive ::Simultaneity ::Playable)
(derive ::Chord ::Simultaneity)

Expand All @@ -110,6 +116,20 @@
(doseq [p (:playables sim)] (play instrument metronome beat p))
(+ beat (:duration sim)))

(defmethod notation ::Simultaneity
[{:keys [playables duration]}]
(apply str "(voices " (concat (interpose " " (map notation playables)) [" " duration ")"])))

(defmethod notation ::Chord
[{:keys [playables duration]}]
(if (every? #(= duration (:duration %)) playables)
(apply str "(chord " duration
(concat (map (fn [{:keys [pitch]}] (str " " (notation pitch))) playables)
[")"]))
(apply str "(chord"
(concat (map (fn [note] (str " " (notation note))) playables)
[" " duration ")"]))))

(defn duration
"Calculate the duration of a sequence of playables."
[ps]
Expand Down Expand Up @@ -146,5 +166,11 @@
(piano soprano)
(piano alto)
(piano (voices [soprano alto]))
(notation (voices [soprano alto]))

(notation alto)

(piano (chord 4 C4 E4 G4 B4))
(notation (chord 4 C4 E4 G4 B4))

(piano (chord 4 C4 E4 G4 B4)))
(notation (chord [(note C4 2) (note G4 1)])))

0 comments on commit c523816

Please sign in to comment.