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
85 86 87 88 89 90 91 92 |
# File 'lib/musa-dsl/music/scales.rb', line 85 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
125 126 127 128 129 |
# File 'lib/musa-dsl/music/scales.rb', line 125 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.
81 82 83 |
# File 'lib/musa-dsl/music/scales.rb', line 81 def self.default_a_frequency 440.0 end |
.default_tuning ⇒ Object
98 99 100 |
# File 'lib/musa-dsl/music/scales.rb', line 98 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.
73 74 75 |
# File 'lib/musa-dsl/music/scales.rb', line 73 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.
35 36 37 |
# File 'lib/musa-dsl/music/scales.rb', line 35 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#, … }.
59 60 61 62 63 64 |
# File 'lib/musa-dsl/music/scales.rb', line 59 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.
43 44 45 |
# File 'lib/musa-dsl/music/scales.rb', line 43 def self.notes_in_octave raise 'Method not implemented. Should be implemented in subclass.' end |
.offset_of_interval(name) ⇒ Object
94 95 96 |
# File 'lib/musa-dsl/music/scales.rb', line 94 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.
51 52 53 |
# File 'lib/musa-dsl/music/scales.rb', line 51 def self.part_of_tone_size raise 'Method not implemented. Should be implemented in subclass.' end |
.register(scale_kind_class) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/musa-dsl/music/scales.rb', line 102 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
111 112 113 114 115 |
# File 'lib/musa-dsl/music/scales.rb', line 111 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
117 118 119 |
# File 'lib/musa-dsl/music/scales.rb', line 117 def self.scale_kind_class?(id) @scale_kind_classes.key? id end |
.scale_kind_classes ⇒ Object
121 122 123 |
# File 'lib/musa-dsl/music/scales.rb', line 121 def self.scale_kind_classes @scale_kind_classes end |
Instance Method Details
#==(other) ⇒ Object
131 132 133 |
# File 'lib/musa-dsl/music/scales.rb', line 131 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.
81 82 83 |
# File 'lib/musa-dsl/music/scales.rb', line 81 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.
73 74 75 |
# File 'lib/musa-dsl/music/scales.rb', line 73 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.
35 36 37 |
# File 'lib/musa-dsl/music/scales.rb', line 35 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#, … }.
59 60 61 62 63 64 |
# File 'lib/musa-dsl/music/scales.rb', line 59 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.
43 44 45 |
# File 'lib/musa-dsl/music/scales.rb', line 43 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.
51 52 53 |
# File 'lib/musa-dsl/music/scales.rb', line 51 def self.part_of_tone_size raise 'Method not implemented. Should be implemented in subclass.' end |