Class: Coltrane::Progression
- Inherits:
-
Object
- Object
- Coltrane::Progression
- Extended by:
- ClassicProgressions
- Defined in:
- lib/coltrane/progression.rb
Overview
Allows the creation of chord progressions using standard notations. Ex: Progression.new(‘I-IV-V’, key: ‘Am’)
Instance Attribute Summary collapse
-
#chords ⇒ Object
readonly
Returns the value of attribute chords.
-
#notation ⇒ Object
readonly
Returns the value of attribute notation.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(notation = nil, chords: nil, roman_chords: nil, key: nil, scale: nil) ⇒ Progression
constructor
A new instance of Progression.
- #interval_sequence ⇒ Object
- #roman_chords ⇒ Object
- #root_notes ⇒ Object
Constructor Details
#initialize(notation = nil, chords: nil, roman_chords: nil, key: nil, scale: nil) ⇒ Progression
Returns a new instance of Progression.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/coltrane/progression.rb', line 19 def initialize(notation=nil, chords: nil, roman_chords: nil, key: nil, scale: nil) if notation.nil? && chords.nil? && roman_chords.nil? || key.nil? && scale.nil? raise WrongKeywordsError, '[chords:, [scale: || key:]] '\ '[roman_chords:, [scale: || key:]] '\ '[notation:, [scale: || key:]] '\ end @scale = scale || Scale.from_key(key) @chords = if !chords.nil? chords elsif !roman_chords.nil? roman_chords.map(&:chord) elsif !notation.nil? @notation = notation notation.split('-').map {|c| RomanChord.new(c, scale: @scale).chord } end end |
Instance Attribute Details
#chords ⇒ Object (readonly)
Returns the value of attribute chords.
9 10 11 |
# File 'lib/coltrane/progression.rb', line 9 def chords @chords end |
#notation ⇒ Object (readonly)
Returns the value of attribute notation.
9 10 11 |
# File 'lib/coltrane/progression.rb', line 9 def notation @notation end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
9 10 11 |
# File 'lib/coltrane/progression.rb', line 9 def scale @scale end |
Class Method Details
.find(*chords) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/coltrane/progression.rb', line 11 def self.find(*chords) chords.map! { |c| Chord.new(name: c) } if chords[0].is_a?(String) scales = Scale.having_chords(*chords).scales scales.reduce([]) do |memo, scale| memo + [Progression.new(chords: chords, scale: scale)] end end |
Instance Method Details
#interval_sequence ⇒ Object
39 40 41 |
# File 'lib/coltrane/progression.rb', line 39 def interval_sequence @interval_sequence ||= IntervalSequence(notes: @root_notes) end |
#roman_chords ⇒ Object
47 48 49 50 51 |
# File 'lib/coltrane/progression.rb', line 47 def roman_chords @roman_chords ||= chords.map do |c| RomanChord.new(chord: c, scale: scale) end end |
#root_notes ⇒ Object
43 44 45 |
# File 'lib/coltrane/progression.rb', line 43 def root_notes @root_notes ||= @chords.map(&:root_note) end |