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



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_classObject



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_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



81
82
83
# File 'lib/musa-dsl/music/scales.rb', line 81

def self.default_a_frequency
  440.0
end

.default_tuningObject



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

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



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

.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



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

.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#, … }



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_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



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_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



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

Raises:

  • (KeyError)


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

Returns:

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



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_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



81
82
83
# File 'lib/musa-dsl/music/scales.rb', line 81

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



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

#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



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

#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#, … }



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_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



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_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



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