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.

Examples:

Check ornament options

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

Yields:

  • (value)

    block to call for each value



298
299
300
301
302
303
304
305
306
# File 'lib/musa-dsl/transcription/transcription.rb', line 298

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.



270
271
272
273
274
275
276
277
278
279
# File 'lib/musa-dsl/transcription/transcription.rb', line 270

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