Module: Coltrane::Theory::ClassicScales

Included in:
Scale
Defined in:
lib/coltrane/theory/classic_scales.rb

Overview

This module deals with well known scales on music

Constant Summary collapse

SCALES =
{
  'Pentatonic Major' => [2, 2, 3, 2, 3],
  'Blues Major'      => [2, 1, 1, 3, 2, 3],
  'Harmonic Minor'   => [2, 1, 2, 2, 1, 3, 1],
  'Hungarian Minor'  => [2, 1, 2, 1, 1, 3, 1],
  'Pentatonic Minor' => [3, 2, 2, 3, 2],
  'Blues Minor'      => [3, 2, 1, 1, 3, 2],
  'Whole Tone'       => [2, 2, 2, 2, 2, 2],
  'Flamenco'         => [1, 3, 1, 2, 1, 2, 2],
  'Chromatic'        => [1] * 12
}.freeze
GREEK_MODES =
%w[
  Ionian
  Dorian
  Phrygian
  Lydian
  Mixolydian
  Aeolian
  Locrian
].freeze

Instance Method Summary collapse

Instance Method Details

#fetch(name, tone = nil) ⇒ Object



68
69
70
# File 'lib/coltrane/theory/classic_scales.rb', line 68

def fetch(name, tone = nil)
  public_send(name.underscore, tone)
end

#having_chords(*chords) ⇒ Object Also known as: having_chord



102
103
104
105
106
107
108
# File 'lib/coltrane/theory/classic_scales.rb', line 102

def having_chords(*chords)
  should_create = !chords.first.is_a?(Chord)
  notes = chords.reduce(NoteSet[]) do |memo, c|
    memo + (should_create ? Chord.new(name: c) : c).notes
  end
  having_notes(notes)
end

#having_notes(notes) ⇒ Object

def having_notes(notes)

format = { scales: [], results: {} }
standard_scales.each_with_object(format) do |name, output|
  PitchClass.all.each.map do |tone|
    scale = send(name.underscore, tone)
    output[:results][name] ||= {}
    next if output[:results][name].key?(tone.integer)
    output[:scales] << scale if scale.include?(notes)
    output[:results][name][tone.integer] = scale.notes & notes
  end
end

end



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/coltrane/theory/classic_scales.rb', line 85

def having_notes(notes)
  PitchClass.all
  .reduce([]) { |scales, tone|
    standard_scales
    .reduce([]) { |tone_scales, scale|
      fetch(scale, tone)
      .yield_self { |scale|
        (scale & notes).size > 0 ? tone_scales + [scale] : tone_scales
      }
    }.yield_self { |scales_for_tone|
      scales + scales_for_tone
    }
  }
  .yield_self { |scales| ScaleSet.new(*scales, searched_notes: notes) } # and convert to a set

end

#known_scalesObject



59
60
61
# File 'lib/coltrane/theory/classic_scales.rb', line 59

def known_scales
  SCALES.keys + ['Major', 'Natural Minor']
end

#major(note = 'C') ⇒ Object Also known as: diatonic

Factories for the diatonic scale



46
47
48
# File 'lib/coltrane/theory/classic_scales.rb', line 46

def major(note = 'C')
  DiatonicScale.new(note)
end

#minor(note = 'A') ⇒ Object Also known as: natural_minor



50
51
52
# File 'lib/coltrane/theory/classic_scales.rb', line 50

def minor(note = 'A')
  DiatonicScale.new(note, major: false)
end

#standard_scalesObject

List of scales appropriate for search



64
65
66
# File 'lib/coltrane/theory/classic_scales.rb', line 64

def standard_scales
  known_scales - ['Chromatic']
end