Class: Musa::Scales::ScaleKind
- Inherits:
-
Object
- Object
- Musa::Scales::ScaleKind
- Defined in:
- lib/musa-dsl/music/scales.rb
Direct Known Subclasses
ChromaticScaleKind, MajorScaleKind, MinorHarmonicScaleKind, MinorNaturalScaleKind
Instance Attribute Summary collapse
-
#tuning ⇒ Object
readonly
Returns the value of attribute tuning.
Class Method Summary collapse
-
.chromatic? ⇒ Boolean
abstract
Wether the scales is a full scale (with all the notes in the ScaleSystem), sorted and to be considered canonical.
- .grade_of_function(symbol) ⇒ Object
-
.grades ⇒ Integer
abstract
Number of grades inside of a octave of the scale.
- .grades_functions ⇒ Object
-
.id ⇒ Symbol
abstract
The id of the ScaleKind as a symbol.
-
.pitches ⇒ Array
abstract
The pitches array of the ScaleKind as [ { functions: [ <symbol>, …], pitch: <Number> }, … ].
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](root_pitch) ⇒ Object
- #absolut ⇒ Object
-
#chromatic? ⇒ Boolean
abstract
Wether the scales is a full scale (with all the notes in the ScaleSystem), sorted and to be considered canonical.
- #default_root ⇒ Object
-
#grades ⇒ Integer
abstract
Number of grades inside of a octave of the scale.
-
#id ⇒ Symbol
abstract
The id of the ScaleKind as a symbol.
-
#initialize(tuning) ⇒ ScaleKind
constructor
A new instance of ScaleKind.
- #inspect ⇒ Object (also: #to_s)
-
#pitches ⇒ Array
abstract
The pitches array of the ScaleKind as [ { functions: [ <symbol>, …], pitch: <Number> }, … ].
Constructor Details
#initialize(tuning) ⇒ ScaleKind
Returns a new instance of ScaleKind.
185 186 187 188 |
# File 'lib/musa-dsl/music/scales.rb', line 185 def initialize(tuning) @tuning = tuning @scales = {} end |
Instance Attribute Details
#tuning ⇒ Object (readonly)
Returns the value of attribute tuning.
190 191 192 |
# File 'lib/musa-dsl/music/scales.rb', line 190 def tuning @tuning end |
Class Method Details
.chromatic? ⇒ Boolean
Subclass is expected to implement chromatic?. Only one of the subclasses should return true.
Returns wether the scales is a full scale (with all the notes in the ScaleSystem), sorted and to be considered canonical. I.e. a chromatic 12 semitones uprising serie in a 12 tone tempered ScaleSystem.
232 233 234 |
# File 'lib/musa-dsl/music/scales.rb', line 232 def self.chromatic? false end |
.grade_of_function(symbol) ⇒ Object
243 244 245 246 |
# File 'lib/musa-dsl/music/scales.rb', line 243 def self.grade_of_function(symbol) create_grade_functions_index unless @grade_names_index @grade_names_index[symbol] end |
.grades ⇒ Integer
Subclass is expected to implement grades when the ScaleKind is defining more pitches than notes by octave has the scale. This can happen when there are pitches defined on upper octaves (i.e., to define XII grade, as a octave + fifth)
Returns Number of grades inside of a octave of the scale.
239 240 241 |
# File 'lib/musa-dsl/music/scales.rb', line 239 def self.grades pitches.length end |
.grades_functions ⇒ Object
248 249 250 251 |
# File 'lib/musa-dsl/music/scales.rb', line 248 def self.grades_functions create_grade_functions_index unless @grade_names_index @grade_names_index.keys end |
.id ⇒ Symbol
Subclass is expected to implement id
Returns the id of the ScaleKind as a symbol.
218 219 220 |
# File 'lib/musa-dsl/music/scales.rb', line 218 def self.id raise 'Method not implemented. Should be implemented in subclass.' end |
.pitches ⇒ Array
Subclass is expected to implement pitches
Returns the pitches array of the ScaleKind as [ { functions: [ <symbol>, …], pitch: <Number> }, … ].
225 226 227 |
# File 'lib/musa-dsl/music/scales.rb', line 225 def self.pitches raise 'Method not implemented. Should be implemented in subclass.' end |
Instance Method Details
#==(other) ⇒ Object
205 206 207 |
# File 'lib/musa-dsl/music/scales.rb', line 205 def ==(other) self.class == other.class && @tuning == other.tuning end |
#[](root_pitch) ⇒ Object
192 193 194 195 |
# File 'lib/musa-dsl/music/scales.rb', line 192 def [](root_pitch) @scales[root_pitch] = Scale.new(self, root_pitch: root_pitch) unless @scales.key?(root_pitch) @scales[root_pitch] end |
#absolut ⇒ Object
201 202 203 |
# File 'lib/musa-dsl/music/scales.rb', line 201 def absolut self[0] end |
#chromatic? ⇒ Boolean
Subclass is expected to implement chromatic?. Only one of the subclasses should return true.
Returns wether the scales is a full scale (with all the notes in the ScaleSystem), sorted and to be considered canonical. I.e. a chromatic 12 semitones uprising serie in a 12 tone tempered ScaleSystem.
232 233 234 |
# File 'lib/musa-dsl/music/scales.rb', line 232 def self.chromatic? false end |
#default_root ⇒ Object
197 198 199 |
# File 'lib/musa-dsl/music/scales.rb', line 197 def default_root self[60] end |
#grades ⇒ Integer
Subclass is expected to implement grades when the ScaleKind is defining more pitches than notes by octave has the scale. This can happen when there are pitches defined on upper octaves (i.e., to define XII grade, as a octave + fifth)
Returns Number of grades inside of a octave of the scale.
239 240 241 |
# File 'lib/musa-dsl/music/scales.rb', line 239 def self.grades pitches.length end |
#id ⇒ Symbol
Subclass is expected to implement id
Returns the id of the ScaleKind as a symbol.
218 219 220 |
# File 'lib/musa-dsl/music/scales.rb', line 218 def self.id raise 'Method not implemented. Should be implemented in subclass.' end |
#inspect ⇒ Object Also known as: to_s
209 210 211 |
# File 'lib/musa-dsl/music/scales.rb', line 209 def inspect "<#{self.class.name}: tuning = #{@tuning}>" end |
#pitches ⇒ Array
Subclass is expected to implement pitches
Returns the pitches array of the ScaleKind as [ { functions: [ <symbol>, …], pitch: <Number> }, … ].
225 226 227 |
# File 'lib/musa-dsl/music/scales.rb', line 225 def self.pitches raise 'Method not implemented. Should be implemented in subclass.' end |