Class: Musa::Scales::ScaleSystem
- Inherits:
-
Object
- Object
- Musa::Scales::ScaleSystem
- Defined in:
- lib/musa-dsl/music/scales.rb
Direct Known Subclasses
Class Method Summary collapse
- .[](a_frequency) ⇒ Object
- .chromatic_class ⇒ Object
-
.default_a_frequency ⇒ Number
abstract
The frequency A by default.
- .default_tuning ⇒ Object
-
.frequency_of_pitch(pitch, root_pitch, a_frequency) ⇒ Number
abstract
The frequency of the fundamental tone of the pitch.
-
.id ⇒ Symbol
abstract
The id of the ScaleSystem as a symbol.
-
.intervals ⇒ Hash
abstract
The intervals of the ScaleSystem as { name: semitones#, … }.
-
.notes_in_octave ⇒ Integer
abstract
The number of notes in one octave in the ScaleSystem.
- .offset_of_interval(name) ⇒ Object
-
.part_of_tone_size ⇒ Integer
abstract
The size inside the ScaleSystem of the smaller part of a tone; used for calculate sharp and flat notes.
- .register(scale_kind_class) ⇒ Object
- .scale_kind_class(id) ⇒ Object
- .scale_kind_class?(id) ⇒ Boolean
- .scale_kind_classes ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#default_a_frequency ⇒ Number
abstract
The frequency A by default.
-
#frequency_of_pitch ⇒ Number
abstract
The frequency of the fundamental tone of the pitch.
-
#id ⇒ Symbol
abstract
The id of the ScaleSystem as a symbol.
-
#intervals ⇒ Hash
abstract
The intervals of the ScaleSystem as { name: semitones#, … }.
-
#notes_in_octave ⇒ Integer
abstract
The number of notes in one octave in the ScaleSystem.
-
#part_of_tone_size ⇒ Integer
abstract
The size inside the ScaleSystem of the smaller part of a tone; used for calculate sharp and flat notes.
Class Method Details
.[](a_frequency) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/musa-dsl/music/scales.rb', line 83 def self.[](a_frequency) a_frequency = a_frequency.to_f @a_tunings ||= {} @a_tunings[a_frequency] = ScaleSystemTuning.new self, a_frequency unless @a_tunings.key?(a_frequency) @a_tunings[a_frequency] end |
.chromatic_class ⇒ Object
123 124 125 126 127 |
# File 'lib/musa-dsl/music/scales.rb', line 123 def self.chromatic_class raise "Chromatic scale kind class for [#{self.id}] scale system undefined" if @chromatic_scale_kind_class.nil? @chromatic_scale_kind_class end |
.default_a_frequency ⇒ Number
Subclass can implement default_a_frequency. If subclass doesn’t implement default_a_frequency 440.0 Hz is assumed.
Returns the frequency A by default.
79 80 81 |
# File 'lib/musa-dsl/music/scales.rb', line 79 def self.default_a_frequency 440.0 end |
.default_tuning ⇒ Object
96 97 98 |
# File 'lib/musa-dsl/music/scales.rb', line 96 def self.default_tuning self[default_a_frequency] end |
.frequency_of_pitch(pitch, root_pitch, a_frequency) ⇒ Number
Subclass is expected to implement frequency_of_pitch
Returns the frequency of the fundamental tone of the pitch.
71 72 73 |
# File 'lib/musa-dsl/music/scales.rb', line 71 def self.frequency_of_pitch(pitch, root_pitch, a_frequency) raise 'Method not implemented. Should be implemented in subclass.' end |
.id ⇒ Symbol
Subclass is expected to implement names
Returns the id of the ScaleSystem as a symbol.
33 34 35 |
# File 'lib/musa-dsl/music/scales.rb', line 33 def self.id raise 'Method not implemented. Should be implemented in subclass.' end |
.intervals ⇒ Hash
Subclass is expected to implement intervals
Returns the intervals of the ScaleSystem as { name: semitones#, … }.
57 58 59 60 61 62 |
# File 'lib/musa-dsl/music/scales.rb', line 57 def self.intervals # TODO: implementar intérvalos sinónimos (p.ej, m3 = A2) # TODO: implementar identificación de intérvalos, teniendo en cuenta no sólo los semitonos sino los grados de separación # TODO: implementar inversión de intérvalos raise 'Method not implemented. Should be implemented in subclass.' end |
.notes_in_octave ⇒ Integer
Subclass is expected to implement notes_in_octave
Returns the number of notes in one octave in the ScaleSystem.
41 42 43 |
# File 'lib/musa-dsl/music/scales.rb', line 41 def self.notes_in_octave raise 'Method not implemented. Should be implemented in subclass.' end |
.offset_of_interval(name) ⇒ Object
92 93 94 |
# File 'lib/musa-dsl/music/scales.rb', line 92 def self.offset_of_interval(name) intervals[name] end |
.part_of_tone_size ⇒ Integer
Subclass is expected to implement part_of_tone_size
Returns the size inside the ScaleSystem of the smaller part of a tone; used for calculate sharp and flat notes.
49 50 51 |
# File 'lib/musa-dsl/music/scales.rb', line 49 def self.part_of_tone_size raise 'Method not implemented. Should be implemented in subclass.' end |
.register(scale_kind_class) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/musa-dsl/music/scales.rb', line 100 def self.register(scale_kind_class) @scale_kind_classes ||= {} @scale_kind_classes[scale_kind_class.id] = scale_kind_class if scale_kind_class.chromatic? @chromatic_scale_kind_class = scale_kind_class end self end |
.scale_kind_class(id) ⇒ Object
109 110 111 112 113 |
# File 'lib/musa-dsl/music/scales.rb', line 109 def self.scale_kind_class(id) raise KeyError, "Scale kind class [#{id}] not found in scale system [#{self.id}]" unless @scale_kind_classes.key? id @scale_kind_classes[id] end |
.scale_kind_class?(id) ⇒ Boolean
115 116 117 |
# File 'lib/musa-dsl/music/scales.rb', line 115 def self.scale_kind_class?(id) @scale_kind_classes.key? id end |
.scale_kind_classes ⇒ Object
119 120 121 |
# File 'lib/musa-dsl/music/scales.rb', line 119 def self.scale_kind_classes @scale_kind_classes end |
Instance Method Details
#==(other) ⇒ Object
129 130 131 |
# File 'lib/musa-dsl/music/scales.rb', line 129 def ==(other) self.class == other.class end |
#default_a_frequency ⇒ Number
Subclass can implement default_a_frequency. If subclass doesn’t implement default_a_frequency 440.0 Hz is assumed.
Returns the frequency A by default.
79 80 81 |
# File 'lib/musa-dsl/music/scales.rb', line 79 def self.default_a_frequency 440.0 end |
#frequency_of_pitch ⇒ Number
Subclass is expected to implement frequency_of_pitch
Returns the frequency of the fundamental tone of the pitch.
71 72 73 |
# File 'lib/musa-dsl/music/scales.rb', line 71 def self.frequency_of_pitch(pitch, root_pitch, a_frequency) raise 'Method not implemented. Should be implemented in subclass.' end |
#id ⇒ Symbol
Subclass is expected to implement names
Returns the id of the ScaleSystem as a symbol.
33 34 35 |
# File 'lib/musa-dsl/music/scales.rb', line 33 def self.id raise 'Method not implemented. Should be implemented in subclass.' end |
#intervals ⇒ Hash
Subclass is expected to implement intervals
Returns the intervals of the ScaleSystem as { name: semitones#, … }.
57 58 59 60 61 62 |
# File 'lib/musa-dsl/music/scales.rb', line 57 def self.intervals # TODO: implementar intérvalos sinónimos (p.ej, m3 = A2) # TODO: implementar identificación de intérvalos, teniendo en cuenta no sólo los semitonos sino los grados de separación # TODO: implementar inversión de intérvalos raise 'Method not implemented. Should be implemented in subclass.' end |
#notes_in_octave ⇒ Integer
Subclass is expected to implement notes_in_octave
Returns the number of notes in one octave in the ScaleSystem.
41 42 43 |
# File 'lib/musa-dsl/music/scales.rb', line 41 def self.notes_in_octave raise 'Method not implemented. Should be implemented in subclass.' end |
#part_of_tone_size ⇒ Integer
Subclass is expected to implement part_of_tone_size
Returns the size inside the ScaleSystem of the smaller part of a tone; used for calculate sharp and flat notes.
49 50 51 |
# File 'lib/musa-dsl/music/scales.rb', line 49 def self.part_of_tone_size raise 'Method not implemented. Should be implemented in subclass.' end |