Class: Fet::ChordProgression

Inherits:
Object
  • Object
show all
Defined in:
lib/fet/chord_progression.rb

Overview

Class in charge of generating chord progressions, as well as any associated music theory

Constant Summary collapse

TEMPLATE_MAJOR =
"major".deep_freeze
TEMPLATE_MINOR =
"minor".deep_freeze
DEFAULT_TEMPLATES =
{
  # I-IV-V7-I
  TEMPLATE_MAJOR => [[0, 4, 7], [0, 5, 9], [-1, 5, 7], [0, 4, 7]],
  # i-iv-V7-i
  TEMPLATE_MINOR => [[0, 3, 7], [0, 5, 8], [-1, 5, 7], [0, 3, 7]],
}.deep_freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(offset:, template_type: nil, template: nil) ⇒ ChordProgression

Returns a new instance of ChordProgression.



18
19
20
21
22
23
24
# File 'lib/fet/chord_progression.rb', line 18

def initialize(offset:, template_type: nil, template: nil)
  self.template = template_type ? DEFAULT_TEMPLATES[template_type] : template
  validate_template!

  self.offset = offset
  validate_offset!
end

Instance Attribute Details

#offsetObject

Returns the value of attribute offset.



16
17
18
# File 'lib/fet/chord_progression.rb', line 16

def offset
  @offset
end

#templateObject

Returns the value of attribute template.



16
17
18
# File 'lib/fet/chord_progression.rb', line 16

def template
  @template
end

Instance Method Details

#with_offsetObject



26
27
28
# File 'lib/fet/chord_progression.rb', line 26

def with_offset
  return template.map { |chord| chord.map { |note| note + offset } }
end