Class: Musa::Scales::ScaleKind

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#tuningObject (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

This method is abstract.

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.

Returns:

  • (Boolean)

    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.



228
229
230
# File 'lib/musa-dsl/music/scales.rb', line 228

def self.chromatic?
  false
end

.grade_of_function(symbol) ⇒ Object



239
240
241
242
# File 'lib/musa-dsl/music/scales.rb', line 239

def self.grade_of_function(symbol)
  create_grade_functions_index unless @grade_names_index
  @grade_names_index[symbol]
end

.gradesInteger

This method is abstract.

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.

Returns:

  • (Integer)

    Number of grades inside of a octave of the scale



235
236
237
# File 'lib/musa-dsl/music/scales.rb', line 235

def self.grades
  pitches.length
end

.grades_functionsObject



244
245
246
247
# File 'lib/musa-dsl/music/scales.rb', line 244

def self.grades_functions
  create_grade_functions_index unless @grade_names_index
  @grade_names_index.keys
end

.idSymbol

This method is abstract.

Subclass is expected to implement id

Returns the id of the ScaleKind as a symbol.

Returns:

  • (Symbol)

    the id of the ScaleKind as a symbol



214
215
216
# File 'lib/musa-dsl/music/scales.rb', line 214

def self.id
  raise 'Method not implemented. Should be implemented in subclass.'
end

.pitchesArray

This method is abstract.

Subclass is expected to implement pitches

Returns the pitches array of the ScaleKind as [ { functions: [ <symbol>, …], pitch: <Number> }, … ].

Returns:

  • (Array)

    the pitches array of the ScaleKind as [ { functions: [ <symbol>, …], pitch: <Number> }, … ]



221
222
223
# File 'lib/musa-dsl/music/scales.rb', line 221

def self.pitches
  raise 'Method not implemented. Should be implemented in subclass.'
end

Instance Method Details

#==(other) ⇒ Object



201
202
203
# File 'lib/musa-dsl/music/scales.rb', line 201

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

#absolutObject



197
198
199
# File 'lib/musa-dsl/music/scales.rb', line 197

def absolut
  self[0]
end

#chromatic?Boolean

This method is abstract.

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.

Returns:

  • (Boolean)

    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.



228
229
230
# File 'lib/musa-dsl/music/scales.rb', line 228

def self.chromatic?
  false
end

#gradesInteger

This method is abstract.

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.

Returns:

  • (Integer)

    Number of grades inside of a octave of the scale



235
236
237
# File 'lib/musa-dsl/music/scales.rb', line 235

def self.grades
  pitches.length
end

#idSymbol

This method is abstract.

Subclass is expected to implement id

Returns the id of the ScaleKind as a symbol.

Returns:

  • (Symbol)

    the id of the ScaleKind as a symbol



214
215
216
# File 'lib/musa-dsl/music/scales.rb', line 214

def self.id
  raise 'Method not implemented. Should be implemented in subclass.'
end

#inspectObject Also known as: to_s



205
206
207
# File 'lib/musa-dsl/music/scales.rb', line 205

def inspect
  "<#{self.class.name}: tuning = #{@tuning}>"
end

#pitchesArray

This method is abstract.

Subclass is expected to implement pitches

Returns the pitches array of the ScaleKind as [ { functions: [ <symbol>, …], pitch: <Number> }, … ].

Returns:

  • (Array)

    the pitches array of the ScaleKind as [ { functions: [ <symbol>, …], pitch: <Number> }, … ]



221
222
223
# File 'lib/musa-dsl/music/scales.rb', line 221

def self.pitches
  raise 'Method not implemented. Should be implemented in subclass.'
end