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.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/Gemfile +0 -1
- data/README.md +5 -1
- data/lib/musa-dsl.rb +54 -11
- data/lib/musa-dsl/core-ext.rb +7 -13
- data/lib/musa-dsl/core-ext/array-explode-ranges.rb +15 -23
- data/lib/musa-dsl/core-ext/arrayfy.rb +30 -12
- data/lib/musa-dsl/core-ext/attribute-builder.rb +194 -0
- data/lib/musa-dsl/core-ext/deep-copy.rb +185 -0
- data/lib/musa-dsl/core-ext/dynamic-proxy.rb +44 -40
- data/lib/musa-dsl/core-ext/inspect-nice.rb +40 -22
- data/lib/musa-dsl/core-ext/smart-proc-binder.rb +108 -0
- data/lib/musa-dsl/core-ext/with.rb +26 -0
- data/lib/musa-dsl/datasets.rb +8 -3
- data/lib/musa-dsl/datasets/dataset.rb +3 -0
- data/lib/musa-dsl/datasets/delta-d.rb +12 -0
- data/lib/musa-dsl/datasets/e.rb +61 -0
- data/lib/musa-dsl/datasets/gdv.rb +51 -411
- data/lib/musa-dsl/datasets/gdvd.rb +179 -0
- data/lib/musa-dsl/datasets/helper.rb +41 -0
- data/lib/musa-dsl/datasets/p.rb +68 -0
- data/lib/musa-dsl/datasets/packed-v.rb +19 -0
- data/lib/musa-dsl/datasets/pdv.rb +22 -15
- data/lib/musa-dsl/datasets/ps.rb +113 -0
- data/lib/musa-dsl/datasets/score.rb +210 -0
- data/lib/musa-dsl/datasets/score/queriable.rb +48 -0
- data/lib/musa-dsl/datasets/score/render.rb +31 -0
- data/lib/musa-dsl/datasets/score/to-mxml/process-pdv.rb +160 -0
- data/lib/musa-dsl/datasets/score/to-mxml/process-ps.rb +51 -0
- data/lib/musa-dsl/datasets/score/to-mxml/process-time.rb +153 -0
- data/lib/musa-dsl/datasets/score/to-mxml/to-mxml.rb +158 -0
- data/lib/musa-dsl/datasets/v.rb +23 -0
- data/lib/musa-dsl/generative.rb +5 -5
- data/lib/musa-dsl/generative/backboner.rb +274 -0
- data/lib/musa-dsl/generative/darwin.rb +102 -96
- data/lib/musa-dsl/generative/generative-grammar.rb +182 -187
- data/lib/musa-dsl/generative/markov.rb +56 -53
- data/lib/musa-dsl/generative/variatio.rb +234 -222
- data/lib/musa-dsl/logger.rb +1 -0
- data/lib/musa-dsl/logger/logger.rb +31 -0
- data/lib/musa-dsl/matrix.rb +1 -0
- data/lib/musa-dsl/matrix/matrix.rb +210 -0
- data/lib/musa-dsl/midi.rb +2 -2
- data/lib/musa-dsl/midi/midi-recorder.rb +54 -52
- data/lib/musa-dsl/midi/midi-voices.rb +183 -182
- data/lib/musa-dsl/music.rb +5 -5
- data/lib/musa-dsl/music/chord-definition.rb +54 -50
- data/lib/musa-dsl/music/chord-definitions.rb +13 -9
- data/lib/musa-dsl/music/chords.rb +236 -238
- data/lib/musa-dsl/music/equally-tempered-12-tone-scale-system.rb +187 -183
- data/lib/musa-dsl/music/scales.rb +331 -332
- data/lib/musa-dsl/musicxml.rb +1 -0
- data/lib/musa-dsl/musicxml/builder/attributes.rb +155 -0
- data/lib/musa-dsl/musicxml/builder/backup-forward.rb +45 -0
- data/lib/musa-dsl/musicxml/builder/direction.rb +322 -0
- data/lib/musa-dsl/musicxml/builder/helper.rb +90 -0
- data/lib/musa-dsl/musicxml/builder/measure.rb +137 -0
- data/lib/musa-dsl/musicxml/builder/note-complexities.rb +152 -0
- data/lib/musa-dsl/musicxml/builder/note.rb +577 -0
- data/lib/musa-dsl/musicxml/builder/part-group.rb +44 -0
- data/lib/musa-dsl/musicxml/builder/part.rb +67 -0
- data/lib/musa-dsl/musicxml/builder/pitched-note.rb +126 -0
- data/lib/musa-dsl/musicxml/builder/rest.rb +117 -0
- data/lib/musa-dsl/musicxml/builder/score-partwise.rb +120 -0
- data/lib/musa-dsl/musicxml/builder/typed-text.rb +43 -0
- data/lib/musa-dsl/musicxml/builder/unpitched-note.rb +112 -0
- data/lib/musa-dsl/neumalang.rb +1 -1
- data/lib/musa-dsl/neumalang/datatypes.citrus +79 -0
- data/lib/musa-dsl/neumalang/neuma.citrus +165 -0
- data/lib/musa-dsl/neumalang/neumalang.citrus +32 -242
- data/lib/musa-dsl/neumalang/neumalang.rb +373 -142
- data/lib/musa-dsl/neumalang/process.citrus +21 -0
- data/lib/musa-dsl/neumalang/terminals.citrus +67 -0
- data/lib/musa-dsl/neumalang/vectors.citrus +23 -0
- data/lib/musa-dsl/neumas.rb +5 -0
- data/lib/musa-dsl/neumas/array-to-neumas.rb +34 -0
- data/lib/musa-dsl/neumas/neuma-decoder.rb +63 -0
- data/lib/musa-dsl/neumas/neuma-gdv-decoder.rb +57 -0
- data/lib/musa-dsl/neumas/neuma-gdvd-decoder.rb +15 -0
- data/lib/musa-dsl/neumas/neumas.rb +37 -0
- data/lib/musa-dsl/neumas/string-to-neumas.rb +34 -0
- data/lib/musa-dsl/repl.rb +1 -1
- data/lib/musa-dsl/repl/repl.rb +105 -105
- data/lib/musa-dsl/sequencer.rb +1 -1
- data/lib/musa-dsl/sequencer/base-sequencer-implementation-control.rb +163 -136
- data/lib/musa-dsl/sequencer/base-sequencer-implementation-play-helper.rb +301 -286
- data/lib/musa-dsl/sequencer/base-sequencer-implementation.rb +562 -270
- data/lib/musa-dsl/sequencer/base-sequencer-public.rb +199 -199
- data/lib/musa-dsl/sequencer/base-sequencer-tick-based.rb +77 -0
- data/lib/musa-dsl/sequencer/base-sequencer-tickless-based.rb +75 -0
- data/lib/musa-dsl/sequencer/sequencer-dsl.rb +105 -85
- data/lib/musa-dsl/sequencer/timeslots.rb +34 -0
- data/lib/musa-dsl/series.rb +1 -1
- data/lib/musa-dsl/{core-ext → series}/array-to-serie.rb +1 -1
- data/lib/musa-dsl/series/base-series.rb +171 -168
- data/lib/musa-dsl/series/hash-serie-splitter.rb +134 -132
- data/lib/musa-dsl/series/holder-serie.rb +1 -1
- data/lib/musa-dsl/series/main-serie-constructors.rb +6 -1
- data/lib/musa-dsl/series/main-serie-operations.rb +807 -797
- data/lib/musa-dsl/series/proxy-serie.rb +6 -6
- data/lib/musa-dsl/series/queue-serie.rb +5 -5
- data/lib/musa-dsl/series/series.rb +2 -0
- data/lib/musa-dsl/transcription.rb +4 -0
- data/lib/musa-dsl/transcription/from-gdv-to-midi.rb +227 -0
- data/lib/musa-dsl/transcription/from-gdv-to-musicxml.rb +36 -0
- data/lib/musa-dsl/transcription/from-gdv.rb +17 -0
- data/lib/musa-dsl/transcription/transcription.rb +55 -0
- data/lib/musa-dsl/transport.rb +6 -6
- data/lib/musa-dsl/transport/clock.rb +26 -26
- data/lib/musa-dsl/transport/dummy-clock.rb +32 -30
- data/lib/musa-dsl/transport/external-tick-clock.rb +21 -20
- data/lib/musa-dsl/transport/input-midi-clock.rb +82 -80
- data/lib/musa-dsl/transport/timer-clock.rb +72 -71
- data/lib/musa-dsl/transport/timer.rb +28 -26
- data/lib/musa-dsl/transport/transport.rb +99 -95
- data/musa-dsl.gemspec +3 -3
- metadata +73 -24
- data/lib/musa-dsl/core-ext/array-apply-get.rb +0 -18
- data/lib/musa-dsl/core-ext/array-to-neumas.rb +0 -28
- data/lib/musa-dsl/core-ext/as-context-run.rb +0 -44
- data/lib/musa-dsl/core-ext/duplicate.rb +0 -134
- data/lib/musa-dsl/core-ext/key-parameters-procedure-binder.rb +0 -85
- data/lib/musa-dsl/core-ext/proc-nice.rb +0 -13
- data/lib/musa-dsl/core-ext/send-nice.rb +0 -21
- data/lib/musa-dsl/core-ext/string-to-neumas.rb +0 -27
- data/lib/musa-dsl/datasets/gdv-decorators.rb +0 -221
- data/lib/musa-dsl/generative/rules.rb +0 -282
- data/lib/musa-dsl/neuma.rb +0 -1
- data/lib/musa-dsl/neuma/neuma.rb +0 -181
data/lib/musa-dsl/sequencer.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
require_relative 'sequencer/sequencer'
|
@@ -1,189 +1,216 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module Musa
|
4
|
+
module Sequencer
|
5
|
+
class BaseSequencer
|
6
|
+
class EventHandler
|
7
|
+
include Musa::Extension::SmartProcBinder
|
7
8
|
|
8
|
-
|
9
|
+
attr_accessor :continue_parameters
|
9
10
|
|
10
|
-
|
11
|
-
capture_stdout ||= false
|
11
|
+
@@counter = 0
|
12
12
|
|
13
|
-
|
13
|
+
def initialize(parent = nil)
|
14
|
+
@id = (@@counter += 1)
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
@parent = parent
|
17
|
+
@handlers = {}
|
17
18
|
|
18
|
-
|
19
|
+
@stop = false
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
26
|
+
def stopped?
|
27
|
+
@stop
|
28
|
+
end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
def pause
|
31
|
+
raise NotImplementedError
|
32
|
+
end
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
def continue
|
35
|
+
@paused = false
|
36
|
+
end
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
def paused?
|
39
|
+
@paused
|
40
|
+
end
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
42
|
+
def on(event, name: nil, only_once: nil, &block)
|
43
|
+
only_once ||= false
|
48
44
|
|
49
|
-
|
50
|
-
only_once ||= false
|
45
|
+
@handlers[event] ||= {}
|
51
46
|
|
52
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
51
|
+
def launch(event, *value_parameters, **key_parameters)
|
52
|
+
_launch event, value_parameters, key_parameters
|
53
|
+
end
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
def _launch(event, value_parameters = nil, key_parameters = nil)
|
56
|
+
value_parameters ||= []
|
57
|
+
key_parameters ||= {}
|
58
|
+
processed = false
|
61
59
|
|
62
|
-
|
63
|
-
|
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
|
-
|
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
|
-
|
74
|
-
|
71
|
+
def inspect
|
72
|
+
"EventHandler #{id}"
|
73
|
+
end
|
75
74
|
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
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
|
-
|
89
|
-
end
|
86
|
+
private_constant :EventHandler
|
90
87
|
|
91
|
-
|
88
|
+
class PlayControl < EventHandler
|
89
|
+
attr_reader :do_after
|
92
90
|
|
93
|
-
|
94
|
-
|
91
|
+
def initialize(parent, after: nil)
|
92
|
+
super parent
|
95
93
|
|
96
|
-
|
97
|
-
super parent, capture_stdout: capture_stdout
|
94
|
+
@do_after = []
|
98
95
|
|
99
|
-
|
96
|
+
self.after &after if after
|
97
|
+
end
|
100
98
|
|
101
|
-
|
102
|
-
|
99
|
+
def pause
|
100
|
+
@paused = true
|
101
|
+
end
|
103
102
|
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
121
|
+
def after(_bars = nil, &block)
|
122
|
+
# TODO implementar parámetro _bars (?)
|
123
|
+
@do_after << block
|
124
|
+
end
|
125
|
+
end
|
125
126
|
|
126
|
-
|
127
|
-
# TODO implementar parámetro _bars (?)
|
128
|
-
@do_after << block
|
129
|
-
end
|
130
|
-
end
|
127
|
+
private_constant :PlayControl
|
131
128
|
|
132
|
-
|
129
|
+
class EveryControl < EventHandler
|
130
|
+
attr_reader :duration_value, :till_value, :condition_block, :do_on_stop, :do_after
|
133
131
|
|
134
|
-
|
135
|
-
|
132
|
+
attr_accessor :_start_position
|
133
|
+
attr_accessor :_execution_counter
|
136
134
|
|
137
|
-
|
135
|
+
def initialize(parent, duration: nil, till: nil, condition: nil, on_stop: nil, after_bars: nil, after: nil)
|
136
|
+
super parent
|
138
137
|
|
139
|
-
|
140
|
-
|
138
|
+
@duration_value = duration
|
139
|
+
@till_value = till
|
140
|
+
@condition_block = condition
|
141
141
|
|
142
|
-
|
143
|
-
|
144
|
-
@condition_block = condition
|
142
|
+
@do_on_stop = []
|
143
|
+
@do_after = []
|
145
144
|
|
146
|
-
|
147
|
-
@do_after = []
|
145
|
+
@do_on_stop << on_stop if on_stop
|
148
146
|
|
149
|
-
|
147
|
+
self.after after_bars, &after if after
|
148
|
+
end
|
150
149
|
|
151
|
-
|
152
|
-
|
150
|
+
def duration(value)
|
151
|
+
@duration_value = value.rationalize
|
152
|
+
end
|
153
153
|
|
154
|
-
|
155
|
-
|
156
|
-
|
154
|
+
def till(value)
|
155
|
+
@till_value = value.rationalize
|
156
|
+
end
|
157
157
|
|
158
|
-
|
159
|
-
|
160
|
-
|
158
|
+
def condition(&block)
|
159
|
+
@condition_block = block
|
160
|
+
end
|
161
161
|
|
162
|
-
|
163
|
-
|
164
|
-
|
162
|
+
def on_stop(&block)
|
163
|
+
@do_on_stop << block
|
164
|
+
end
|
165
165
|
|
166
|
-
|
167
|
-
|
168
|
-
|
166
|
+
def after(bars = nil, &block)
|
167
|
+
bars ||= 0
|
168
|
+
@do_after << { bars: bars.rationalize, block: block }
|
169
|
+
end
|
170
|
+
end
|
169
171
|
|
170
|
-
|
171
|
-
bars ||= 0
|
172
|
-
@do_after << { bars: bars.rationalize, block: block }
|
173
|
-
end
|
174
|
-
end
|
172
|
+
private_constant :EveryControl
|
175
173
|
|
176
|
-
|
174
|
+
class MoveControl < EventHandler
|
175
|
+
attr_reader :every_control, :do_on_stop, :do_after
|
177
176
|
|
178
|
-
|
179
|
-
|
177
|
+
def initialize(parent, duration: nil, till: nil, on_stop: nil, after_bars: nil, after: nil)
|
178
|
+
super parent
|
180
179
|
|
181
|
-
|
182
|
-
@every_control = every_control
|
183
|
-
end
|
180
|
+
@every_control = EveryControl.new(self, duration: duration, till: till)
|
184
181
|
|
185
|
-
|
186
|
-
|
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
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
27
|
-
raise NotImplementedError
|
28
|
-
end
|
29
|
-
end
|
20
|
+
attr_reader :block_procedure_binder
|
30
21
|
|
31
|
-
|
22
|
+
def subcontext
|
23
|
+
self
|
24
|
+
end
|
32
25
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
26
|
+
def eval_element(_element)
|
27
|
+
raise NotImplementedError
|
28
|
+
end
|
37
29
|
|
38
|
-
|
39
|
-
|
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
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
82
|
-
value =
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
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
|
-
|
111
|
-
|
66
|
+
class WaitModePlayEval < PlayEval
|
67
|
+
include Musa::Datasets
|
112
68
|
|
113
|
-
|
114
|
-
|
115
|
-
|
69
|
+
def initialize(block_procedure_binder)
|
70
|
+
@block_procedure_binder = block_procedure_binder
|
71
|
+
end
|
116
72
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
-
|
124
|
-
|
125
|
-
|
100
|
+
value ||= {
|
101
|
+
current_operation: :block,
|
102
|
+
current_block: @block_procedure_binder,
|
103
|
+
current_parameter: element,
|
104
|
+
continue_operation: :now
|
105
|
+
}
|
126
106
|
|
127
|
-
|
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
|
-
|
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
|
-
|
163
|
-
|
164
|
-
series.collect { |s| context.eval_serie s[:serie] }.extend Parallel
|
165
|
-
end
|
113
|
+
class NeumalangModePlayEval < PlayEval
|
114
|
+
include Musa::Datasets
|
166
115
|
|
167
|
-
|
168
|
-
_value = nil
|
116
|
+
module Parallel end
|
169
117
|
|
170
|
-
|
171
|
-
@nl_context.instance_variable_set var_name, _value = subcontext.eval_element(value)
|
172
|
-
end
|
118
|
+
@@id = 0
|
173
119
|
|
174
|
-
|
175
|
-
|
120
|
+
attr_reader :nl_context
|
121
|
+
attr_reader :block_procedure_binder
|
176
122
|
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
186
|
-
|
187
|
-
|
127
|
+
@block_procedure_binder = block_procedure_binder
|
128
|
+
@decoder = decoder
|
129
|
+
@nl_context = nl_context
|
188
130
|
|
189
|
-
|
190
|
-
|
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
|
-
|
198
|
-
|
199
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
240
|
-
|
241
|
-
|
242
|
-
continue_operation: :wait,
|
243
|
-
continue_parameter: element[:duration] }
|
164
|
+
def eval_gdvd(gdvd)
|
165
|
+
@decoder.decode(gdvd)
|
166
|
+
end
|
244
167
|
|
245
|
-
|
246
|
-
|
247
|
-
|
168
|
+
def eval_p(p)
|
169
|
+
p.to_ps_serie(@decoder.base_duration).instance
|
170
|
+
end
|
248
171
|
|
249
|
-
|
250
|
-
|
251
|
-
|
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
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
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
|
-
|
182
|
+
def eval_assign_to(variable_names, value)
|
183
|
+
_value = nil
|
261
184
|
|
262
|
-
|
263
|
-
|
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
|
-
|
274
|
-
|
189
|
+
_value
|
190
|
+
end
|
275
191
|
|
276
|
-
|
277
|
-
|
278
|
-
|
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
|
-
{
|
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
|
-
|
287
|
-
|
288
|
-
{
|
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
|
-
|
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
|
-
|
301
|
-
|
210
|
+
def eval_call_methods(on, call_methods)
|
211
|
+
play_eval = subcontext
|
302
212
|
|
303
|
-
|
213
|
+
value = play_eval.eval_element on
|
304
214
|
|
305
|
-
|
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
|
-
|
221
|
+
_value = _value.send methd[:method], *value_parameters, **key_parameters
|
222
|
+
end
|
308
223
|
|
309
|
-
|
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
|
-
|
312
|
-
|
231
|
+
value = value.send methd[:method], *value_parameters, **key_parameters
|
232
|
+
end
|
313
233
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
current_key_parameters: key_parameters,
|
318
|
-
continue_operation: :now }
|
234
|
+
value
|
235
|
+
end
|
236
|
+
end
|
319
237
|
|
320
|
-
|
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
|
-
|
251
|
+
def run_operation(element)
|
252
|
+
case element
|
253
|
+
when nil
|
254
|
+
{ current_operation: :none,
|
255
|
+
continue_operation: :now }
|
323
256
|
|
324
|
-
|
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
|
-
|
263
|
+
when Musa::Series::Serie
|
264
|
+
{ current_operation: :play,
|
265
|
+
current_parameter: element.restart }
|
327
266
|
|
328
|
-
|
267
|
+
when Parallel
|
268
|
+
{ current_operation: :parallel_play,
|
269
|
+
current_parameter: element.tap { |e| e.each(&:restart) } }
|
329
270
|
|
330
|
-
|
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
|
-
|
333
|
-
|
351
|
+
def inspect
|
352
|
+
"NeumalangModePlayEval #{id} #{@decoder}"
|
334
353
|
end
|
335
|
-
end
|
336
|
-
end
|
337
354
|
|
338
|
-
|
339
|
-
|
340
|
-
|
355
|
+
def id
|
356
|
+
if @parent
|
357
|
+
"#{@parent.id}.#{@id}"
|
358
|
+
else
|
359
|
+
@id.to_s
|
360
|
+
end
|
361
|
+
end
|
341
362
|
|
342
|
-
|
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
|
-
|
366
|
+
private_constant :NeumalangModePlayEval
|
367
|
+
end
|
351
368
|
end
|
352
|
-
|
353
|
-
private_constant :NeumalangModePlayEval
|
354
369
|
end
|