musa-dsl 0.14.26 → 0.21.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/Gemfile +0 -1
  4. data/README.md +5 -1
  5. data/lib/musa-dsl.rb +54 -11
  6. data/lib/musa-dsl/core-ext.rb +7 -13
  7. data/lib/musa-dsl/core-ext/array-explode-ranges.rb +15 -23
  8. data/lib/musa-dsl/core-ext/arrayfy.rb +30 -12
  9. data/lib/musa-dsl/core-ext/attribute-builder.rb +194 -0
  10. data/lib/musa-dsl/core-ext/deep-copy.rb +185 -0
  11. data/lib/musa-dsl/core-ext/dynamic-proxy.rb +44 -40
  12. data/lib/musa-dsl/core-ext/inspect-nice.rb +40 -22
  13. data/lib/musa-dsl/core-ext/smart-proc-binder.rb +108 -0
  14. data/lib/musa-dsl/core-ext/with.rb +26 -0
  15. data/lib/musa-dsl/datasets.rb +8 -3
  16. data/lib/musa-dsl/datasets/dataset.rb +3 -0
  17. data/lib/musa-dsl/datasets/delta-d.rb +12 -0
  18. data/lib/musa-dsl/datasets/e.rb +61 -0
  19. data/lib/musa-dsl/datasets/gdv.rb +51 -411
  20. data/lib/musa-dsl/datasets/gdvd.rb +179 -0
  21. data/lib/musa-dsl/datasets/helper.rb +41 -0
  22. data/lib/musa-dsl/datasets/p.rb +68 -0
  23. data/lib/musa-dsl/datasets/packed-v.rb +19 -0
  24. data/lib/musa-dsl/datasets/pdv.rb +22 -15
  25. data/lib/musa-dsl/datasets/ps.rb +113 -0
  26. data/lib/musa-dsl/datasets/score.rb +210 -0
  27. data/lib/musa-dsl/datasets/score/queriable.rb +48 -0
  28. data/lib/musa-dsl/datasets/score/render.rb +31 -0
  29. data/lib/musa-dsl/datasets/score/to-mxml/process-pdv.rb +160 -0
  30. data/lib/musa-dsl/datasets/score/to-mxml/process-ps.rb +51 -0
  31. data/lib/musa-dsl/datasets/score/to-mxml/process-time.rb +153 -0
  32. data/lib/musa-dsl/datasets/score/to-mxml/to-mxml.rb +158 -0
  33. data/lib/musa-dsl/datasets/v.rb +23 -0
  34. data/lib/musa-dsl/generative.rb +5 -5
  35. data/lib/musa-dsl/generative/backboner.rb +274 -0
  36. data/lib/musa-dsl/generative/darwin.rb +102 -96
  37. data/lib/musa-dsl/generative/generative-grammar.rb +182 -187
  38. data/lib/musa-dsl/generative/markov.rb +56 -53
  39. data/lib/musa-dsl/generative/variatio.rb +234 -222
  40. data/lib/musa-dsl/logger.rb +1 -0
  41. data/lib/musa-dsl/logger/logger.rb +31 -0
  42. data/lib/musa-dsl/matrix.rb +1 -0
  43. data/lib/musa-dsl/matrix/matrix.rb +210 -0
  44. data/lib/musa-dsl/midi.rb +2 -2
  45. data/lib/musa-dsl/midi/midi-recorder.rb +54 -52
  46. data/lib/musa-dsl/midi/midi-voices.rb +183 -182
  47. data/lib/musa-dsl/music.rb +5 -5
  48. data/lib/musa-dsl/music/chord-definition.rb +54 -50
  49. data/lib/musa-dsl/music/chord-definitions.rb +13 -9
  50. data/lib/musa-dsl/music/chords.rb +236 -238
  51. data/lib/musa-dsl/music/equally-tempered-12-tone-scale-system.rb +187 -183
  52. data/lib/musa-dsl/music/scales.rb +331 -332
  53. data/lib/musa-dsl/musicxml.rb +1 -0
  54. data/lib/musa-dsl/musicxml/builder/attributes.rb +155 -0
  55. data/lib/musa-dsl/musicxml/builder/backup-forward.rb +45 -0
  56. data/lib/musa-dsl/musicxml/builder/direction.rb +322 -0
  57. data/lib/musa-dsl/musicxml/builder/helper.rb +90 -0
  58. data/lib/musa-dsl/musicxml/builder/measure.rb +137 -0
  59. data/lib/musa-dsl/musicxml/builder/note-complexities.rb +152 -0
  60. data/lib/musa-dsl/musicxml/builder/note.rb +577 -0
  61. data/lib/musa-dsl/musicxml/builder/part-group.rb +44 -0
  62. data/lib/musa-dsl/musicxml/builder/part.rb +67 -0
  63. data/lib/musa-dsl/musicxml/builder/pitched-note.rb +126 -0
  64. data/lib/musa-dsl/musicxml/builder/rest.rb +117 -0
  65. data/lib/musa-dsl/musicxml/builder/score-partwise.rb +120 -0
  66. data/lib/musa-dsl/musicxml/builder/typed-text.rb +43 -0
  67. data/lib/musa-dsl/musicxml/builder/unpitched-note.rb +112 -0
  68. data/lib/musa-dsl/neumalang.rb +1 -1
  69. data/lib/musa-dsl/neumalang/datatypes.citrus +79 -0
  70. data/lib/musa-dsl/neumalang/neuma.citrus +165 -0
  71. data/lib/musa-dsl/neumalang/neumalang.citrus +32 -242
  72. data/lib/musa-dsl/neumalang/neumalang.rb +373 -142
  73. data/lib/musa-dsl/neumalang/process.citrus +21 -0
  74. data/lib/musa-dsl/neumalang/terminals.citrus +67 -0
  75. data/lib/musa-dsl/neumalang/vectors.citrus +23 -0
  76. data/lib/musa-dsl/neumas.rb +5 -0
  77. data/lib/musa-dsl/neumas/array-to-neumas.rb +34 -0
  78. data/lib/musa-dsl/neumas/neuma-decoder.rb +63 -0
  79. data/lib/musa-dsl/neumas/neuma-gdv-decoder.rb +57 -0
  80. data/lib/musa-dsl/neumas/neuma-gdvd-decoder.rb +15 -0
  81. data/lib/musa-dsl/neumas/neumas.rb +37 -0
  82. data/lib/musa-dsl/neumas/string-to-neumas.rb +34 -0
  83. data/lib/musa-dsl/repl.rb +1 -1
  84. data/lib/musa-dsl/repl/repl.rb +105 -105
  85. data/lib/musa-dsl/sequencer.rb +1 -1
  86. data/lib/musa-dsl/sequencer/base-sequencer-implementation-control.rb +163 -136
  87. data/lib/musa-dsl/sequencer/base-sequencer-implementation-play-helper.rb +301 -286
  88. data/lib/musa-dsl/sequencer/base-sequencer-implementation.rb +562 -270
  89. data/lib/musa-dsl/sequencer/base-sequencer-public.rb +199 -199
  90. data/lib/musa-dsl/sequencer/base-sequencer-tick-based.rb +77 -0
  91. data/lib/musa-dsl/sequencer/base-sequencer-tickless-based.rb +75 -0
  92. data/lib/musa-dsl/sequencer/sequencer-dsl.rb +105 -85
  93. data/lib/musa-dsl/sequencer/timeslots.rb +34 -0
  94. data/lib/musa-dsl/series.rb +1 -1
  95. data/lib/musa-dsl/{core-ext → series}/array-to-serie.rb +1 -1
  96. data/lib/musa-dsl/series/base-series.rb +171 -168
  97. data/lib/musa-dsl/series/hash-serie-splitter.rb +134 -132
  98. data/lib/musa-dsl/series/holder-serie.rb +1 -1
  99. data/lib/musa-dsl/series/main-serie-constructors.rb +6 -1
  100. data/lib/musa-dsl/series/main-serie-operations.rb +807 -797
  101. data/lib/musa-dsl/series/proxy-serie.rb +6 -6
  102. data/lib/musa-dsl/series/queue-serie.rb +5 -5
  103. data/lib/musa-dsl/series/series.rb +2 -0
  104. data/lib/musa-dsl/transcription.rb +4 -0
  105. data/lib/musa-dsl/transcription/from-gdv-to-midi.rb +227 -0
  106. data/lib/musa-dsl/transcription/from-gdv-to-musicxml.rb +36 -0
  107. data/lib/musa-dsl/transcription/from-gdv.rb +17 -0
  108. data/lib/musa-dsl/transcription/transcription.rb +55 -0
  109. data/lib/musa-dsl/transport.rb +6 -6
  110. data/lib/musa-dsl/transport/clock.rb +26 -26
  111. data/lib/musa-dsl/transport/dummy-clock.rb +32 -30
  112. data/lib/musa-dsl/transport/external-tick-clock.rb +21 -20
  113. data/lib/musa-dsl/transport/input-midi-clock.rb +82 -80
  114. data/lib/musa-dsl/transport/timer-clock.rb +72 -71
  115. data/lib/musa-dsl/transport/timer.rb +28 -26
  116. data/lib/musa-dsl/transport/transport.rb +99 -95
  117. data/musa-dsl.gemspec +3 -3
  118. metadata +73 -24
  119. data/lib/musa-dsl/core-ext/array-apply-get.rb +0 -18
  120. data/lib/musa-dsl/core-ext/array-to-neumas.rb +0 -28
  121. data/lib/musa-dsl/core-ext/as-context-run.rb +0 -44
  122. data/lib/musa-dsl/core-ext/duplicate.rb +0 -134
  123. data/lib/musa-dsl/core-ext/key-parameters-procedure-binder.rb +0 -85
  124. data/lib/musa-dsl/core-ext/proc-nice.rb +0 -13
  125. data/lib/musa-dsl/core-ext/send-nice.rb +0 -21
  126. data/lib/musa-dsl/core-ext/string-to-neumas.rb +0 -27
  127. data/lib/musa-dsl/datasets/gdv-decorators.rb +0 -221
  128. data/lib/musa-dsl/generative/rules.rb +0 -282
  129. data/lib/musa-dsl/neuma.rb +0 -1
  130. data/lib/musa-dsl/neuma/neuma.rb +0 -181
