Class: Musa::Transcription::FeatureTranscriptor
- 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:
- Extract their specific feature from GDV hash
- Process/transform the event based on that feature
- Return modified event(s) or call
superif feature not present - Use
deleteto remove processed feature attributes
Helper Methods
check(value, &block): Safely iterate over value or array
Direct Known Subclasses
Musa::Transcriptors::FromGDV::Base, Musa::Transcriptors::FromGDV::ToMIDI::Appogiatura, Musa::Transcriptors::FromGDV::ToMIDI::Mordent, Musa::Transcriptors::FromGDV::ToMIDI::Staccato, Musa::Transcriptors::FromGDV::ToMIDI::Trill, Musa::Transcriptors::FromGDV::ToMIDI::Turn, Musa::Transcriptors::FromGDV::ToMusicXML::Appogiatura
Instance Method Summary collapse
-
#check(value_or_array) {|value| ... } ⇒ Object
Helper to safely process value or array.
-
#transcript(element, base_duration:, tick_duration:) ⇒ Hash+
Transcribes GDV event for this feature.
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
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.
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 |