From 079d1107b40c75b84102a7243ea258fb621d054f Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 19 Jul 2018 20:10:03 -0400 Subject: [PATCH] Implement pitch and trans --- src/music.clj | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/music.clj b/src/music.clj index c796699..48414d2 100644 --- a/src/music.clj +++ b/src/music.clj @@ -72,11 +72,16 @@ "Returns the absolute pitch of a pitch class at an octave" (+ (* 12 octave) (pc-to-int pitch-class))) -;; TODO (defn pitch [abs-pitch] "Returns the pitch class and octave represented by the absolute pitch. In cases of enharmonic equivalence, returns the sharp rather than the flat." - ()) + (let [scale [:C :C# :D :D# :E :F :F# :G :G# :A :A# :B] + octave (quot abs-pitch 12) + index (rem abs-pitch 12)] + [(nth scale index) octave])) + +(defn trans [n [pitch-class octave]] + (pitch (+ (abs-pitch pitch-class octave) n))) ;; TODO exercise 2.1 (ii-V-I function) ;; this will involve being able to answer, "what pitch is n semitones above this one?"