Class: JazzModel::Scale

Inherits:
Base
  • Object
show all
Includes:
KeyContext, ModeContext
Defined in:
lib/jazz_model/scale.rb

Overview

A scale is an ordered collection of tones.

Creating a Scale

Scale objects should be created by indexing the Scale class directly:

Scale['Major']

An alternative method of resolving a chord is to use the resolve method, though this is likely to become deprecated in the future when chord progression support/representation is added:

Scale.resolve(name)

Associations

  • modes - Associated modes.

  • main_mode - Associated mode with a mode index of 1 (first mode). This sometimes

    the only defined mode such as for the whole tone scale.
    
  • tones - A collection of ScaleTones.

  • notes - An array of notes (delegated through tones)

  • chords - A collection of associated chords with the first mode of this scale.

Modes

Each scale can have one or many modes, which really define the relationship to chords. Modes are accessible like so (all methods are equal):

Scale['Major']['Dorian']
Scale['Major'][2]
Scale['Major'].modes['Dorian']
Scale['Major'].modes[2]

Examples

Listing Tones in Scales

Scale['Major'].notes
# => ["C", "D", "E", "F", "G", "A", "B"]

Scale['Major'].in_key_of('Eb').notes
Scale['Eb Major'].notes  # Same as above
# => ["Eb", "F", "G", "Ab", "Bb", "C", "D"]

Correctly Interpets Theoretical Keys (not just pitches)

Scale['Gb Major'].notes
# => ["Gb", "Ab", "Bb", "Cb", "Db", "Eb", "F"]
# Note the use of Cb which is theoretically correct over enharmonic B.

Also correctly interpet tones off of enharmonic base keys:

Scale['Gb Major'].notes
# => ["Gb", "Ab", "Bb", "Cb", "Db", "Eb", "F"]
Scale['F# Major'].notes
# => ["F#", "G#", "A#", "B", "C#", "D#", "E#"]

Listing Tones within the context of a mode

Scale['Major'].modes['Dorian']
Scale['Major']['Dorian']  # Same as above
# => ["D", "E", "F", "G", "A", "B", "C"]

Scale['Melodic Minor'].modes['Super Locrian'].notes
# => ["B", "C", "D", "Eb", "F", "G", "A"]  # aka. Altered Scale or Dim. Whole Tone

Listing Related Chords

Scale['Major'].chords.symbols
# => ['maj7', 'maj6', '6/9']
Scale['Major']['Dorian'].chords.symbols
# => ['min7', 'min6']

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModeContext

included

Methods included from KeyContext

included

Methods inherited from Base

load_definitions

Class Method Details

.resolve(symbol) ⇒ Object Also known as: []



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/jazz_model/scale.rb', line 86

def resolve(symbol)
	in_key = nil
			
	return nil if symbol.nil?
	symbol = symbol.dup
			
	Key.all.each do |k|
		if symbol.starts_with?(k.name)
			in_key = k
			symbol.gsub!(/^#{k.name}/, '').strip!
			break
		end
	end
			
	scale = Scale.find_by_name(symbol)
			
	# Perhaps the matched key was really part of the name of the chord, try that:
	if scale.nil? && !in_key.nil?
		symbol = in_key.name + symbol
		scale = Scale.all.detect {|s| s.name == symbol}
	end
			
	# If still not found, must be invalid:
	return nil if scale.nil?
			
	scale.key = in_key
	scale
end

Instance Method Details

#[](name) ⇒ Object



117
118
119
# File 'lib/jazz_model/scale.rb', line 117

def [](name)
	name.is_a?(String) ? self.modes.find_by_name(name) : self.modes.find_by_mode(name)
end

#main_modeObject



121
122
123
# File 'lib/jazz_model/scale.rb', line 121

def main_mode
	self[1]
end

#symmetric?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/jazz_model/scale.rb', line 125

def symmetric?
	!self.symmetry_index.nil?
end

#to_xml(options = {}) ⇒ Object



130
131
132
# File 'lib/jazz_model/scale.rb', line 130

def to_xml(options = {})
	super(options.merge(:skip_types => true))
end