@@ -1 +1 @@
1
- require 'musa-dsl/sequencer/sequencer'
1
+ require_relative 'sequencer/sequencer'
@@ -1,189 +1,216 @@
1
1
  require 'forwardable'
2
2
 
3
- class Musa::BaseSequencer
4
- class EventHandler
5
- attr_reader :stdout, :stderr
6
- attr_accessor :continue_parameters
3
+ module Musa
4
+ module Sequencer
5
+ class BaseSequencer
6
+ class EventHandler
7
+ include Musa::Extension::SmartProcBinder
7
8
 
8
- @@counter = 0
9
+ attr_accessor :continue_parameters
9
10
 
10
- def initialize(parent = nil, capture_stdout: nil)
11
- capture_stdout ||= false
11
+ @@counter = 0
12
12
 
13
- @id = (@@counter += 1)
13
+ def initialize(parent = nil)
14
+ @id = (@@counter += 1)
14
15
 
15
- @parent = parent
16
- @handlers = {}
16
+ @parent = parent
17
+ @handlers = {}
17
18
 
18
- @stop = false
19
+ @stop = false
20
+ end
19
21
 
20
- if capture_stdout || !parent
21
- @stdout = $stdout
22
- @stderr = $stderr
23
- else
24
- @stdout = @parent.stdout
25
- @stderr = @parent.stderr
26
- end
27
- end
22
+ def stop
23
+ @stop = true
24
+ end
28
25
 
