musa-dsl 0.23.8 → 0.23.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/musa-dsl/core-ext/with.rb +4 -3
- data/lib/musa-dsl/datasets/gdv.rb +2 -2
- data/lib/musa-dsl/datasets/gdvd.rb +2 -1
- data/lib/musa-dsl/datasets/helper.rb +1 -1
- data/lib/musa-dsl/datasets/score/queriable.rb +43 -42
- data/lib/musa-dsl/datasets/score/render.rb +24 -20
- data/lib/musa-dsl/datasets/score/to-mxml/to-mxml.rb +120 -122
- data/lib/musa-dsl/generative/backboner.rb +2 -2
- data/lib/musa-dsl/generative/generative-grammar.rb +2 -0
- data/lib/musa-dsl/generative/markov.rb +1 -2
- data/lib/musa-dsl/generative/variatio.rb +6 -10
- data/lib/musa-dsl/logger/logger.rb +22 -22
- data/lib/musa-dsl/matrix/matrix.rb +3 -5
- data/lib/musa-dsl/midi/midi-recorder.rb +3 -4
- data/lib/musa-dsl/midi/midi-voices.rb +3 -3
- data/lib/musa-dsl/music/chords.rb +26 -29
- data/lib/musa-dsl/musicxml/builder/direction.rb +2 -2
- data/lib/musa-dsl/neumalang/neumalang.rb +25 -67
- data/lib/musa-dsl/neumas/array-to-neumas.rb +2 -2
- data/lib/musa-dsl/repl/repl.rb +1 -1
- data/lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb +12 -11
- data/lib/musa-dsl/sequencer/base-sequencer-implementation-move.rb +53 -52
- data/lib/musa-dsl/sequencer/base-sequencer-implementation-play-helper.rb +2 -4
- data/lib/musa-dsl/sequencer/base-sequencer-implementation-play-timed.rb +43 -39
- data/lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb +5 -7
- data/lib/musa-dsl/sequencer/base-sequencer-implementation.rb +6 -14
- data/lib/musa-dsl/sequencer/base-sequencer-tick-based.rb +4 -3
- data/lib/musa-dsl/sequencer/base-sequencer.rb +5 -5
- data/lib/musa-dsl/sequencer/sequencer-dsl.rb +11 -6
- data/lib/musa-dsl/series/array-to-serie.rb +5 -3
- data/lib/musa-dsl/series/base-series.rb +2 -2
- data/lib/musa-dsl/series/buffer-serie.rb +0 -5
- data/lib/musa-dsl/series/main-serie-constructors.rb +16 -6
- data/lib/musa-dsl/series/main-serie-operations.rb +2 -2
- data/lib/musa-dsl/series/quantizer-serie.rb +47 -51
- data/lib/musa-dsl/series/series-composer.rb +16 -6
- data/lib/musa-dsl/series/timed-serie.rb +49 -48
- data/lib/musa-dsl/transcription/from-gdv-to-midi.rb +5 -7
- data/lib/musa-dsl/transcription/from-gdv-to-musicxml.rb +1 -4
- data/lib/musa-dsl/transcription/from-gdv.rb +1 -3
- data/lib/musa-dsl/transcription/transcription.rb +2 -4
- data/lib/musa-dsl/transport/input-midi-clock.rb +7 -4
- data/lib/musa-dsl/transport/transport.rb +10 -12
- data/lib/musa-dsl.rb +1 -1
- data/musa-dsl.gemspec +2 -2
- metadata +2 -2
@@ -97,19 +97,19 @@ module Musa
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def on_debug_at(&block)
|
100
|
-
@on_debug_at << SmartProcBinder.new(block)
|
100
|
+
@on_debug_at << Musa::Extension::SmartProcBinder::SmartProcBinder.new(block)
|
101
101
|
end
|
102
102
|
|
103
103
|
def on_error(&block)
|
104
|
-
@on_error << SmartProcBinder.new(block)
|
104
|
+
@on_error << Musa::Extension::SmartProcBinder::SmartProcBinder.new(block)
|
105
105
|
end
|
106
106
|
|
107
107
|
def on_fast_forward(&block)
|
108
|
-
@on_fast_forward << SmartProcBinder.new(block)
|
108
|
+
@on_fast_forward << Musa::Extension::SmartProcBinder::SmartProcBinder.new(block)
|
109
109
|
end
|
110
110
|
|
111
111
|
def before_tick(&block)
|
112
|
-
@before_tick << SmartProcBinder.new(block)
|
112
|
+
@before_tick << Musa::Extension::SmartProcBinder::SmartProcBinder.new(block)
|
113
113
|
end
|
114
114
|
|
115
115
|
def on(event, &block)
|
@@ -132,7 +132,7 @@ module Musa
|
|
132
132
|
bars_delay = Series::S(*bars_delay) if bars_delay.is_a?(Array)
|
133
133
|
bars_delay = bars_delay.instance if bars_delay
|
134
134
|
|
135
|
-
_serie_at bars_delay.
|
135
|
+
_serie_at bars_delay.with { |delay| position + delay }, control, debug: debug, &block
|
136
136
|
end
|
137
137
|
|
138
138
|
@event_handlers.pop
|
@@ -18,7 +18,7 @@ module Musa
|
|
18
18
|
:event_handler
|
19
19
|
|
20
20
|
def_delegators :@dsl, :position, :quantize_position, :logger, :debug
|
21
|
-
def_delegators :@dsl, :
|
21
|
+
def_delegators :@dsl, :now, :at, :wait, :play, :play_timed, :every, :move
|
22
22
|
def_delegators :@dsl, :everying, :playing, :moving
|
23
23
|
def_delegators :@dsl, :launch, :on
|
24
24
|
def_delegators :@dsl, :run
|
@@ -28,6 +28,7 @@ module Musa
|
|
28
28
|
sequencer: nil,
|
29
29
|
logger: nil,
|
30
30
|
do_log: nil, do_error_log: nil, log_position_format: nil,
|
31
|
+
keep_proc_context: nil,
|
31
32
|
&block)
|
32
33
|
|
33
34
|
@sequencer = sequencer
|
@@ -37,14 +38,17 @@ module Musa
|
|
37
38
|
do_error_log: do_error_log,
|
38
39
|
log_position_format: log_position_format
|
39
40
|
|
40
|
-
@dsl = DSLContext.new @sequencer
|
41
|
+
@dsl = DSLContext.new @sequencer, keep_proc_context: keep_proc_context
|
41
42
|
|
42
|
-
with &block if block_given?
|
43
|
+
@dsl.with &block if block_given?
|
44
|
+
end
|
45
|
+
|
46
|
+
def with(&block)
|
47
|
+
@dsl.with &block
|
43
48
|
end
|
44
49
|
|
45
50
|
class DSLContext
|
46
51
|
extend Forwardable
|
47
|
-
include Musa::Extension::SmartProcBinder
|
48
52
|
include Musa::Extension::With
|
49
53
|
|
50
54
|
attr_reader :sequencer
|
@@ -57,8 +61,9 @@ module Musa
|
|
57
61
|
:ticks_per_bar, :logger, :debug, :inspect,
|
58
62
|
:run
|
59
63
|
|
60
|
-
def initialize(sequencer)
|
64
|
+
def initialize(sequencer, keep_proc_context:)
|
61
65
|
@sequencer = sequencer
|
66
|
+
@keep_proc_context_on_with = keep_proc_context
|
62
67
|
end
|
63
68
|
|
64
69
|
def now(*value_parameters, **key_parameters, &block)
|
@@ -104,7 +109,7 @@ module Musa
|
|
104
109
|
block ||= proc {}
|
105
110
|
|
106
111
|
@sequencer.every *value_parameters, **key_parameters do |*value_args, **key_args|
|
107
|
-
args = SmartProcBinder.new(block)._apply(value_args, key_args)
|
112
|
+
args = Musa::Extension::SmartProcBinder::SmartProcBinder.new(block)._apply(value_args, key_args)
|
108
113
|
with *args.first, **args.last, &block
|
109
114
|
end
|
110
115
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require_relative '../series'
|
2
2
|
|
3
|
+
# TODO: esto sería un refinement, no?
|
4
|
+
|
3
5
|
class Array
|
4
6
|
def to_serie(of_series: nil, recursive: nil)
|
5
7
|
of_series ||= false
|
@@ -8,11 +10,11 @@ class Array
|
|
8
10
|
raise ArgumentError, 'Cannot convert to serie of_series and recursive simultaneously' if recursive && of_series
|
9
11
|
|
10
12
|
if recursive
|
11
|
-
S(*(collect { |_| _.is_a?(Array) ? _.to_serie(recursive: true) : _ }))
|
13
|
+
Musa::Series::Constructors.S(*(collect { |_| _.is_a?(Array) ? _.to_serie(recursive: true) : _ }))
|
12
14
|
elsif of_series
|
13
|
-
S(*(collect { |_| S(*_) }))
|
15
|
+
Musa::Series::Constructors.S(*(collect { |_| Musa::Series::Constructors.S(*_) }))
|
14
16
|
else
|
15
|
-
S(*self)
|
17
|
+
Musa::Series::Constructors.S(*self)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require_relative '../core-ext/deep-copy'
|
2
2
|
require_relative '../generative/generative-grammar'
|
3
3
|
|
4
|
-
using Musa::Extension::DeepCopy
|
5
|
-
|
6
4
|
module Musa
|
7
5
|
module Series
|
8
6
|
module Constructors; extend self; end
|
@@ -338,6 +336,8 @@ module Musa
|
|
338
336
|
include Prototyping
|
339
337
|
include Operations
|
340
338
|
|
339
|
+
using Musa::Extension::DeepCopy
|
340
|
+
|
341
341
|
def init
|
342
342
|
@_have_peeked_next_value = false
|
343
343
|
@_peeked_next_value = nil
|
@@ -206,11 +206,6 @@ module Musa
|
|
206
206
|
@index -= offset
|
207
207
|
end
|
208
208
|
|
209
|
-
# private def _init
|
210
|
-
# @source.prototype.singleton._register(self) if instance?
|
211
|
-
# @index = @last_nil_index
|
212
|
-
# end
|
213
|
-
#
|
214
209
|
private def _sources_resolved
|
215
210
|
@source.singleton._register(self) if instance?
|
216
211
|
@index = @last_nil_index
|
@@ -3,13 +3,12 @@ require_relative '../core-ext/smart-proc-binder'
|
|
3
3
|
|
4
4
|
require_relative 'base-series'
|
5
5
|
|
6
|
-
using Musa::Extension::Arrayfy
|
7
|
-
using Musa::Extension::ExplodeRanges
|
8
|
-
|
9
6
|
# TODO: añadir en for: steps: (nº de pasos en los que repartir el incremento)
|
10
7
|
|
11
8
|
module Musa
|
12
9
|
module Series::Constructors
|
10
|
+
using Musa::Extension::ExplodeRanges
|
11
|
+
|
13
12
|
def UNDEFINED
|
14
13
|
UndefinedSerie.new
|
15
14
|
end
|
@@ -48,10 +47,14 @@ module Musa
|
|
48
47
|
ForLoop.new from, to, step
|
49
48
|
end
|
50
49
|
|
51
|
-
def RND(*values, from: nil, to: nil, step: nil, random: nil)
|
50
|
+
def RND(*_values, values: nil, from: nil, to: nil, step: nil, random: nil)
|
51
|
+
raise ArgumentError, "Can't use both direct values #{_values} and values named parameter #{values} at the same time." if values && !_values.empty?
|
52
|
+
|
52
53
|
random = Random.new random if random.is_a?(Integer)
|
53
54
|
random ||= Random.new
|
54
55
|
|
56
|
+
values ||= _values
|
57
|
+
|
55
58
|
if !values.empty? && from.nil? && to.nil? && step.nil?
|
56
59
|
RandomValuesFromArray.new values.explode_ranges, random
|
57
60
|
elsif values.empty? && !to.nil?
|
@@ -67,10 +70,14 @@ module Musa
|
|
67
70
|
Sequence.new(series)
|
68
71
|
end
|
69
72
|
|
70
|
-
def RND1(*values, from: nil, to: nil, step: nil, random: nil)
|
73
|
+
def RND1(*_values, values: nil, from: nil, to: nil, step: nil, random: nil)
|
74
|
+
raise ArgumentError, "Can't use both direct values #{_values} and values named parameter #{values} at the same time." if values && !_values.empty?
|
75
|
+
|
71
76
|
random = Random.new random if random.is_a?(Integer)
|
72
77
|
random ||= Random.new
|
73
78
|
|
79
|
+
values ||= _values
|
80
|
+
|
74
81
|
if !values.empty? && from.nil? && to.nil? && step.nil?
|
75
82
|
RandomValueFromArray.new values.explode_ranges, random
|
76
83
|
elsif values.empty? && !to.nil?
|
@@ -111,7 +118,8 @@ module Musa
|
|
111
118
|
end
|
112
119
|
end
|
113
120
|
|
114
|
-
|
121
|
+
# UndefinedSerie is not private because is used in Composer
|
122
|
+
# private_constant :UndefinedSerie
|
115
123
|
|
116
124
|
class NilSerie
|
117
125
|
include Series::Serie.base
|
@@ -128,6 +136,8 @@ module Musa
|
|
128
136
|
class FromArray
|
129
137
|
include Series::Serie.base
|
130
138
|
|
139
|
+
using Musa::Extension::Arrayfy
|
140
|
+
|
131
141
|
def initialize(values = nil, extends = nil)
|
132
142
|
@values = values
|
133
143
|
mark_as_prototype!
|
@@ -84,11 +84,11 @@ module Musa
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def after(*series)
|
87
|
-
|
87
|
+
Musa::Series::Constructors.MERGE self, *series
|
88
88
|
end
|
89
89
|
|
90
90
|
def +(other)
|
91
|
-
|
91
|
+
Musa::Series::Constructors.MERGE self, other
|
92
92
|
end
|
93
93
|
|
94
94
|
def cut(length)
|
@@ -4,8 +4,6 @@ require_relative '../core-ext/inspect-nice'
|
|
4
4
|
require_relative 'base-series'
|
5
5
|
|
6
6
|
# TODO remove debugging puts, intermediate hash comments on :info and InspectNice
|
7
|
-
using Musa::Extension::InspectNice
|
8
|
-
|
9
7
|
module Musa
|
10
8
|
module Series::Operations
|
11
9
|
def quantize(reference: nil, step: nil,
|
@@ -15,7 +13,7 @@ module Musa
|
|
15
13
|
left_open: nil,
|
16
14
|
right_open: nil)
|
17
15
|
|
18
|
-
Series.QUANTIZE(self,
|
16
|
+
Series::Constructors.QUANTIZE(self,
|
19
17
|
reference: reference,
|
20
18
|
step: step,
|
21
19
|
value_attribute: value_attribute,
|
@@ -70,7 +68,7 @@ module Musa
|
|
70
68
|
time = n[0].rationalize
|
71
69
|
value = n[1].rationalize
|
72
70
|
else
|
73
|
-
raise
|
71
|
+
raise "Don't know how to process #{n}"
|
74
72
|
end
|
75
73
|
|
76
74
|
return time, value
|
@@ -115,9 +113,8 @@ module Musa
|
|
115
113
|
end
|
116
114
|
|
117
115
|
private def _next_value
|
116
|
+
i = 2
|
118
117
|
if @stops
|
119
|
-
i = 2
|
120
|
-
|
121
118
|
loop do
|
122
119
|
while @segments.size < i && process2; end
|
123
120
|
|
@@ -142,17 +139,16 @@ module Musa
|
|
142
139
|
return { time: first[:time],
|
143
140
|
@value_attribute => first[:value],
|
144
141
|
duration: durations_to_sum.sum { |_| _[:duration] } }
|
145
|
-
|
146
|
-
|
142
|
+
.extend(Musa::Datasets::AbsTimed)
|
143
|
+
.extend(Musa::Datasets::AbsD)
|
147
144
|
else
|
148
145
|
i += 1
|
149
146
|
end
|
150
147
|
end
|
151
148
|
|
152
|
-
|
149
|
+
nil
|
153
150
|
|
154
151
|
else
|
155
|
-
i = 2
|
156
152
|
# puts "\n\n"
|
157
153
|
loop do
|
158
154
|
while @segments.size < i && process2; end
|
@@ -179,8 +175,8 @@ module Musa
|
|
179
175
|
return { time: first[:time],
|
180
176
|
@value_attribute => first[:value],
|
181
177
|
duration: durations_to_sum.sum { |_| _[:duration] } }
|
182
|
-
|
183
|
-
|
178
|
+
.extend(Musa::Datasets::AbsTimed)
|
179
|
+
.extend(Musa::Datasets::AbsD)
|
184
180
|
else
|
185
181
|
i += 1
|
186
182
|
end
|
@@ -211,7 +207,7 @@ module Musa
|
|
211
207
|
|
212
208
|
# puts "process2: from_time #{from_time} from_value #{from_value} to_time #{to_time} to_value #{to_value} to_last #{to_point_is_last || 'nil'} sign #{sign}"
|
213
209
|
|
214
|
-
if sign
|
210
|
+
if sign.zero?
|
215
211
|
if @segments.last && @segments.last[:time] == from_time
|
216
212
|
|
217
213
|
@segments.last[:duration] = to_time - from_time
|
@@ -261,8 +257,8 @@ module Musa
|
|
261
257
|
|
262
258
|
loop_from_value.step(loop_to_value, step_value_increment) do |value|
|
263
259
|
if @segments.last &&
|
264
|
-
|
265
|
-
|
260
|
+
@segments.last[:time] == intermediate_point_time &&
|
261
|
+
@segments.last[:value] == value
|
266
262
|
|
267
263
|
@segments.last[:duration] = step_time_increment
|
268
264
|
@segments.last[:info] += '; edited on b'
|
@@ -294,7 +290,7 @@ module Musa
|
|
294
290
|
|
295
291
|
private def process(time, value, last_time_value)
|
296
292
|
if time && value
|
297
|
-
raise
|
293
|
+
raise 'time only can go forward' if @last_processed_time && time <= @last_processed_time
|
298
294
|
|
299
295
|
q_value = round_quantize(value)
|
300
296
|
|
@@ -399,23 +395,23 @@ module Musa
|
|
399
395
|
if @first
|
400
396
|
@first = false
|
401
397
|
|
402
|
-
if time > first_time
|
403
|
-
|
398
|
+
result = if time > first_time
|
399
|
+
{ time: first_time,
|
404
400
|
@value_attribute => round_to_nearest_quantize(first_value, value),
|
405
401
|
duration: time - first_time }
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
402
|
+
.extend(Musa::Datasets::AbsD)
|
403
|
+
.extend(Musa::Datasets::AbsTimed)
|
404
|
+
else
|
405
|
+
_next_value
|
406
|
+
end
|
411
407
|
else
|
412
408
|
if @crossings[1]
|
413
409
|
next_time = @crossings[1][:time]
|
414
410
|
result = { time: time,
|
415
411
|
@value_attribute => value,
|
416
412
|
duration: next_time - time }
|
417
|
-
|
418
|
-
|
413
|
+
.extend(Musa::Datasets::AbsD)
|
414
|
+
.extend(Musa::Datasets::AbsTimed)
|
419
415
|
|
420
416
|
@crossings.shift
|
421
417
|
|
@@ -424,8 +420,8 @@ module Musa
|
|
424
420
|
result = { time: @crossings[0][:time],
|
425
421
|
@value_attribute => @crossings[0][@value_attribute],
|
426
422
|
duration: @last_time - @crossings[0][:time] }
|
427
|
-
|
428
|
-
|
423
|
+
.extend(Musa::Datasets::AbsD)
|
424
|
+
.extend(Musa::Datasets::AbsTimed)
|
429
425
|
|
430
426
|
@last_time = nil
|
431
427
|
end
|
@@ -436,8 +432,8 @@ module Musa
|
|
436
432
|
result = { time: first_time,
|
437
433
|
value: round_to_nearest_quantize(first_value),
|
438
434
|
duration: @last_time - first_time }
|
439
|
-
|
440
|
-
|
435
|
+
.extend(Musa::Datasets::AbsD)
|
436
|
+
.extend(Musa::Datasets::AbsTimed)
|
441
437
|
|
442
438
|
@first = false
|
443
439
|
@last_time = false
|
@@ -453,8 +449,8 @@ module Musa
|
|
453
449
|
if @last_time.nil? || c[:time] > @last_time
|
454
450
|
|
455
451
|
if c[:stop] &&
|
456
|
-
|
457
|
-
|
452
|
+
@crossings.dig(-1, :stop) &&
|
453
|
+
@crossings.dig(-1, @value_attribute) == c[@value_attribute]
|
458
454
|
|
459
455
|
c[:stops] = (@crossings[-1][:stops] || 0) + 1
|
460
456
|
|
@@ -473,7 +469,7 @@ module Musa
|
|
473
469
|
from_time, from_value = get_time_value(@source.next_value)
|
474
470
|
|
475
471
|
if from_time && from_value
|
476
|
-
raise
|
472
|
+
raise 'time only can go forward' if @last_time && from_time <= @last_time
|
477
473
|
|
478
474
|
@last_time = from_time
|
479
475
|
|
@@ -500,36 +496,36 @@ module Musa
|
|
500
496
|
delta_time = to_time - from_time
|
501
497
|
|
502
498
|
crossings =
|
503
|
-
|
504
|
-
|
499
|
+
from_step.step(last_step, sign).collect do |i|
|
500
|
+
value = @crossing_reference + i * @step_size
|
505
501
|
|
506
|
-
|
507
|
-
|
508
|
-
|
502
|
+
{ time: from_time + (delta_time / delta_value) * (value - from_value),
|
503
|
+
@value_attribute => value + sign * @halfway_offset }
|
504
|
+
end
|
509
505
|
|
510
506
|
if @include_stops
|
511
507
|
first_crossing_time = crossings.dig(0, :time)
|
512
508
|
last_crossing_time = crossings.dig(-1, :time)
|
513
509
|
|
514
|
-
if first_crossing_time.nil? || from_time < first_crossing_time
|
515
|
-
|
510
|
+
stop_before = if first_crossing_time.nil? || from_time < first_crossing_time
|
511
|
+
[ { time: from_time,
|
516
512
|
@value_attribute =>
|
517
|
-
|
518
|
-
|
513
|
+
round_to_nearest_quantize(from_value,
|
514
|
+
crossings.dig(0, @value_attribute)),
|
519
515
|
stop: true } ]
|
520
|
-
|
521
|
-
|
522
|
-
|
516
|
+
else
|
517
|
+
[]
|
518
|
+
end
|
523
519
|
|
524
|
-
if last_crossing_time.nil? || to_time > last_crossing_time
|
525
|
-
|
520
|
+
stop_after = if last_crossing_time.nil? || to_time > last_crossing_time
|
521
|
+
[ { time: to_time,
|
526
522
|
@value_attribute =>
|
527
|
-
|
528
|
-
|
523
|
+
round_to_nearest_quantize(to_value,
|
524
|
+
crossings.dig(-1, @value_attribute)),
|
529
525
|
stop: true } ]
|
530
|
-
|
531
|
-
|
532
|
-
|
526
|
+
else
|
527
|
+
[]
|
528
|
+
end
|
533
529
|
|
534
530
|
stop_before + crossings + stop_after
|
535
531
|
else
|