Module: Coltrane::ClassicScales
- Included in:
- Scale
- Defined in:
- lib/coltrane/classic_scales.rb
Overview
This module deals with well known scales on music
Constant Summary collapse
- SCALES =
{ 'Major' => [2, 2, 1, 2, 2, 2, 1], 'Pentatonic Major' => [2, 2, 3, 2, 3], 'Blues Major' => [2, 1, 1, 3, 2, 3], 'Natural Minor' => [2, 1, 2, 2, 1, 2, 2], '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
- MODES =
{ 'Major' => %w[Ionian Dorian Phrygian Lydian Mixolydian Aeolian Locrian] }.freeze
Instance Method Summary collapse
- #fetch(name, tone = nil) ⇒ Object
- #from_key(key) ⇒ Object
- #having_chords(*chords) ⇒ Object (also: #having_chord)
-
#having_notes(notes) ⇒ Object
Will output a OpenStruct like the following: { scales: [array of scales] results: { scale_name: { note_number => found_notes } } }.
- #known_scales ⇒ Object
-
#standard_scales ⇒ Object
All but the chromatic.
Instance Method Details
#fetch(name, tone = nil) ⇒ Object
55 56 57 |
# File 'lib/coltrane/classic_scales.rb', line 55 def fetch(name, tone = nil) Coltrane::Scale.public_send(name, tone) end |
#from_key(key) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/coltrane/classic_scales.rb', line 59 def from_key(key) key_regex = /([A-G][#b]?)([mM]?)/ _, note, s = *key.match(key_regex) scale = s == 'm' ? :minor : :major Scale.public_send(scale, note) end |
#having_chords(*chords) ⇒ Object Also known as: having_chord
91 92 93 94 95 96 97 |
# File 'lib/coltrane/classic_scales.rb', line 91 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
Will output a OpenStruct like the following: {
scales: [array of scales]
results: {
scale_name: {
note_number => found_notes
}
}
}
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/coltrane/classic_scales.rb', line 76 def having_notes(notes) format = { scales: [], results: {} } OpenStruct.new( standard_scales.each_with_object(format) do |(name, intervals), output| Note.all.each.map do |tone| scale = new(*intervals, tone: tone, name: scale) output[:results][name] ||= {} next if output[:results][name].key?(tone.number) output[:scales] << scale if scale.include?(notes) output[:results][name][tone.number] = scale.notes & notes end end ) end |
#known_scales ⇒ Object
46 47 48 |
# File 'lib/coltrane/classic_scales.rb', line 46 def known_scales SCALES.keys end |
#standard_scales ⇒ Object
All but the chromatic
51 52 53 |
# File 'lib/coltrane/classic_scales.rb', line 51 def standard_scales SCALES.reject { |k,v| k == 'Chromatic' } end |