Module: Trriad::Chord
- Defined in:
- lib/trriad/chord.rb,
lib/trriad/chord_data.rb
Constant Summary collapse
- CHORDS =
all the different chord notations
{ "maj" => "1,3,5".split(','), "m" => "1,3b,5".split(','), "7" => "1,3,5,7b".split(','), "6" => "1,3,5,6".split(','), "m6" => "1,3b,5,6".split(','), "maj7" => "1,3,5,7".split(','), "m7" => "1,3b,5,7".split(','), "dim" => "1,3b,5b,6".split(','), "+" => "1,3,5#".split(','), "9" => "1,3,5,7b,9".split(','), "7+5" => "1,3,5#,7b".split(','), "7b5" => "1,3,5b,7b".split(','), "m7b5" => "1,3b,5b,7b".split(','), "m9" => "1,3b,5,7b,9".split(','), "9+5" => "1,3,5#,7b,9".split(','), "9b5" => "1,3,5b,7b,9".split(','), "maj9" => "1,3,5,7,9".split(','), "6add9" => "1,3,5,6,9".split(','), "7b9" => "1,3,5,7b,9b".split(','), "7sus4" => "1,4,5,7b".split(','), "7add6" => "1,3,5,6,7b".split(','), "11" => "1,3,5,7b,9,11".split(','), "11+" => "1,3,5,7b,9,11#".split(','), "11b9" => "1,3,5,7b,9b,11".split(','), "13" => "1,3,5,7b,9,11,13".split(','), "13b9" => "1,3,5,7b,9b,11,13".split(','), }
- NOTES =
sharp and flat available notes
{ :sharp => "C,C#,D,D#,E,F,F#,G,G#,A,A#,B".split(","), :flat => "C,Db,D,Eb,E,F,Gb,G,Ab,A,Bb,B".split(",") }
- DISTANCES =
DISTANCES = “2,2,1,2,2,2,1”.split(“,”) the semitone distances for a major key
"2,2,1,2,2,2".split(",")
- KEYS =
differentiate the keys with sharps and flats
{ # since we only have :sharp an :flat, I need to put "C" somewhere # so it's in :sharp :sharp => "C,G,D,A,E,B,F#,C#".split(","), :flat => "Bb,Eb,Ab,Db,Gb,Cb,Fb".split(","), }
Class Method Summary collapse
-
.get_scale(root) ⇒ Object
get the scale of a root note returns an array of strings with the scale notes.
-
.next_semi(root, accidental = :sharp) ⇒ Object
get the next semi note return the note as a string.
-
.valid_note(note) ⇒ Object
check if it’s a valid note returns true of false.
Class Method Details
.get_scale(root) ⇒ Object
get the scale of a root note returns an array of strings with the scale notes
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/trriad/chord.rb', line 25 def self.get_scale(root) accitental = nil accidental = :flat if KEYS[:flat].include?(root) accidental = :sharp if KEYS[:sharp].include?(root) result="#{root}" cur=root DISTANCES.each { |distance| 1.upto(distance.to_i) { cur=next_semi(cur,accidental) } result += ",#{cur}" } result.split(',') end |
.next_semi(root, accidental = :sharp) ⇒ Object
get the next semi note return the note as a string
14 15 16 17 18 19 20 21 |
# File 'lib/trriad/chord.rb', line 14 def self.next_semi(root, accidental = :sharp) if NOTES[accidental].include?(root) then at=NOTES[accidental].index(root) tmp=NOTES[accidental] + NOTES[accidental] at+=1 tmp[at] end end |