Class: Musa::Transcription::FeatureTranscriptor

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

Overview

Base class for feature transcriptors.

Provides common functionality for processing specific musical features in GDV events. Subclasses implement transcript method to handle their specific feature (ornament, articulation, etc.).

Contract

Transcriptor implementations should:

  1. Extract their specific feature from GDV hash
  2. Process/transform the event based on that feature
  3. Return modified event(s) or call super if feature not present
  4. Use delete to remove processed feature attributes

Helper Methods

  • check(value, &block): Safely iterate over value or array

Examples:

Implement custom transcriptor

class Accent < FeatureTranscriptor
  def transcript(gdv, base_duration:, tick_duration:)
    if accent = gdv.delete(:accent)
      gdv[:velocity] *= 1.2  # Increase velocity
    end
    super  # Clean up and pass through
  end
end

Instance Method Summary collapse

Instance Method Details

#check(value_or_array) {|value| ... } ⇒ Object

Helper to safely process value or array.

Yields each element if array, or yields single value. Useful for processing feature values that may be single or multiple.

How a feature transcriptor reads an option that may come alone or in a list (a reading: check is called on the transcriptor, from inside it):

check(ornament_value) do |option|
  case option
  when :up then direction = :up
  when :down then direction = :down
  end
end

Parameters:

Yields:

  • (value)

    block to call for each value



307
308
309
310
311
312
313
314
315
# File 'lib/musa-dsl/transcription/transcription.rb', line 307

def check(value_or_array, &block)
  if block_given?
    if value_or_array.is_a?(Array)
      value_or_array.each(&block)
    else
      yield value_or_array
    end
  end
end

#transcript(element, base_duration:, tick_duration:) ⇒ Hash+

Transcribes GDV event for this feature.

Base implementation cleans up empty :modifiers attribute. Subclasses should override to process their specific feature, then call super.

Parameters:

  • element (Hash, Array<Hash>)

    GDV event or array of events

  • base_duration (Rational)

    base duration unit

  • tick_duration (Rational)

    minimum tick duration

Returns:



277
278
279
280
281
282
283
284
285
286
# File 'lib/musa-dsl/transcription/transcription.rb', line 277

def transcript(element, base_duration:, tick_duration:)
  case element
  when Hash
    element.delete :modifiers if element[:modifiers]&.empty?
  when Array
    element.each { |_| _.delete :modifiers if _[:modifiers]&.empty? }
  end

  element
end