Class: Musa::Scales::ScaleKind

Inherits:
Object
  • Object
show all
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.



232
233
234
# File 'lib/musa-dsl/music/scales.rb', line 232

def self.chromatic?
  false
end

.grade_of_function(symbol) ⇒ Object



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

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



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

def self.grades
  pitches.length
end

.grades_functionsObject



248
249
250
251
# File 'lib/musa-dsl/music/scales.rb', line 248

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



218
219
220
# File 'lib/musa-dsl/music/scales.rb', line 218

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



225
226
227
# File 'lib/musa-dsl/music/scales.rb', line 225

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

Instance Method Details

#==(other) ⇒ Object



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

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



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

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.



232
233
234
# File 'lib/musa-dsl/music/scales.rb', line 232

def self.chromatic?
  false
end

#default_rootObject



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

def default_root
  self[60]
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



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

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



218
219
220
# File 'lib/musa-dsl/music/scales.rb', line 218

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

#inspectObject Also known as: to_s



209
210
211
# File 'lib/musa-dsl/music/scales.rb', line 209

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



225
226
227
# File 'lib/musa-dsl/music/scales.rb', line 225

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