29
- def stop
30
- @stop = true
31
- end
26
+ def stopped?
27
+ @stop
28
+ end
32
29
 
33
- def stopped?
34
- @stop
35
- end
30
+ def pause
31
+ raise NotImplementedError
32
+ end
36
33
 
37
- def pause
38
- raise NotImplementedError
39
- end
34
+ def continue
35
+ @paused = false
36
+ end
40
37
 
41
- def continue
42
- @paused = false
43
- end
38
+ def paused?
39
+ @paused
40
+ end
44
41
 
45
- def paused?
46
- @paused
47
- end
42
+ def on(event, name: nil, only_once: nil, &block)
43
+ only_once ||= false
48
44
 
49
- def on(event, name: nil, only_once: nil, &block)
50
- only_once ||= false
45
+ @handlers[event] ||= {}
51
46
 
52
- @handlers[event] ||= {}
47
+ # TODO: add on_rescue: proc { |e| _rescue_block_error(e) } [this method is on Sequencer, not in EventHandler]
48
+ @handlers[event][name] = {block: SmartProcBinder.new(block), only_once: only_once }
49
+ end
53
50
 
54
- # TODO: add on_rescue: proc { |e| _rescue_block_error(e) } [this method is on Sequencer, not in EventHandler]
55
- @handlers[event][name] = { block: KeyParametersProcedureBinder.new(block), only_once: only_once }
56
- end
51
+ def launch(event, *value_parameters, **key_parameters)
52
+ _launch event, value_parameters, key_parameters
53
+ end
57
54
 
58
- def launch(event, *value_parameters, **key_parameters)
59
- _launch event, value_parameters, key_parameters
60
- end
55
+ def _launch(event, value_parameters = nil, key_parameters = nil)
56
+ value_parameters ||= []
57
+ key_parameters ||= {}
58
+ processed = false
61
59
 
62
- def _launch(event, value_parameters = nil, key_parameters = nil)
63
- processed = false
60
+ if @handlers.key? event
61
+ @handlers[event].each do |name, handler|
62
+ handler[:block].call *value_parameters, **key_parameters
63
+ @handlers[event].delete name if handler[:only_once]
64
+ processed = true
65
+ end
66
+ end
64
67
 
65
- if @handlers.key? event
66
- @handlers[event].each do |name, handler|
67
- handler[:block]._call value_parameters, key_parameters
68
- @handlers[event].delete name if handler[:only_once]
69
- processed = true
68
+ @parent._launch event, value_parameters, key_parameters if @parent && !processed
70
69
  end
71
- end
72
70
 
73
- @parent._launch event, value_parameters, key_parameters if @parent && !processed
74
- end
71
+ def inspect
72
+ "EventHandler #{id}"
73
+ end
75
74
 
76
- def inspect
77
- "EventHandler #{id}"
78
- end
75
+ def id
76
+ if @parent
77
+ "#{@parent.id}.#{self.class.name.split('::').last}-#{@id}"
78
+ else
79
+ "#{self.class.name.split('::').last}-#{@id.to_s}"
80
+ end
81
+ end
79
82
 
80
- def id
81
- if @parent
82
- "#{@parent.id}.#{self.class.name.split('::').last}-#{@id}"
83
- else
84
- "#{self.class.name.split('::').last}-#{@id.to_s}"
83
+ alias to_s inspect
85
84
  end
86
- end
87
85
 
88
- alias to_s inspect
89
- end
86
+ private_constant :EventHandler
90
87
 
91
- private_constant :EventHandler
88
+ class PlayControl < EventHandler
89
+ attr_reader :do_after
92
90
 
93
- class PlayControl < EventHandler
94
- attr_reader :do_after
91
+ def initialize(parent, after: nil)
92
+ super parent
95
93
 
96
- def initialize(parent, capture_stdout: nil, after: nil)
97
- super parent, capture_stdout: capture_stdout
94
+ @do_after = []
98
95
 
99
- @do_after = []
96
+ self.after &after if after
97
+ end
100
98
 
101
- self.after &after if after
102
- end
99
+ def pause
100
+ @paused = true
101
+ end
103
102
 
104
- def pause
105
- @paused = true
106
- end
103
+ def store_continuation(sequencer:, serie:, nl_context:, mode:, decoder:, play_eval:, mode_args:)
104
+ @continuation_sequencer = sequencer
105
+ @continuation_parameters = {
106
+ serie: serie,
107
+ control: self,
108
+ nl_context: nl_context,
109
+ mode: mode,
110
+ decoder: decoder,
111
+ play_eval: play_eval,
112
+ mode_args: mode_args
113
+ }
114
+ end
107
115
 
108
- def store_continuation(sequencer:, serie:, nl_context:, mode:, decoder:, play_eval:, mode_args:)
109
- @continuation_sequencer = sequencer
110
- @continuation_parameters = {
111
- serie: serie,
112
- control: self,
113
- nl_context: nl_context,
114
- mode: mode,
115
- decoder: decoder,
116
- play_eval: play_eval,
117
- mode_args: mode_args
118
- }
119
- end
116
+ def continue
117
+ super
118
+ @continuation_sequencer.continuation_play(@continuation_parameters) if @continuation_sequencer
119
+ end
120
120
 
