Class: Coltrane::Theory::RomanChord
- Inherits:
-
Object
- Object
- Coltrane::Theory::RomanChord
- Defined in:
- lib/coltrane/theory/roman_chord.rb
Overview
This class deals with chords in roman notation. Ex: IVº.
Constant Summary collapse
- DIGITS =
%w[I II III IV V VI VII].freeze
- NOTATION_REGEX =
/(b?[ivIV]*)(.*)/
- NOTATION_SUBSTITUTIONS =
[ %w[º dim], %w[o dim], %w[ø m7b5] ].freeze
Instance Method Summary collapse
- #chord ⇒ Object
- #degree ⇒ Object
- #function ⇒ Object
-
#initialize(notation = nil, chord: nil, key: nil, scale: nil) ⇒ RomanChord
constructor
A new instance of RomanChord.
- #major? ⇒ Boolean
- #minor? ⇒ Boolean
- #notation ⇒ Object
- #quality ⇒ Object
- #quality_name ⇒ Object
- #roman_numeral ⇒ Object
- #root_note ⇒ Object
- #upcase? ⇒ Boolean
Constructor Details
#initialize(notation = nil, chord: nil, key: nil, scale: nil) ⇒ RomanChord
Returns a new instance of RomanChord.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/coltrane/theory/roman_chord.rb', line 16 def initialize(notation = nil, chord: nil, key: nil, scale: nil) if notation.nil? && chord.nil? || key.nil? && scale.nil? raise WrongKeywordsError, '[notation, [scale: || key:]] '\ '[chord:, [scale: || key:]] '\ end @scale = scale || Key[key] if notation @notation = notation elsif chord @chord = chord.is_a?(String) ? Chord.new(name: chord) : chord end end |
Instance Method Details
#chord ⇒ Object
47 48 49 50 |
# File 'lib/coltrane/theory/roman_chord.rb', line 47 def chord @chord ||= Chord.new root_note: root_note, quality: quality end |
#degree ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/coltrane/theory/roman_chord.rb', line 30 def degree return @scale.degree_of_note(root_note) unless @chord.nil? d = regexed_notation[:degree] @flats = d.count('b') d = d.delete('b') @degree ||= DIGITS.index(d.upcase) + 1 end |
#function ⇒ Object
91 92 93 94 95 |
# File 'lib/coltrane/theory/roman_chord.rb', line 91 def function return if @scale.name != 'Major' %w[Tonic Supertonic Mediant Subdominant Dominant Submediant Leading][degree - 1] end |
#major? ⇒ Boolean
56 57 58 |
# File 'lib/coltrane/theory/roman_chord.rb', line 56 def major? quality.has_major_third? end |
#minor? ⇒ Boolean
52 53 54 |
# File 'lib/coltrane/theory/roman_chord.rb', line 52 def minor? quality.has_minor_third? end |
#notation ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/coltrane/theory/roman_chord.rb', line 78 def notation q = case quality_name when 'm', 'M' then '' when 'm7', 'M' then '7' else quality_name end @notation ||= [ roman_numeral, q ].join end |
#quality ⇒ Object
68 69 70 71 |
# File 'lib/coltrane/theory/roman_chord.rb', line 68 def quality return @chord.quality unless @chord.nil? ChordQuality.new(name: quality_name) if quality_name end |
#quality_name ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/coltrane/theory/roman_chord.rb', line 60 def quality_name return @chord.quality.name unless @chord.nil? q = normalize_quality_name(regexed_notation[:quality]) minor = 'm' if (!q.match? /dim|m7b5/) && !upcase? q = [minor, q].join q.empty? ? 'M' : q end |
#roman_numeral ⇒ Object
38 39 40 41 |
# File 'lib/coltrane/theory/roman_chord.rb', line 38 def roman_numeral r = DIGITS[degree] minor? ? r.downcase : r end |
#root_note ⇒ Object
73 74 75 76 |
# File 'lib/coltrane/theory/roman_chord.rb', line 73 def root_note return @chord.root_note unless @chord.nil? @scale[degree] - @flats end |
#upcase? ⇒ Boolean
43 44 45 |
# File 'lib/coltrane/theory/roman_chord.rb', line 43 def upcase? !!(regexed_notation[:degree][0].match /[[:upper:]]/) end |