Class: Musa::Neumas::Decoders::NeumaDecoder
- Inherits:
-
Decoder
- Object
- ProtoDecoder
- DifferentialDecoder
- Decoder
- Musa::Neumas::Decoders::NeumaDecoder
- Defined in:
- lib/musa-dsl/neumas/neuma-gdv-decoder.rb
Overview
GDV neuma decoder for converting neumas to Grade-Duration-Velocity events.
Converts neuma notation (GDVD - differential format) to GDV (absolute format) using scale information. This decoder is the primary way to transform text-based neuma notation into playable musical events.
GDVD vs GDV
- GDVD (differential): Relative changes
+2 _2(up 2 steps, double duration) - GDV (absolute): Absolute values
{grade: 2, duration: 1/2r}ready for playback
Conversion Process
Neuma String
Scale Integration
The decoder uses a scale to interpret grade values:
scale = Musa::Scales::Scales.et12[440.0].major[60]
decoder = NeumaDecoder.new(scale)
# Grade 2 in C major = E (C=0, D=1, E=2)
Appogiatura Handling
Grace notes (appogiatura) are processed recursively:
"(+1_/4)+2_" # Grace note +1 with duration 1/4, main note +2
Both the grace note and main note are converted from GDVD to GDV.
Instance Attribute Summary collapse
-
#base_duration ⇒ Rational
Base duration unit for duration calculations.
-
#scale ⇒ Scale
Scale for interpreting grade values.
Instance Method Summary collapse
-
#apply(gdvd, on:) ⇒ Hash
Applies GDVD to previous state, producing absolute GDV.
-
#initialize(scale, base_duration: nil, transcriptor: nil, base: nil) ⇒ NeumaDecoder
constructor
Creates GDV neuma decoder.
-
#inspect ⇒ String
(also: #to_s)
Returns debug representation.
-
#process(gdvd) ⇒ Hash
Processes GDVD attributes before conversion.
-
#subcontext ⇒ NeumaDecoder
Creates independent subcontext decoder.
Constructor Details
#initialize(scale, base_duration: nil, transcriptor: nil, base: nil) ⇒ NeumaDecoder
Creates GDV neuma decoder.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 95 def initialize(scale, base_duration: nil, transcriptor: nil, base: nil) @base_duration = base_duration @base_duration ||= base[:duration] if base @base_duration ||= Rational(1, 4) base ||= { grade: 0, octave: 0, duration: @base_duration, velocity: 1 } @scale = scale super base, transcriptor: transcriptor end |
Instance Attribute Details
#base_duration ⇒ Rational
Base duration unit for duration calculations.
119 120 121 |
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 119 def base_duration @base_duration end |
#scale ⇒ Scale
Scale for interpreting grade values.
112 113 114 |
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 112 def scale @scale end |
Instance Method Details
#apply(gdvd, on:) ⇒ Hash
Applies GDVD to previous state, producing absolute GDV.
Converts differential GDVD to absolute GDV using scale. Processes appogiatura modifiers recursively.
176 177 178 179 180 181 182 183 |
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 176 def apply(gdvd, on:) gdv = gdvd.to_gdv @scale, previous: on appogiatura_action = gdvd.dig(:modifiers, :appogiatura) gdv[:appogiatura] = appogiatura_action.to_gdv @scale, previous: on if appogiatura_action gdv end |
#inspect ⇒ String Also known as: to_s
Returns debug representation.
190 191 192 |
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 190 def inspect "GDV NeumaDecoder: @last = #{@last}" end |
#process(gdvd) ⇒ Hash
Processes GDVD attributes before conversion.
Sets base_duration on GDVD object for duration calculations. Handles appogiatura (grace note) modifiers recursively.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 131 def process(gdvd) gdvd = gdvd.clone gdvd.base_duration = @base_duration appogiatura_gdvd = gdvd[:modifiers]&.delete :appogiatura if appogiatura_gdvd appogiatura_gdvd = appogiatura_gdvd.clone appogiatura_gdvd.base_duration = @base_duration gdvd[:modifiers][:appogiatura] = appogiatura_gdvd end gdvd end |
#subcontext ⇒ NeumaDecoder
Creates independent subcontext decoder.
Returns new decoder with current @last state as base, enabling
independent processing of nested structures (grace notes, etc.).
156 157 158 |
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 156 def subcontext NeumaDecoder.new @scale, base_duration: @base_duration, transcriptor: @transcriptor, base: @last end |