121
- def continue
122
- super
123
- @continuation_sequencer.continuation_play(@continuation_parameters) if @continuation_sequencer
124
- end
121
+ def after(_bars = nil, &block)
122
+ # TODO implementar parámetro _bars (?)
123
+ @do_after << block
124
+ end
125
+ end
125
126
 
126
- def after(_bars = nil, &block)
127
- # TODO implementar parámetro _bars (?)
128
- @do_after << block
129
- end
130
- end
127
+ private_constant :PlayControl
131
128
 
132
- private_constant :PlayControl
129
+ class EveryControl < EventHandler
130
+ attr_reader :duration_value, :till_value, :condition_block, :do_on_stop, :do_after
133
131
 
134
- class EveryControl < EventHandler
135
- attr_reader :duration_value, :till_value, :condition_block, :do_on_stop, :do_after
132
+ attr_accessor :_start_position
133
+ attr_accessor :_execution_counter
136
134
 
137
- attr_accessor :_start
135
+ def initialize(parent, duration: nil, till: nil, condition: nil, on_stop: nil, after_bars: nil, after: nil)
136
+ super parent
138
137
 
139
- def initialize(parent, capture_stdout: nil, duration: nil, till: nil, condition: nil, on_stop: nil, after_bars: nil, after: nil)
140
- super parent, capture_stdout: capture_stdout
138
+ @duration_value = duration
139
+ @till_value = till
140
+ @condition_block = condition
141
141
 
142
- @duration_value = duration
143
- @till_value = till
144
- @condition_block = condition
142
+ @do_on_stop = []
143
+ @do_after = []
145
144
 
146
- @do_on_stop = []
147
- @do_after = []
145
+ @do_on_stop << on_stop if on_stop
148
146
 
149
- @do_on_stop << on_stop if on_stop
147
+ self.after after_bars, &after if after
148
+ end
150
149
 
151
- self.after after_bars, &after if after
152
- end
150
+ def duration(value)
151
+ @duration_value = value.rationalize
152
+ end
153
153
 
154
- def duration(value)
155
- @duration_value = value.rationalize
156
- end
154
+ def till(value)
155
+ @till_value = value.rationalize
156
+ end
157
157
 
158
- def till(value)
159
- @till_value = value.rationalize
160
- end
158
+ def condition(&block)
159
+ @condition_block = block
160
+ end
161
161
 
162
- def condition(&block)
163
- @condition_block = block
164
- end
162
+ def on_stop(&block)
163
+ @do_on_stop << block
164
+ end
165
165
 
166
- def on_stop(&block)
167
- @do_on_stop << block
168
- end
166
+ def after(bars = nil, &block)
167
+ bars ||= 0
168
+ @do_after << { bars: bars.rationalize, block: block }
169
+ end
170
+ end
169
171
 
170
- def after(bars = nil, &block)
171
- bars ||= 0
172
- @do_after << { bars: bars.rationalize, block: block }
173
- end
174
- end
172
+ private_constant :EveryControl
175
173
 
176
- private_constant :EveryControl
174
+ class MoveControl < EventHandler
175
+ attr_reader :every_control, :do_on_stop, :do_after
177
176
 
178
- class MoveControl
179
- extend Forwardable
177
+ def initialize(parent, duration: nil, till: nil, on_stop: nil, after_bars: nil, after: nil)
178
+ super parent
180
179
 
181
- def initialize(every_control)
182
- @every_control = every_control
183
- end
180
+ @every_control = EveryControl.new(self, duration: duration, till: till)
184
181
 
185
- def_delegators :@every_control, :stdout, :stderr, :on_stop, :after, :on, :launch, :stop
186
- end
182
+ @do_on_stop = []
183
+ @do_after = []
184
+
185
+ @do_on_stop << on_stop if on_stop
186
+ self.after after_bars, &after if after
187
+
188
+ @every_control.on_stop do
189
+ @stop = true
190
+ @do_on_stop.each(&:call)
191
+ end
192
+ end
193
+
194
+ def on_stop(&block)
195
+ @do_on_stop << block
196
+ end
197
+
198
+ def after(bars = nil, &block)
199
+ bars ||= 0
200
+ @do_after << { bars: bars.rationalize, block: block }
201
+ end
187
202
 
188
- private_constant :MoveControl
203
+ def stop
204
+ @every_control.stop
205
+ end
206
+
207
+ def stopped?
208
+ @stop
209
+ end
210
+ end
211
+
212
+ private_constant :MoveControl
213
+ end
214
+ end
189
215
  end
216
+
@@ -1,354 +1,369 @@
1
- class Musa::BaseSequencer
2
- class PlayEval
3
- def self.create(mode, block_procedure_binder, decoder, nl_context)
4
- case mode
5
- when :at
6
- AtModePlayEval.new block_procedure_binder
7
- when :wait
8
- WaitModePlayEval.new block_procedure_binder
9
- when :neumalang
10
- NeumalangModePlayEval.new block_procedure_binder, decoder, nl_context
11
- else
12
- raise ArgumentError, "Mode #{mode} not allowed"
13
- end
14
- end
15
-
16
- attr_reader :block_procedure_binder
17
-
18
- def subcontext
19
- self
20
- end
21
-
22
- def eval_element(_element)
23
- raise NotImplementedError
24
- end
1
+ using Musa::Extension::DeepCopy
2
+
3
+ module Musa
4
+ module Sequencer
5
+ class BaseSequencer
6
+ class PlayEval
7
+ def self.create(mode, block_procedure_binder, decoder, nl_context)
8
+ case mode
9
+ when :at
10
+ AtModePlayEval.new block_procedure_binder
11
+ when :wait
12
+ WaitModePlayEval.new block_procedure_binder
13
+ when :neumalang
14
+ NeumalangModePlayEval.new block_procedure_binder, decoder, nl_context
15
+ else
16
+ raise ArgumentError, "Mode #{mode} not allowed"
17
+ end
18
+ end
25
19
 
