Class: HeadMusic::ScaleType
- Inherits:
-
Object
- Object
- HeadMusic::ScaleType
- Defined in:
- lib/head_music/scale_type.rb
Overview
A ScaleType represents a particular scale pattern, such as major, lydian, or minor pentatonic.
Constant Summary collapse
- H =
whole step
1- W =
half step
2- I =
Modal
[W, W, H, W, W, W, H].freeze
- II =
I.rotate
- III =
I.rotate(2)
- IV =
I.rotate(3)
- V =
I.rotate(4)
- VI =
I.rotate(5)
- VII =
I.rotate(6)
- HARMONIC_MINOR =
Tonal
[W, H, W, W, H, 3, H].freeze
- MELODIC_MINOR_ASCENDING =
[W, H, W, W, W, W, H].freeze
- MODE_NAMES =
{ i: %i[ionian major], ii: [:dorian], iii: [:phrygian], iv: [:lydian], v: [:mixolydian], vi: %i[aeolian minor natural_minor], vii: [:locrian] }.freeze
- CHROMATIC =
([H] * 12)
- MINOR_PENTATONIC =
[3, 2, 2, 3, 2].freeze
- SCALE_TYPES =
{}.tap do |scales| scales.merge!(_modes) scales.merge!(_minor_scales) scales.merge!(_chromatic_scales) scales.merge!(_pentatonic_scales) scales.merge!(_exotic_scales) end.freeze
Instance Attribute Summary collapse
-
#ascending_intervals ⇒ Object
(also: #intervals)
readonly
Returns the value of attribute ascending_intervals.
-
#descending_intervals ⇒ Object
readonly
Returns the value of attribute descending_intervals.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent_name ⇒ Object
readonly
Returns the value of attribute parent_name.
Class Method Summary collapse
- ._chromatic_scales ⇒ Object
- ._exotic_scales ⇒ Object
- ._minor_scales ⇒ Object
- ._modes ⇒ Object
- ._pentatonic_scales ⇒ Object
- .default ⇒ Object
- .get(name) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #chromatic? ⇒ Boolean
- #diatonic? ⇒ Boolean
-
#initialize(name, attributes) ⇒ ScaleType
constructor
A new instance of ScaleType.
- #parent ⇒ Object
- #pentatonic? ⇒ Boolean
- #state ⇒ Object
- #whole_tone? ⇒ Boolean
Constructor Details
#initialize(name, attributes) ⇒ ScaleType
Returns a new instance of ScaleType.
104 105 106 107 108 109 |
# File 'lib/head_music/scale_type.rb', line 104 def initialize(name, attributes) @name = name @ascending_intervals = attributes[:ascending] @descending_intervals = attributes[:descending] || ascending_intervals.reverse @parent_name = attributes[:parent_name] end |
Instance Attribute Details
#ascending_intervals ⇒ Object (readonly) Also known as: intervals
Returns the value of attribute ascending_intervals.
99 100 101 |
# File 'lib/head_music/scale_type.rb', line 99 def ascending_intervals @ascending_intervals end |
#descending_intervals ⇒ Object (readonly)
Returns the value of attribute descending_intervals.
99 100 101 |
# File 'lib/head_music/scale_type.rb', line 99 def descending_intervals @descending_intervals end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
99 100 101 |
# File 'lib/head_music/scale_type.rb', line 99 def name @name end |
#parent_name ⇒ Object (readonly)
Returns the value of attribute parent_name.
99 100 101 |
# File 'lib/head_music/scale_type.rb', line 99 def parent_name @parent_name end |
Class Method Details
._chromatic_scales ⇒ Object
50 51 52 |
# File 'lib/head_music/scale_type.rb', line 50 def self._chromatic_scales {chromatic: {ascending: CHROMATIC}} end |
._exotic_scales ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/head_music/scale_type.rb', line 64 def self._exotic_scales # 'octatonic' is also called the 'whole-half diminished scale' { octatonic: {ascending: [W, H, W, H, W, H, W, H]}, whole_tone: {ascending: [W, W, W, W, W, W]} } end |
._minor_scales ⇒ Object
43 44 45 46 47 48 |
# File 'lib/head_music/scale_type.rb', line 43 def self._minor_scales { harmonic_minor: {ascending: HARMONIC_MINOR}, melodic_minor: {ascending: MELODIC_MINOR_ASCENDING, descending: VI.reverse} } end |
._modes ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/head_music/scale_type.rb', line 33 def self._modes {}.tap do |modes| MODE_NAMES.each do |roman_numeral, aliases| intervals = {ascending: const_get(roman_numeral.upcase)} modes[roman_numeral] = intervals aliases.each { |name| modes[name] = intervals } end end end |
._pentatonic_scales ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/head_music/scale_type.rb', line 54 def self._pentatonic_scales { minor_pentatonic: {ascending: MINOR_PENTATONIC, parent_name: :minor}, major_pentatonic: {ascending: MINOR_PENTATONIC.rotate, parent_name: :major}, egyptian_pentatonic: {ascending: MINOR_PENTATONIC.rotate(2), parent_name: :minor}, blues_minor_pentatonic: {ascending: MINOR_PENTATONIC.rotate(3), parent_name: :minor}, blues_major_pentatonic: {ascending: MINOR_PENTATONIC.rotate(4), parent_name: :major} } end |
.default ⇒ Object
95 96 97 |
# File 'lib/head_music/scale_type.rb', line 95 def self.default get(:major) end |
.get(name) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/head_music/scale_type.rb', line 88 def self.get(name) @scale_types ||= {} identifier = HeadMusic::Utilities::HashKey.for(name) attributes = SCALE_TYPES[identifier] @scale_types[identifier] ||= new(identifier, attributes) end |
Instance Method Details
#==(other) ⇒ Object
111 112 113 |
# File 'lib/head_music/scale_type.rb', line 111 def ==(other) state == other.state end |
#chromatic? ⇒ Boolean
135 136 137 |
# File 'lib/head_music/scale_type.rb', line 135 def chromatic? intervals.length == 12 end |
#diatonic? ⇒ Boolean
123 124 125 |
# File 'lib/head_music/scale_type.rb', line 123 def diatonic? intervals.length == 7 end |
#parent ⇒ Object
119 120 121 |
# File 'lib/head_music/scale_type.rb', line 119 def parent @parent ||= self.class.get(parent_name) if parent_name end |
#pentatonic? ⇒ Boolean
131 132 133 |
# File 'lib/head_music/scale_type.rb', line 131 def pentatonic? intervals.length == 5 end |
#state ⇒ Object
115 116 117 |
# File 'lib/head_music/scale_type.rb', line 115 def state [ascending_intervals, descending_intervals] end |
#whole_tone? ⇒ Boolean
127 128 129 |
# File 'lib/head_music/scale_type.rb', line 127 def whole_tone? intervals.length == 6 && intervals.uniq == [2] end |