Class: Musa::Scales::ScaleSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/musa-dsl/music/scales.rb

Direct Known Subclasses

TwelveSemitonesScaleSystem

Class Method Summary collapse

Instance Method Summary collapse

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_classObject



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_frequencyNumber

This method is abstract.

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.

Returns:

  • (Number)

    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_tuningObject



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

This method is abstract.

Subclass is expected to implement frequency_of_pitch

Returns the frequency of the fundamental tone of the pitch.

Parameters:

  • pitch (Number)

    The pitch (MIDI note numbers based) of the note to get the fundamental frequency

  • root_pitch (Number)

    The pitch (MIDI note numbers based) of the root note of the scale (needed for not equally tempered scales)

  • a_frequency (Number)

    The reference frequency of the mid A note

Returns:

  • (Number)

    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

.idSymbol

This method is abstract.

Subclass is expected to implement names

Returns the id of the ScaleSystem as a symbol.

Returns:

  • (Symbol)

    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

.intervalsHash

This method is abstract.

Subclass is expected to implement intervals

Returns the intervals of the ScaleSystem as { name: semitones#, … }.

Returns:

  • (Hash)

    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_octaveInteger

This method is abstract.

Subclass is expected to implement notes_in_octave

Returns the number of notes in one octave in the ScaleSystem.

Returns:

  • (Integer)

    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_sizeInteger

This method is abstract.

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.

Returns:

  • (Integer)

    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

Raises:

  • (KeyError)


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

Returns:

  • (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_classesObject



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_frequencyNumber

This method is abstract.

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.

Returns:

  • (Number)

    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_pitchNumber

This method is abstract.

Subclass is expected to implement frequency_of_pitch

Returns the frequency of the fundamental tone of the pitch.

Parameters:

  • pitch (Number)

    The pitch (MIDI note numbers based) of the note to get the fundamental frequency

  • root_pitch (Number)

    The pitch (MIDI note numbers based) of the root note of the scale (needed for not equally tempered scales)

  • a_frequency (Number)

    The reference frequency of the mid A note

Returns:

  • (Number)

    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

#idSymbol

This method is abstract.

Subclass is expected to implement names

Returns the id of the ScaleSystem as a symbol.

Returns:

  • (Symbol)

    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

#intervalsHash

This method is abstract.

Subclass is expected to implement intervals

Returns the intervals of the ScaleSystem as { name: semitones#, … }.

Returns:

  • (Hash)

    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_octaveInteger

This method is abstract.

Subclass is expected to implement notes_in_octave

Returns the number of notes in one octave in the ScaleSystem.

Returns:

  • (Integer)

    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_sizeInteger

This method is abstract.

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.

Returns:

  • (Integer)

    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