Class: TransposeChords::Chord
- Inherits:
-
Object
- Object
- TransposeChords::Chord
- Defined in:
- lib/transpose_chords.rb
Class Method Summary collapse
Instance Method Summary collapse
- #capo(fret) ⇒ Object
-
#initialize(keys) ⇒ Chord
constructor
A new instance of Chord.
- #key_indexes ⇒ Object
- #keys_for(key) ⇒ Object
- #table ⇒ Object
- #table_key_for(key) ⇒ Object
- #to(key) ⇒ Object
Constructor Details
#initialize(keys) ⇒ Chord
Returns a new instance of Chord.
7 8 9 |
# File 'lib/transpose_chords.rb', line 7 def initialize(keys) @keys = keys end |
Class Method Details
.transpose(keys) ⇒ Object
3 4 5 |
# File 'lib/transpose_chords.rb', line 3 def self.transpose(keys) new(keys) end |
Instance Method Details
#capo(fret) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/transpose_chords.rb', line 39 def capo(fret) @keys.map do |k| key = table_key_for(k) table[:to_capo][key][fret] end end |
#key_indexes ⇒ Object
50 51 52 |
# File 'lib/transpose_chords.rb', line 50 def key_indexes @keys.map { |k| keys_for(table_key_for(@keys.first))[k] } end |
#keys_for(key) ⇒ Object
54 55 56 |
# File 'lib/transpose_chords.rb', line 54 def keys_for(key) Hash[table[:to_key][key].map.with_index{|*ki| ki}] end |
#table ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/transpose_chords.rb', line 11 def table { to_key: { c: ['C', 'Dm', 'Em', 'F', 'G', 'Am', 'Bdim'], d: ['D', 'Em', 'F#m', 'G', 'A', 'Bm', 'C#dim'], e: ['E', 'F#m', 'G#m', 'A', 'B', 'C#m', 'D#dim'], f: ['F', 'Gm', 'Am', 'Bb', 'C', 'Dm', 'Edim'], g: ['G', 'Am', 'Bm', 'C', 'D', 'Em', 'F#dim'], a: ['A', 'Bm', 'C#m', 'D', 'E', 'F#m', 'G#dim'], b: ['B', 'C#m', 'D#m', 'E', 'F#', 'G#m', 'A#dim'] }, to_capo: { c: ['C', 'C#/Db', 'D', 'D#/Eb', 'E', 'F', 'F#/Gb', 'G'], d: ['D', 'D#/Eb', 'E', 'F', 'F#/Gb', 'G', 'Gb/Ab', 'A'], e: ['E', 'F', 'F#/Gb', 'G', 'G#/Ab', 'A', 'A#/Bb', 'B'], f: ['F', 'F#/Gb', 'G', 'G#/Ab', 'A', 'A#/Bb', 'B', 'C'], g: ['G', 'G#/Ab', 'A', 'A#/Bb', 'B', 'C', 'C#/Db', 'D'], a: ['A', 'A#/Bb', 'B', 'C', 'C#/Db', 'D', 'D#/Eb', 'E'], b: ['B', 'C', 'C#/Db', 'D', 'D#/Eb', 'E', 'F', 'F#/Gb'] } } end |
#table_key_for(key) ⇒ Object
46 47 48 |
# File 'lib/transpose_chords.rb', line 46 def table_key_for(key) key.downcase.to_sym end |
#to(key) ⇒ Object
34 35 36 37 |
# File 'lib/transpose_chords.rb', line 34 def to(key) key = table_key_for(key) key_indexes.map { |k| table[:to_key][key][k] } end |