26
- def run_operation(_element)
27
- raise NotImplementedError
28
- end
29
- end
20
+ attr_reader :block_procedure_binder
30
21
 
31
- private_constant :PlayEval
22
+ def subcontext
23
+ self
24
+ end
32
25
 
33
- class AtModePlayEval < PlayEval
34
- def initialize(block_procedure_binder)
35
- @block_procedure_binder = block_procedure_binder
36
- end
26
+ def eval_element(_element)
27
+ raise NotImplementedError
28
+ end
37
29
 
38
- def run_operation(element)
39
- value = nil
40
-
41
- if element.is_a? Hash
42
- value = {
43
- current_operation: :block,
44
- current_block: @block_procedure_binder,
45
- current_parameter: element,
46
- continue_operation: :at,
47
- continue_parameter: element[:at]
48
- }
30
+ def run_operation(_element)
31
+ raise NotImplementedError
32
+ end
49
33
  end
50
34
 
51
- value ||= {
52
- current_operation: @block_procedure_binder,
53
- current_parameter: element,
54
- continue_operation: :at,
55
- continue_parameter: position
56
- }
57
- end
58
- end
59
-
60
- private_constant :AtModePlayEval
35
+ private_constant :PlayEval
61
36
 
62
- class WaitModePlayEval < PlayEval
63
- def initialize(block_procedure_binder)
64
- @block_procedure_binder = block_procedure_binder
65
- end
66
-
67
- def run_operation(element)
68
- value = nil
69
-
70
- if element.is_a? Hash
71
- if element.key? :duration
72
- value = {
73
- current_operation: :block,
74
- current_block: @block_procedure_binder,
75
- current_parameter: element,
76
- continue_operation: :wait,
77
- continue_parameter: element[:duration]
78
- }
37
+ class AtModePlayEval < PlayEval
38
+ def initialize(block_procedure_binder)
39
+ @block_procedure_binder = block_procedure_binder
79
40
  end
80
41
 
