musa-dsl 0.23.14 → 0.23.18
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/smart-proc-binder.rb +2 -2
- data/lib/musa-dsl/core-ext/with.rb +3 -5
- data/lib/musa-dsl/neumalang/neumalang.rb +1 -1
- data/lib/musa-dsl/series/main-serie-operations.rb +72 -19
- data/lib/musa-dsl/series/quantizer-serie.rb +10 -7
- data/lib/musa-dsl/transport/timer-clock.rb +3 -2
- data/lib/musa-dsl/transport/timer.rb +7 -1
- data/lib/musa-dsl.rb +1 -1
- data/musa-dsl.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b3da8a6794922e430f83799de2679402d3bfefda3208fa1788f0beedb1ae55e
|
4
|
+
data.tar.gz: 8583d5e0e518ff221cdf8b3f7cd6bc96ffe5a2c8b6c86ae53eb7d339b2a0eabd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06642f37659b697dca34396cca40aaa0ee30788cb2905e29ae9e2be16d3df570e1195996d50b81d10506059b37ef319f0c7c0aec8ccf789a35dc5d4734ba19ce
|
7
|
+
data.tar.gz: bd2c24988b5f1ef6e11d3b426de27a8ed46a9ca14f08f4d7eb1fbcff95e6854f839bb369e716c3ed05b393852571440bffbb223e2d3333a82900b62ffd0ce0db
|
@@ -33,7 +33,7 @@ module Musa
|
|
33
33
|
_call value_parameters, key_parameters
|
34
34
|
end
|
35
35
|
|
36
|
-
def _call(value_parameters, key_parameters)
|
36
|
+
def _call(value_parameters, key_parameters = {})
|
37
37
|
if @on_rescue
|
38
38
|
begin
|
39
39
|
__call value_parameters, key_parameters
|
@@ -45,7 +45,7 @@ module Musa
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
private def __call(value_parameters, key_parameters)
|
48
|
+
private def __call(value_parameters, key_parameters = {})
|
49
49
|
effective_value_parameters, effective_key_parameters = apply(*value_parameters, **key_parameters)
|
50
50
|
|
51
51
|
if effective_key_parameters.empty?
|
@@ -19,12 +19,10 @@ module Musa
|
|
19
19
|
else
|
20
20
|
binder.call(*effective_value_parameters, **effective_key_parameters)
|
21
21
|
end
|
22
|
+
elsif effective_value_parameters.empty? && effective_key_parameters.empty?
|
23
|
+
instance_eval &block
|
22
24
|
else
|
23
|
-
|
24
|
-
instance_eval &block
|
25
|
-
else
|
26
|
-
instance_exec *effective_value_parameters, **effective_key_parameters, &block
|
27
|
-
end
|
25
|
+
instance_exec *effective_value_parameters, **effective_key_parameters, &block
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
@@ -20,7 +20,7 @@ module Musa
|
|
20
20
|
def value
|
21
21
|
{ kind: :parallel,
|
22
22
|
parallel: [{ kind: :serie,
|
23
|
-
serie: S(*capture(:aa).value) }] +
|
23
|
+
serie: Musa::Series::Constructors.S(*capture(:aa).value) }] +
|
24
24
|
captures(:bb).collect { |c| { kind: :serie, serie: Musa::Series::Constructors.S(*c.value) } }
|
25
25
|
}.extend(Musa::Neumas::Neuma::Parallel)
|
26
26
|
end
|
@@ -101,15 +101,28 @@ module Musa
|
|
101
101
|
|
102
102
|
# TODO on with and map methods implement parameter passing with cloning on restart as on E()
|
103
103
|
#
|
104
|
-
def with(
|
105
|
-
|
106
|
-
|
104
|
+
def with(*with_series, on_restart: nil, isolate_values: nil, **with_key_series, &block)
|
105
|
+
if with_series.any? && with_key_series.any?
|
106
|
+
raise ArgumentError, 'Can\'t use extra parameters series and key named parameters series'
|
107
|
+
end
|
108
|
+
|
109
|
+
extra_series = if with_series.any?
|
110
|
+
with_series
|
111
|
+
elsif with_key_series.any?
|
112
|
+
with_key_series
|
113
|
+
end
|
114
|
+
|
115
|
+
isolate_values ||= isolate_values.nil? ? true : isolate_values
|
116
|
+
|
117
|
+
ProcessWith.new self, extra_series, on_restart, isolate_values: isolate_values, &block
|
107
118
|
end
|
108
119
|
|
109
120
|
alias_method :eval, :with
|
110
121
|
|
111
|
-
def map(&block)
|
112
|
-
|
122
|
+
def map(isolate_values: nil, &block)
|
123
|
+
isolate_values ||= isolate_values.nil? ? false : isolate_values
|
124
|
+
|
125
|
+
ProcessWith.new self, isolate_values: isolate_values, &block
|
113
126
|
end
|
114
127
|
|
115
128
|
def anticipate(&block)
|
@@ -129,12 +142,16 @@ module Musa
|
|
129
142
|
sources: true, sources_as: :with_sources, mandatory_sources: false,
|
130
143
|
smart_block: true)
|
131
144
|
|
132
|
-
|
145
|
+
using Musa::Extension::Arrayfy
|
146
|
+
|
147
|
+
def initialize(serie, with_series = nil, on_restart = nil, isolate_values: nil, &block)
|
133
148
|
self.source = serie
|
134
|
-
self.with_sources = with_series ||
|
149
|
+
self.with_sources = with_series || []
|
135
150
|
self.on_restart = on_restart
|
136
151
|
self.proc = block if block
|
137
152
|
|
153
|
+
@isolate_values = isolate_values
|
154
|
+
|
138
155
|
init
|
139
156
|
end
|
140
157
|
|
@@ -152,21 +169,59 @@ module Musa
|
|
152
169
|
|
153
170
|
private def _restart
|
154
171
|
@source.restart
|
155
|
-
|
172
|
+
|
173
|
+
case @sources
|
174
|
+
when Array
|
175
|
+
@sources.each(&:restart)
|
176
|
+
when Hash
|
177
|
+
@sources.each_value(&:restart)
|
178
|
+
end
|
179
|
+
|
156
180
|
@on_restart.call if @on_restart
|
157
181
|
end
|
158
182
|
|
159
183
|
private def _next_value
|
160
184
|
main = @source.next_value
|
161
|
-
|
185
|
+
|
186
|
+
others = case @sources
|
187
|
+
when Array
|
188
|
+
@sources.map(&:next_value)
|
189
|
+
when Hash
|
190
|
+
@sources.transform_values(&:next_value)
|
191
|
+
end
|
162
192
|
|
163
193
|
value = nil
|
164
194
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
195
|
+
|
196
|
+
if main
|
197
|
+
case others
|
198
|
+
when Array
|
199
|
+
unless others.include?(nil)
|
200
|
+
value = if @block
|
201
|
+
if @isolate_values
|
202
|
+
raise ArgumentError, "Received 'with_sources' as an Array and asked to 'isolate_values'. This can't be done. Please, set 'isolate_values' to false or make with_sources to be a Hash." if others.any?
|
203
|
+
|
204
|
+
@block._call([main])
|
205
|
+
else
|
206
|
+
@block._call(main.arrayfy + others)
|
207
|
+
end
|
208
|
+
else
|
209
|
+
if @isolate_values
|
210
|
+
[main, others]
|
211
|
+
else
|
212
|
+
main.arrayfy + others
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
when Hash
|
218
|
+
unless others.values.include?(nil)
|
219
|
+
value = if @block
|
220
|
+
@block._call(main, others)
|
221
|
+
else
|
222
|
+
[main, others]
|
223
|
+
end
|
224
|
+
end
|
170
225
|
end
|
171
226
|
end
|
172
227
|
|
@@ -243,7 +298,7 @@ module Musa
|
|
243
298
|
end
|
244
299
|
|
245
300
|
def infinite?
|
246
|
-
@source.infinite? && @sources.any?
|
301
|
+
@source.infinite? && @sources.any?(&:infinite?)
|
247
302
|
end
|
248
303
|
end
|
249
304
|
|
@@ -287,7 +342,7 @@ module Musa
|
|
287
342
|
end
|
288
343
|
|
289
344
|
def infinite?
|
290
|
-
@source.infinite? && @sources.any?
|
345
|
+
@source.infinite? && @sources.any?(&:infinite?)
|
291
346
|
end
|
292
347
|
end
|
293
348
|
|
@@ -641,9 +696,7 @@ module Musa
|
|
641
696
|
else
|
642
697
|
value = @pending_values.shift
|
643
698
|
|
644
|
-
if value.nil?
|
645
|
-
value = _next_value
|
646
|
-
end
|
699
|
+
value = _next_value if value.nil?
|
647
700
|
|
648
701
|
value
|
649
702
|
end
|
@@ -468,16 +468,19 @@ module Musa
|
|
468
468
|
private def next_crossings
|
469
469
|
from_time, from_value = get_time_value(@source.next_value)
|
470
470
|
|
471
|
-
|
472
|
-
raise 'time only can go forward' if @last_time && from_time <= @last_time
|
471
|
+
return unless from_time && from_value
|
473
472
|
|
474
|
-
|
473
|
+
if @last_time && from_time < @last_time
|
474
|
+
raise "time only can go forward: last time = #{@last_time} (#{@last_time.to_f}) but " \
|
475
|
+
"from_time = #{from_time} (#{from_time.to_f}) (expected last_time to be < from_time) "
|
476
|
+
end
|
475
477
|
|
476
|
-
|
478
|
+
@last_time = from_time
|
477
479
|
|
478
|
-
|
479
|
-
|
480
|
-
|
480
|
+
to_time, to_value = get_time_value(@source.peek_next_value)
|
481
|
+
|
482
|
+
if to_time && to_value
|
483
|
+
crossings(from_time, from_value, to_time, to_value)
|
481
484
|
end
|
482
485
|
end
|
483
486
|
|
@@ -3,7 +3,7 @@ require_relative 'clock'
|
|
3
3
|
module Musa
|
4
4
|
module Clock
|
5
5
|
class TimerClock < Clock
|
6
|
-
def initialize(period = nil, ticks_per_beat: nil, bpm: nil, correction: nil, do_log: nil)
|
6
|
+
def initialize(period = nil, ticks_per_beat: nil, bpm: nil, correction: nil, logger: nil, do_log: nil)
|
7
7
|
do_log ||= false
|
8
8
|
|
9
9
|
super()
|
@@ -20,6 +20,7 @@ module Musa
|
|
20
20
|
@started = false
|
21
21
|
@paused = false
|
22
22
|
|
23
|
+
@logger = logger
|
23
24
|
@do_log = do_log
|
24
25
|
end
|
25
26
|
|
@@ -55,7 +56,7 @@ module Musa
|
|
55
56
|
@run = true
|
56
57
|
|
57
58
|
while @run
|
58
|
-
@timer = Timer.new(@period, correction: @correction, stop: true)
|
59
|
+
@timer = Timer.new(@period, correction: @correction, stop: true, logger: @logger, do_log: @do_log)
|
59
60
|
|
60
61
|
@timer.run do
|
61
62
|
yield if block_given?
|
@@ -3,10 +3,12 @@ module Musa
|
|
3
3
|
class Timer
|
4
4
|
attr_accessor :period
|
5
5
|
|
6
|
-
def initialize(period_in_seconds, correction: nil, stop: nil)
|
6
|
+
def initialize(period_in_seconds, correction: nil, stop: nil, logger: nil, do_log: nil)
|
7
7
|
@period = period_in_seconds.rationalize
|
8
8
|
@correction = (correction || 0r).rationalize
|
9
9
|
@stop = stop || false
|
10
|
+
@logger = logger
|
11
|
+
@do_log = do_log
|
10
12
|
end
|
11
13
|
|
12
14
|
def run
|
@@ -21,6 +23,10 @@ module Musa
|
|
21
23
|
@next_moment += @period
|
22
24
|
to_sleep = (@next_moment + @correction) - Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
23
25
|
|
26
|
+
if @do_log && to_sleep.negative?
|
27
|
+
@logger&.error "Timer delayed #{-to_sleep}s (near #{(-to_sleep / @period).round} ticks)"
|
28
|
+
end
|
29
|
+
|
24
30
|
sleep to_sleep if to_sleep > 0.0
|
25
31
|
end
|
26
32
|
|
data/lib/musa-dsl.rb
CHANGED
data/musa-dsl.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'musa-dsl'
|
3
|
-
s.version = '0.23.
|
4
|
-
s.date = '2021-09-
|
3
|
+
s.version = '0.23.18'
|
4
|
+
s.date = '2021-09-28'
|
5
5
|
s.summary = 'A simple Ruby DSL for making complex music'
|
6
6
|
s.description = 'Musa-DSL: A Ruby framework and DSL for algorithmic sound and musical thinking and composition'
|
7
7
|
s.authors = ['Javier Sánchez Yeste']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: musa-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.23.
|
4
|
+
version: 0.23.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Sánchez Yeste
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: citrus
|