module Coltrane::Theory::ClassicScales

This module deals with well known scales on music

Constants

SCALES

Public Instance Methods

diatonic(note = 'C')
Alias for: major
fetch(name, tone = nil) click to toggle source
# File lib/coltrane/theory/classic_scales.rb, line 56
def fetch(name, tone = nil)
  public_send(name.underscore, tone)
end
having_chord(*chords)
Alias for: having_chords
having_chords(*chords) click to toggle source
# 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
Also aliased as: having_chord
having_notes(notes) click to toggle source

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

# 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_scales() click to toggle source
# File lib/coltrane/theory/classic_scales.rb, line 47
def known_scales
  ['Major', 'Natural Minor'] + SCALES.keys
end
major(note = 'C') click to toggle source

Factories for the diatonic scale

# File lib/coltrane/theory/classic_scales.rb, line 34
def major(note = 'C')
  DiatonicScale.new(note)
end
Also aliased as: diatonic
minor(note = 'A') click to toggle source
# File lib/coltrane/theory/classic_scales.rb, line 38
def minor(note = 'A')
  DiatonicScale.new(note, major: false)
end
Also aliased as: natural_minor
natural_minor(note = 'A')
Alias for: minor
standard_scales() click to toggle source

List of scales appropriate for search

# File lib/coltrane/theory/classic_scales.rb, line 52
def standard_scales
  known_scales - ['Chromatic']
end