musa-dsl 0.23.14 → 0.23.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 575141955334ac2cc933f922f854faa5211aa2e8749e1bd1c9994f1fd9d199f2
4
- data.tar.gz: 42f7507bc1870565af4fc96bacbb32b92d62cbcf49b3e322e1f83642ff5c30c4
3
+ metadata.gz: 8dab879e30a1ece7bc5a71a32398213d0592b4a95bb6a852346ec472314bcee7
4
+ data.tar.gz: c10467430f594206804aee8521c51b514af79c29bca67b70782e0c7820294eb1
5
5
  SHA512:
6
- metadata.gz: 9112018924f197cc6d92cb974741609d557319a234ed1fd930ee38f4c99d253ecc5391d3a7dac32d8dae668b8ce6a1ddd534470cf36143330f531547f18d1b9c
7
- data.tar.gz: f2d172183d72bf7713f9aaa3dd303ac9b6b90afb513574c7eda406ea6c7a97873325a748f813a3accd8810b059213e3de3996f10a72b9674306c20e501b03095
6
+ metadata.gz: 892c2017cc142814b475872a1bd9a4471686667b8237c5130ea3e7589fd50a0a0eb6d163ef40bd46b4924385fff4dc0ff9abfb18186349053fb362fe65becb17
7
+ data.tar.gz: 9f287f7302a6d3547e5b85190c5cbda040e4a2e0f0c4dc89b4bb0dea3823772fcaae32c137aec1733b1e658fefe06963ef3cb4bbcc468244a77ef623f0cd7c17
@@ -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
- if effective_value_parameters.empty? && effective_key_parameters.empty?
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(block = nil, on_restart: nil, **with_series, &yield_block)
105
- block ||= yield_block
106
- ProcessWith.new self, with_series, on_restart, &block
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
- ProcessWith.new self, &block
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
- def initialize(serie, with_series = nil, on_restart = nil, &block)
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
- @sources.values.each(&:restart)
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
- others = @sources.transform_values { |v| v.next_value }
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
- if main && !others.values.include?(nil)
166
- if @block
167
- value = @block._call([main], others)
168
- else
169
- value = [main, others]
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? { |serie| serie.infinite? }
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? { |serie| serie.infinite? }
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
data/lib/musa-dsl.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Musa
2
- VERSION = '0.23.14'
2
+ VERSION = '0.23.15'
3
3
  end
4
4
 
5
5
  require_relative 'musa-dsl/core-ext'
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.14'
4
- s.date = '2021-09-03'
3
+ s.version = '0.23.15'
4
+ s.date = '2021-09-07'
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.14
4
+ version: 0.23.15
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-03 00:00:00.000000000 Z
11
+ date: 2021-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: citrus