Class: Musa::Neumas::Decoders::NeumaDecoder

Inherits:
Decoder show all
Defined in:
lib/musa-dsl/neumas/neuma-gdv-decoder.rb

Overview

to get a GDV

Instance Attribute Summary collapse

Attributes inherited from Decoder

#base, #transcriptor

Instance Method Summary collapse

Methods inherited from Decoder

#decode

Methods inherited from DifferentialDecoder

#decode

Methods inherited from ProtoDecoder

#decode

Constructor Details

#initialize(scale, base_duration: nil, transcriptor: nil, base: nil) ⇒ NeumaDecoder

Returns a new instance of NeumaDecoder.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 6

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_durationObject

Returns the value of attribute base_duration.



18
19
20
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 18

def base_duration
  @base_duration
end

#scaleObject

Returns the value of attribute scale.



18
19
20
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 18

def scale
  @scale
end

Instance Method Details

#apply(gdvd, on:) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 41

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

#inspectObject Also known as: to_s



50
51
52
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 50

def inspect
  "GDV NeumaDecoder: @last = #{@last}"
end

#process(gdvd) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 20

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

#subcontextObject



37
38
39
# File 'lib/musa-dsl/neumas/neuma-gdv-decoder.rb', line 37

def subcontext
  NeumaDecoder.new @scale, base_duration: @base_duration, transcriptor: @transcriptor, base: @last
end