Implement abs-pitch and sketch out pitch

This commit is contained in:
Jeremy Dormitzer 2018-07-19 17:50:11 -04:00
parent 90cdd35d02
commit dbd0c78589

View File

@ -34,21 +34,6 @@
{:duration 1/4, :pitch [:G 3]}
{:duration 1/4, :pitch [:A 3]}]])
;; TODO exercise 2.1 (ii-V-I function)
;; this will involve being able to answer, "what pitch is n semitones above this one?"
(def ii-V-I
(let [Dm [:= (note 1 [:D 4])
(note 1 [:F 4])
(note 1 [:A 4])]
Gmaj [:= (note 1 [:G 4])
(note 1 [:B 4])
(note 1 [:D 5])]
Cmaj [:= (note 2 [:C 4])
(note 2 [:E 4])
(note 2 [:G 4])]]
[:+ Dm Gmaj Cmaj]))
(defn note [duration pitch]
{:duration duration, :pitch pitch})
@ -70,5 +55,40 @@
(defn player [player-name music]
[:modify music {::player player-name}])
(defn keysig [pitch mode music]
[:modify music {::keysig [pitch mode]}])
(defn keysig [pitch-class mode music]
[:modify music {::keysig [pitch-class mode]}])
(defn pc-to-int [pitch-class]
(case pitch-class
:Cbb -2 :Cb -1 :C 0 :C# 1 :C## 2
:Dbb 0 :Db 1 :D 2 :D# 3 :D## 4
:Ebb 2 :Eb 3 :E 4 :E# 5 :E## 6
:Fbb 3 :Fb 4 :F 5 :F# 6 :F## 7
:Gbb 5 :Gb 6 :G 7 :G# 8 :G## 9
:Abb 7 :Ab 8 :A 9 :A# 10 :A## 11
:Bbb 9 :Bb 10 :B 11 :B# 12 :B## 13))
(defn abs-pitch [pitch-class octave]
"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."
())
;; TODO exercise 2.1 (ii-V-I function)
;; this will involve being able to answer, "what pitch is n semitones above this one?"
(def ii-V-I
(let [Dm [:= (note 1 [:D 4])
(note 1 [:F 4])
(note 1 [:A 4])]
Gmaj [:= (note 1 [:G 4])
(note 1 [:B 4])
(note 1 [:D 5])]
Cmaj [:= (note 2 [:C 4])
(note 2 [:E 4])
(note 2 [:G 4])]]
[:+ Dm Gmaj Cmaj]))