daveyarwood / music-theory

A music theory library for Clojure/ClojureScript
Eclipse Public License 1.0
42 stars 2 forks source link

`build-chord` function #13

Closed daveyarwood closed 8 years ago

daveyarwood commented 8 years ago

Building upon #12, we can write a function that, given a tonic note and any number of note intervals, it builds the chord.

e.g.

(build-chord :Bb4 :m3 :M3) ;=> [:Bb4 :Db5 :F5]
(build-chord :A2 :P8 :P5 :P4 :M3 :m3) ;=> [:A2 :A3 :E4 :A4 :C#5 :E5]

This would pave the way for a function (maybe just an overloaded version of this function?) that takes a tonic note and a chord name and returns the notes in the chord, e.g.

(build-chord :C4 :Cmaj7) ;=> [:C4 :E4 :G4 :B4]
daveyarwood commented 8 years ago

On second thought, if we gave build-chord a dual purpose as described above (variable number of intervals vs. chord name), there would be some ambiguity, e.g. :A11 could be either an augmented 11th or an A11 chord (A-C#-E-G-B-D).

To get around this, we can make the function always take 2 args, and if the second arg is a collection, e.g. (build-chord :Bb4 [:m3 :M3]), then we know they are supposed to be intervals, and if it's a single argument, e.g. (build-chord :A3 :A11) then we know it's supposed to be a chord name.

daveyarwood commented 8 years ago

Added in 0.3.0.