Class: Tetsujin::Theory::Scale

Inherits:
Notes
  • Object
show all
Defined in:
lib/tetsujin/theory/scale.rb

Constant Summary collapse

SCALE_PATTERNS =
{
  major:            [2, 2, 1, 2, 2, 2, 1],
  minor:            [2, 1, 2, 2, 1, 2, 2],
  harmonic_minor:   [2, 1, 2, 2, 1, 3, 1],
  melodic_minor:    [2, 1, 2, 2, 2, 2, 1],
  dorian:           [2, 1, 2, 2, 2, 1, 2],
  phrygian:         [1, 2, 2, 2, 1, 2, 2],
  lydian:           [2, 2, 2, 1, 2, 2, 1],
  mixolydian:       [2, 2, 1, 2, 2, 1, 2],
  aeolian:          [2, 1, 2, 2, 1, 2, 2],
  locrian:          [1, 2, 2, 1, 2, 2, 2],
  whole_tone:       [2, 2, 2, 2, 2, 2],
  chromatic:        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  blues:            [3, 2, 1, 1, 3, 2],
  pentatonic_major: [2, 2, 3, 2, 3],
  pentatonic_minor: [3, 2, 2, 3, 2],
  diminished:       [2, 1, 2, 1, 2, 1, 2, 1]
}.freeze

Instance Method Summary collapse

Methods inherited from Notes

#+, #==

Constructor Details

#initialize(root:, pattern: :major) ⇒ Scale

Returns a new instance of Scale.

Raises:

  • (TypeError)


26
27
28
29
30
31
32
33
# File 'lib/tetsujin/theory/scale.rb', line 26

def initialize(root:, pattern: :major)
  raise TypeError unless root.is_a?(Tetsujin::Theory::Note)
  raise TypeError unless pattern.is_a?(Symbol)
  raise ArgumentError unless SCALE_PATTERNS.key?(pattern)

  @root = root
  @pattern = SCALE_PATTERNS[pattern]
end

Instance Method Details

#notesArray<Tetsujin::Theory::Note>



36
37
38
# File 'lib/tetsujin/theory/scale.rb', line 36

def notes
  @_notes ||= generate_scale
end