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

Instance Method Summary collapse

Instance Method Details

#fetch(name, tone = nil) ⇒ Object



56
57
58
# File 'lib/coltrane/theory/classic_scales.rb', line 56

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

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



90
91
92
93
94
95
96
# File 'lib/coltrane/theory/classic_scales.rb', line 90

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



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/coltrane/theory/classic_scales.rb', line 73

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



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

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

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

Factories for the diatonic scale



34
35
36
# File 'lib/coltrane/theory/classic_scales.rb', line 34

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

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



38
39
40
# File 'lib/coltrane/theory/classic_scales.rb', line 38

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

#standard_scalesObject

List of scales appropriate for search



52
53
54
# File 'lib/coltrane/theory/classic_scales.rb', line 52

def standard_scales
  known_scales - ['Chromatic']
end