Class: HeadMusic::Rudiment::ScaleType
- Inherits:
-
Object
- Object
- HeadMusic::Rudiment::ScaleType
- Defined in:
- lib/head_music/rudiment/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.
107 108 109 110 111 112 |
# File 'lib/head_music/rudiment/scale_type.rb', line 107 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.
102 103 104 |
# File 'lib/head_music/rudiment/scale_type.rb', line 102 def ascending_intervals @ascending_intervals end |
#descending_intervals ⇒ Object (readonly)
Returns the value of attribute descending_intervals.
102 103 104 |
# File 'lib/head_music/rudiment/scale_type.rb', line 102 def descending_intervals @descending_intervals end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
102 103 104 |
# File 'lib/head_music/rudiment/scale_type.rb', line 102 def name @name end |
#parent_name ⇒ Object (readonly)
Returns the value of attribute parent_name.
102 103 104 |
# File 'lib/head_music/rudiment/scale_type.rb', line 102 def parent_name @parent_name end |
Class Method Details
._chromatic_scales ⇒ Object
53 54 55 |
# File 'lib/head_music/rudiment/scale_type.rb', line 53 def self._chromatic_scales {chromatic: {ascending: CHROMATIC}} end |
._exotic_scales ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/head_music/rudiment/scale_type.rb', line 67 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
46 47 48 49 50 51 |
# File 'lib/head_music/rudiment/scale_type.rb', line 46 def self._minor_scales { harmonic_minor: {ascending: HARMONIC_MINOR}, melodic_minor: {ascending: MELODIC_MINOR_ASCENDING, descending: VI.reverse} } end |
._modes ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/head_music/rudiment/scale_type.rb', line 36 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
57 58 59 60 61 62 63 64 65 |
# File 'lib/head_music/rudiment/scale_type.rb', line 57 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
98 99 100 |
# File 'lib/head_music/rudiment/scale_type.rb', line 98 def self.default get(:major) end |
.get(name) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/head_music/rudiment/scale_type.rb', line 91 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
114 115 116 |
# File 'lib/head_music/rudiment/scale_type.rb', line 114 def ==(other) state == other.state end |
#chromatic? ⇒ Boolean
138 139 140 |
# File 'lib/head_music/rudiment/scale_type.rb', line 138 def chromatic? intervals.length == 12 end |
#diatonic? ⇒ Boolean
126 127 128 |
# File 'lib/head_music/rudiment/scale_type.rb', line 126 def diatonic? intervals.length == 7 end |
#parent ⇒ Object
122 123 124 |
# File 'lib/head_music/rudiment/scale_type.rb', line 122 def parent @parent ||= self.class.get(parent_name) if parent_name end |
#pentatonic? ⇒ Boolean
134 135 136 |
# File 'lib/head_music/rudiment/scale_type.rb', line 134 def pentatonic? intervals.length == 5 end |
#state ⇒ Object
118 119 120 |
# File 'lib/head_music/rudiment/scale_type.rb', line 118 def state [ascending_intervals, descending_intervals] end |
#whole_tone? ⇒ Boolean
130 131 132 |
# File 'lib/head_music/rudiment/scale_type.rb', line 130 def whole_tone? intervals.length == 6 && intervals.uniq == [2] end |