81
- if element.key? :wait_event
82
- value = {
83
- current_operation: :block,
84
- current_block: @block_procedure_binder,
85
- current_parameter: element,
86
- continue_operation: :on,
87
- continue_parameter: element[:wait_event]
42
+ def run_operation(element)
43
+ value = nil
44
+
45
+ if element.is_a? Hash
46
+ value = {
47
+ current_operation: :block,
48
+ current_block: @block_procedure_binder,
49
+ current_parameter: element,
50
+ continue_operation: :at,
51
+ continue_parameter: element[:at]
52
+ }
53
+ end
54
+
55
+ value ||= {
56
+ current_operation: @block_procedure_binder,
57
+ current_parameter: element,
58
+ continue_operation: :at,
59
+ continue_parameter: position
88
60
  }
89
61
  end
90
62
  end
91
63
 
92
- value ||= {
93
- current_operation: :block,
94
- current_block: @block_procedure_binder,
95
- current_parameter: element,
96
- continue_operation: :now
97
- }
98
-
99
- value
100
- end
101
- end
102
-
103
- private_constant :WaitModePlayEval
104
-
105
- class NeumalangModePlayEval < PlayEval
106
- module Parallel end
107
-
108
- @@id = 0
64
+ private_constant :AtModePlayEval
109
65
 
110
- attr_reader :nl_context
111
- attr_reader :block_procedure_binder
66
+ class WaitModePlayEval < PlayEval
67
+ include Musa::Datasets
112
68
 
113
- def initialize(block_procedure_binder, decoder, nl_context, parent: nil)
114
- @id = @@id += 1
115
- @parent = parent
69
+ def initialize(block_procedure_binder)
70
+ @block_procedure_binder = block_procedure_binder
71
+ end
116
72
 
117
- @block_procedure_binder = block_procedure_binder
118
- @decoder = decoder
119
- @nl_context = nl_context
120
- @nl_context ||= Object.new
121
- end
73
+ def run_operation(element)
74
+ value = nil
75
+
76
+ if element.is_a? Hash
77
+ if AbsD.is_compatible?(element)
78
+ element = AbsD.to_AbsD(element)
79
+
80
+ value = {
81
+ current_operation: :block,
82
+ current_block: @block_procedure_binder,
83
+ current_parameter: element,
84
+ continue_operation: :wait,
85
+ continue_parameter: element.forward_duration
86
+ }
87
+ end
88
+
89
+ if element.key? :wait_event
90
+ value = {
91
+ current_operation: :block,
92
+ current_block: @block_procedure_binder,
93
+ current_parameter: element,
94
+ continue_operation: :on,
95
+ continue_parameter: element[:wait_event]
96
+ }
97
+ end
98
+ end
122
99
 
123
- def subcontext
124
- NeumalangModePlayEval.new @block_procedure_binder, @decoder.subcontext, @nl_context, parent: self
125
- end
100
+ value ||= {
101
+ current_operation: :block,
102
+ current_block: @block_procedure_binder,
103
+ current_parameter: element,
104
+ continue_operation: :now
105
+ }
126
106
 
127
- def eval_element(element)
128
- if element.is_a? Musa::Neumalang::Dataset
129
- element
130
- else
131
- case element[:kind]
132
- when :serie then eval_serie element[:serie]
133
- when :parallel then eval_parallel element[:parallel]
134
- when :assign_to then eval_assign_to element[:assign_to], element[:assign_value]
135
- when :use_variable then eval_use_variable element[:use_variable]
136
- when :command then eval_command element[:command], element[:value_parameters], element[:key_parameters]
137
- when :value then eval_value element[:value]
138
- when :neuma then eval_neuma element[:neuma]
139
- when :call_methods then eval_call_methods element[:on], element[:call_methods]
140
- when :indirection then eval_indirection element[:indirection]
141
- when :reference then eval_reference element[:reference]
142
- when :event then element
143
- else
144
- raise ArgumentError, "eval_element: don't know how to process #{element}"
107
+ value
145
108
  end
146
109
  end
147
- end
148
-
149
- def eval_value(value)
150
- value
151
- end
152
-
153
- def eval_neuma(neuma)
154
- @decoder.decode neuma
155
- end
156
110
 
157
- def eval_serie(serie)
158
- context = subcontext
159
- serie.instance.eval(on_restart: proc { context = subcontext }) { |e| context.eval_element e }
160
- end
111
+ private_constant :WaitModePlayEval
161
112
 
162
- def eval_parallel(series)
163
- context = subcontext
164
- series.collect { |s| context.eval_serie s[:serie] }.extend Parallel
165
- end
113
+ class NeumalangModePlayEval < PlayEval
114
+ include Musa::Datasets
166
115
 
167
- def eval_assign_to(variable_names, value)
168
- _value = nil
116
+ module Parallel end
169
117
 
170
- variable_names.each do |var_name|
171
- @nl_context.instance_variable_set var_name, _value = subcontext.eval_element(value)
172
- end
118
+ @@id = 0
173
119
 
174
- _value
175
- end
120
+ attr_reader :nl_context
121
+ attr_reader :block_procedure_binder
176
122
 
177
- def eval_use_variable(variable_name)
178
- if @nl_context.instance_variable_defined? variable_name
179
- @nl_context.instance_variable_get(variable_name)
180
- else
181
- raise NameError, "Variable #{variable_name} is not defined in context #{@nl_context}"
182
- end
183
- end
123
+ def initialize(block_procedure_binder, decoder, nl_context, parent: nil)
124
+ @id = @@id += 1
125
+ @parent = parent
184
126
 
185
- def eval_command(block, value_parameters, key_parameters)
186
- _value_parameters = value_parameters.collect { |e| subcontext.eval_element(e) } if value_parameters
187
- _key_parameters = key_parameters.collect { |k, e| [k, subcontext.eval_element(e)] }.to_h if key_parameters
127
+ @block_procedure_binder = block_procedure_binder
128
+ @decoder = decoder
129
+ @nl_context = nl_context
188
130
 
189
- @nl_context._as_context_run block, _value_parameters, _key_parameters
190
- end
191
-
192
- def eval_call_methods(on, call_methods)
193
- play_eval = subcontext
194
-
195
- value = play_eval.eval_element on
131
+ @nl_context ||= Object.new
132
+ end
196
133
 
197
- if value.is_a? Parallel
198
- value.collect do |_value|
199
- call_methods.each do |methd|
200
- value_parameters = methd[:value_parameters].collect { |e| play_eval.subcontext.eval_element(e) } if methd[:value_parameters]
201
- key_parameters = methd[:key_parameters].collect { |k, e| [k, play_eval.subcontext.eval_element(e)] }.to_h if methd[:key_parameters]
134
+ def subcontext
135
+ NeumalangModePlayEval.new @block_procedure_binder, @decoder.subcontext, @nl_context, parent: self
136
+ end
202
137
 
203
- _value = _value._send_nice methd[:method], value_parameters, key_parameters
138
+ def eval_element(element)
139
+ if AbsD.is_compatible?(element)
140
+ AbsD.to_AbsD(element)
141
+ else
142
+ case element[:kind]
143
+ when :serie then eval_serie element[:serie]
144
+ when :parallel then eval_parallel element[:parallel]
145
+ when :assign_to then eval_assign_to element[:assign_to], element[:assign_value]
146
+ when :use_variable then eval_use_variable element[:use_variable]
147
+ when :command then eval_command element[:command], element[:value_parameters], element[:key_parameters]
148
+ when :value then eval_value element[:value]
149
+ when :gdvd then eval_gdvd element[:gdvd]
150
+ when :p then eval_p element[:p]
151
+ when :call_methods then eval_call_methods element[:on], element[:call_methods]
152
+ when :reference then eval_reference element[:reference]
153
+ when :event then element
154
+ else
155
+ raise ArgumentError, "eval_element: don't know how to process #{element}"
156
+ end
204
157
  end
205
-
206
- _value
207
- end.extend Parallel
208
- else
209
- call_methods.each do |methd|
210
- value_parameters = methd[:value_parameters].collect { |e| play_eval.subcontext.eval_element(e) } if methd[:value_parameters]
211
- key_parameters = methd[:key_parameters].collect { |k, e| [k, play_eval.subcontext.eval_element(e)] }.to_h if methd[:key_parameters]
212
-
213
- value = value._send_nice methd[:method], value_parameters, key_parameters
214
158
  end
215
159
 
216
- value
217
- end
218
- end
219
-
220
- def eval_reference(element)
221
- if element.is_a?(Hash) && element.key?(:kind)
222
- case element[:kind]
223
- when :command
224
- element[:command]
225
- else
226
- raise ArgumentError, "eval_reference(&): don't know how to process element #{element}"
160
+ def eval_value(value)
161
+ value
227
162
  end
228
- else
229
- raise ArgumentError, "eval_reference(&): don't know how to process element #{element}"
230
- end
231
- end
232
-
233
- def run_operation(element)
234
- case element
235
- when nil
236
- { current_operation: :none,
237
- continue_operation: :now }
238
163
 
239
- when Musa::Neumalang::Dataset
240
- { current_operation: :block,
241
- current_parameter: element,
242
- continue_operation: :wait,
243
- continue_parameter: element[:duration] }
164
+ def eval_gdvd(gdvd)
165
+ @decoder.decode(gdvd)
166
+ end
244
167
 
245
- when Musa::Serie
246
- { current_operation: :play,
247
- current_parameter: element.restart }
168
+ def eval_p(p)
169
+ p.to_ps_serie(@decoder.base_duration).instance
170
+ end
248
171
 
249
- when Parallel
250
- { current_operation: :parallel_play,
251
- current_parameter: element.tap { |e| e.each(&:restart) } }
172
+ def eval_serie(serie)
173
+ context = subcontext
174
+ serie.instance.eval(on_restart: proc { context = subcontext }) { |e| context.eval_element e }
175
+ end
252
176
 
253
- when Array
254
- { current_operation: :no_eval_play,
255
- current_parameter: S(*element) }
256
- else
257
- case element[:kind]
258
- when :value
177
+ def eval_parallel(series)
178
+ context = subcontext
179
+ series.collect { |s| context.eval_serie s[:serie] }.extend Parallel
180
+ end
259
181
 
260
- _value = eval_value element[:value]
182
+ def eval_assign_to(variable_names, value)
183
+ _value = nil
261
184
 
262
- if _value.is_a?(Hash) && _value.key?(:duration)
263
- { current_operation: :block,
264
- current_parameter: _value,
265
- continue_operation: :wait,
266
- continue_parameter: _value[:duration] }
267
- else
268
- { current_operation: :block,
269
- current_parameter: _value,
270
- continue_operation: :now }
185
+ variable_names.each do |var_name|
186
+ @nl_context.instance_variable_set var_name, _value = subcontext.eval_element(value)
271
187
  end
272
188
 
273
- when :neuma
274
- _value = eval_neuma element[:neuma]
189
+ _value
190
+ end
275
191
 
276
- if _value.is_a?(Array)
277
- { current_operation: :no_eval_play,
278
- current_parameter: S(*_value) }
192
+ def eval_use_variable(variable_name)
193
+ if @nl_context.instance_variable_defined?(variable_name)
194
+ @nl_context.instance_variable_get(variable_name)
279
195
  else
280
- { current_operation: :block,
281
- current_parameter: _value,
282
- continue_operation: :wait,
283
- continue_parameter: _value[:duration] }
196
+ raise NameError, "Variable #{variable_name} is not defined in context #{@nl_context}"
284
197
  end
198
+ end
285
199
 
286
- when :serie
287
-
288
- { current_operation: :play,
289
- current_parameter: eval_serie(element[:serie]) }
290
-
291
- when :parallel
292
-
293
- { current_operation: :parallel_play,
294
- current_parameter: eval_parallel(element[:parallel]) }
295
-
296
- when :assign_to
200
+ def eval_command(block, value_parameters, key_parameters)
201
+ _value_parameters = value_parameters ? value_parameters.collect { |e| subcontext.eval_element(e) } : []
202
+ _key_parameters = key_parameters ? key_parameters.collect { |k, e| [k, subcontext.eval_element(e)] }.to_h : {}
297
203
 
298
- eval_assign_to element[:assign_to], element[:assign_value]
204
+ # used instance_exec because the code on block comes from a neumalang source, so the correct execution context is the neumalang context
205
+ # (no other context has any sense)
206
+ #
207
+ @nl_context.instance_exec *_value_parameters, **_key_parameters, &block
208
+ end
299
209
 
300
- { current_operation: :none,
301
- continue_operation: :now }
210
+ def eval_call_methods(on, call_methods)
211
+ play_eval = subcontext
302
212
 
303
- when :use_variable
213
+ value = play_eval.eval_element on
304
214
 
305
- run_operation eval_use_variable(element[:use_variable])
215
+ if value.is_a? Parallel
216
+ value.collect do |_value|
217
+ call_methods.each do |methd|
218
+ value_parameters = methd[:value_parameters] ? methd[:value_parameters].collect { |e| play_eval.subcontext.eval_element(e) } : []
219
+ key_parameters = methd[:key_parameters] ? methd[:key_parameters].collect { |k, e| [k, play_eval.subcontext.eval_element(e)] }.to_h : {}
306
220
 
307
- when :event
221
+ _value = _value.send methd[:method], *value_parameters, **key_parameters
222
+ end
308
223
 
309
- value_parameters = key_parameters = nil
224
+ _value
225
+ end.extend Parallel
226
+ else
227
+ call_methods.each do |methd|
228
+ value_parameters = methd[:value_parameters] ? methd[:value_parameters].collect { |e| play_eval.subcontext.eval_element(e) } : []
229
+ key_parameters = methd[:key_parameters] ? methd[:key_parameters].collect { |k, e| [k, play_eval.subcontext.eval_element(e)] }.to_h : {}
310
230
 
311
- value_parameters = element[:value_parameters].collect { |e| subcontext.eval_element(e) } if element[:value_parameters]
312
- key_parameters = element[:key_parameters].collect { |k, e| [k, subcontext.eval_element(e)] }.to_h if element[:key_parameters]
231
+ value = value.send methd[:method], *value_parameters, **key_parameters
232
+ end
313
233
 
314
- { current_operation: :event,
315
- current_event: element[:event],
316
- current_value_parameters: value_parameters,
317
- current_key_parameters: key_parameters,
318
- continue_operation: :now }
234
+ value
235
+ end
236
+ end
319
237
 
320
- when :command
238
+ def eval_reference(element)
239
+ if element.is_a?(Hash) && element.key?(:kind)
240
+ case element[:kind]
241
+ when :command
242
+ element[:command]
243
+ else
244
+ raise ArgumentError, "eval_reference(&): don't know how to process element #{element}"
245
+ end
246
+ else
247
+ raise ArgumentError, "eval_reference(&): don't know how to process element #{element}"
248
+ end
249
+ end
321
250
 
322
- run_operation eval_command(element[:command], element[:value_parameters], element[:key_parameters])
251
+ def run_operation(element)
252
+ case element
253
+ when nil
254
+ { current_operation: :none,
255
+ continue_operation: :now }
323
256
 
324
- when :call_methods
257
+ when Musa::Datasets::AbsD
258
+ { current_operation: :block,
259
+ current_parameter: element,
260
+ continue_operation: :wait,
261
+ continue_parameter: element.forward_duration }
325
262
 
326
- run_operation eval_call_methods(element[:on], element[:call_methods])
263
+ when Musa::Series::Serie
264
+ { current_operation: :play,
265
+ current_parameter: element.restart }
327
266
 
328
- when :reference
267
+ when Parallel
268
+ { current_operation: :parallel_play,
269
+ current_parameter: element.tap { |e| e.each(&:restart) } }
329
270
 
330
- run_operation eval_reference(element[:reference])
271
+ when Array
272
+ { current_operation: :no_eval_play,
273
+ current_parameter: S(*element) }
274
+ else
275
+ case element[:kind]
276
+ when :value
277
+ _value = eval_value element[:value]
278
+
279
+ if AbsD.is_compatible?(_value)
280
+ _value = AbsD.to_AbsD(_value)
281
+
282
+ { current_operation: :block,
283
+ current_parameter: _value,
284
+ continue_operation: :wait,
285
+ continue_parameter: _value.forward_duration }
286
+ else
287
+ { current_operation: :block,
288
+ current_parameter: _value,
289
+ continue_operation: :now }
290
+ end
291
+
292
+ when :gdvd
293
+ _value = eval_gdvd element[:gdvd]
294
+
295
+ if _value.is_a?(Array)
296
+ { current_operation: :no_eval_play,
297
+ current_parameter: S(*_value) }
298
+ else
299
+ { current_operation: :block,
300
+ current_parameter: _value,
301
+ continue_operation: :wait,
302
+ continue_parameter: _value.forward_duration }
303
+ end
304
+
305
+ when :p
306
+ { current_operation: :play,
307
+ current_parameter: eval_p(element[:p]) }
308
+
309
+ when :serie
310
+ { current_operation: :play,
311
+ current_parameter: eval_serie(element[:serie]) }
312
+
313
+ when :parallel
314
+ { current_operation: :parallel_play,
315
+ current_parameter: eval_parallel(element[:parallel]) }
316
+
317
+ when :assign_to
318
+ eval_assign_to element[:assign_to], element[:assign_value]
319
+
320
+ { current_operation: :none,
321
+ continue_operation: :now }
322
+
323
+ when :use_variable
324
+ run_operation eval_use_variable(element[:use_variable])
325
+
326
+ when :event
327
+ value_parameters = element[:value_parameters] ? element[:value_parameters].collect { |e| subcontext.eval_element(e) } : []
328
+ key_parameters = element[:key_parameters] ? element[:key_parameters].collect { |k, e| [k, subcontext.eval_element(e)] }.to_h : {}
329
+
330
+ { current_operation: :event,
331
+ current_event: element[:event],
332
+ current_value_parameters: value_parameters,
333
+ current_key_parameters: key_parameters,
334
+ continue_operation: :now }
335
+
336
+ when :command
337
+ run_operation eval_command(element[:command], element[:value_parameters], element[:key_parameters])
338
+
339
+ when :call_methods
340
+ run_operation eval_call_methods(element[:on], element[:call_methods])
341
+
342
+ when :reference
343
+ run_operation eval_reference(element[:reference])
344
+
345
+ else
346
+ raise ArgumentError, "run_operation: don't know how to process #{element}"
347
+ end
348
+ end
349
+ end
331
350
 
332
- else
333
- raise ArgumentError, "run_operation: don't know how to process #{element}"
351
+ def inspect
352
+ "NeumalangModePlayEval #{id} #{@decoder}"
334
353
  end
335
- end
336
- end
337
354
 
338
- def inspect
339
- "NeumalangModePlayEval #{id} #{@decoder}"
340
- end
355
+ def id
356
+ if @parent
357
+ "#{@parent.id}.#{@id}"
358
+ else
359
+ @id.to_s
360
+ end
361
+ end
341
362
 
342
- def id
343
- if @parent
344
- "#{@parent.id}.#{@id}"
345
- else
346
- @id.to_s
363
+ alias to_s inspect
347
364
  end
348
- end
349
365
 
350
- alias to_s inspect
366
+ private_constant :NeumalangModePlayEval
367
+ end
351
368
  end
352
-
353
- private_constant :NeumalangModePlayEval
354
369
  end