musa-dsl 0.22.6 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,15 @@ require_relative 'main-serie-operations'
5
5
 
6
6
  require_relative 'array-to-serie'
7
7
 
8
- require_relative 'holder-serie'
9
8
  require_relative 'proxy-serie'
10
9
  require_relative 'queue-serie'
11
10
 
11
+ require_relative 'buffer-serie'
12
+
13
+ require_relative 'series-composer'
14
+
12
15
  require_relative 'hash-or-array-serie-splitter'
13
16
 
14
17
  require_relative 'quantizer-serie'
15
18
  require_relative 'timed-serie'
19
+
@@ -1,9 +1,9 @@
1
1
  require_relative '../datasets/e'
2
2
 
3
- module Musa
4
- module Series
5
- extend self
3
+ require_relative 'base-series'
6
4
 
5
+ module Musa
6
+ module Series::Constructors
7
7
  def TIMED_UNION(*array_of_timed_series, **hash_of_timed_series)
8
8
  raise ArgumentError, 'Can\'t union an array of series with a hash of series' if array_of_timed_series.any? && hash_of_timed_series.any?
9
9
 
@@ -17,29 +17,22 @@ module Musa
17
17
  end
18
18
 
19
19
  class TimedUnionOfArrayOfTimedSeries
20
- include Serie
21
-
22
- attr_reader :sources
20
+ include Series::Serie.with(sources: true)
23
21
 
24
22
  def initialize(series)
25
- @sources = if series[0].prototype?
26
- series.collect(&:prototype).freeze
27
- else
28
- series.collect(&:instance)
29
- end
30
-
31
- _restart false
32
-
33
- mark_regarding! series[0]
23
+ self.sources = series
24
+ init
34
25
  end
35
26
 
36
- private def _restart(restart_sources = true)
37
- @sources.each(&:restart) if restart_sources
27
+ private def _init
38
28
  @sources_next_values = Array.new(@sources.size)
39
-
40
29
  @components = nil
41
30
  end
42
31
 
32
+ private def _restart
33
+ @sources.each(&:restart)
34
+ end
35
+
43
36
  private def _next_value
44
37
  sources_values = @sources_next_values.each_index.collect do |i|
45
38
  @sources_next_values[i] || (@sources_next_values[i] = @sources[i].next_value)
@@ -149,30 +142,27 @@ module Musa
149
142
  private_constant :TimedUnionOfArrayOfTimedSeries
150
143
 
151
144
  class TimedUnionOfHashOfTimedSeries
152
- include Serie
153
-
154
- attr_reader :sources
145
+ include Series::Serie.with(sources: true)
155
146
 
156
147
  def initialize(series)
157
- @components = series.keys
158
-
159
- @sources = if series.values.first.prototype?
160
- series.transform_values(&:prototype).freeze
161
- else
162
- series.transform_values(&:instance)
163
- end
164
-
165
- _restart false
148
+ self.sources = series
149
+ init
150
+ end
166
151
 
167
- mark_regarding! series.values.first
152
+ def sources=(series)
153
+ super
154
+ @components = series.keys
168
155
  end
169
156
 
170
- private def _restart(restart_sources = true)
171
- @sources.each_value(&:restart) if restart_sources
157
+ private def _init
172
158
  @sources_next_values = @components.collect { |k| [k, nil] }.to_h
173
159
  @other_attributes = nil
174
160
  end
175
161
 
162
+ private def _restart
163
+ @sources.each_value(&:restart)
164
+ end
165
+
176
166
  private def _next_value
177
167
  sources_values = {}
178
168
 
@@ -231,126 +221,123 @@ module Musa
231
221
  end
232
222
 
233
223
  private_constant :TimedUnionOfHashOfTimedSeries
224
+ end
234
225
 
235
- module SerieOperations
236
- def flatten_timed
237
- TimedFlattener.new(self)
238
- end
226
+ module Series::Operations
227
+ def flatten_timed
228
+ TimedFlattener.new(self)
229
+ end
239
230
 
240
- def compact_timed
241
- TimedCompacter.new(self)
242
- end
231
+ def compact_timed
232
+ TimedCompacter.new(self)
233
+ end
243
234
 
244
- def union_timed(*other_timed_series, key: nil, **other_key_timed_series)
245
- if key && other_key_timed_series.any?
246
- Series::TIMED_UNION(key => self, **other_key_timed_series)
235
+ def union_timed(*other_timed_series, key: nil, **other_key_timed_series)
236
+ if key && other_key_timed_series.any?
237
+ Series::Constructors.TIMED_UNION(key => self, **other_key_timed_series)
247
238
 
248
- elsif other_timed_series.any? && other_key_timed_series.empty?
249
- Series::TIMED_UNION(self, *other_timed_series)
239
+ elsif other_timed_series.any? && other_key_timed_series.empty?
240
+ Series::Constructors.TIMED_UNION(self, *other_timed_series)
250
241
 
251
- else
252
- raise ArgumentError, 'Can\'t union an array of series with a hash of series'
253
- end
242
+ else
243
+ raise ArgumentError, 'Can\'t union an array of series with a hash of series'
254
244
  end
245
+ end
255
246
 
256
- class TimedFlattener
257
- include Serie
258
-
259
- attr_reader :source
247
+ class TimedFlattener
248
+ include Series::Serie.with(source: true)
260
249
 
261
- def initialize(serie)
262
- @source = serie
263
- mark_regarding! @source
264
- end
250
+ def initialize(serie)
251
+ self.source = serie
252
+ init
253
+ end
265
254
 
266
- def _restart
267
- @source.restart
268
- end
255
+ private def _restart
256
+ @source.restart
257
+ end
269
258
 
270
- def _next_value
271
- source_value = @source.next_value
259
+ private def _next_value
260
+ source_value = @source.next_value
272
261
 
273
- if !source_value.nil?
274
- time = source_value[:time]
275
- source_value_value = source_value[:value]
262
+ if !source_value.nil?
263
+ time = source_value[:time]
264
+ source_value_value = source_value[:value]
276
265
 
277
- source_value_extra = (source_value.keys - [:time, :value]).collect do |attribute_name|
278
- [attribute_name, source_value[attribute_name]]
279
- end.to_h
266
+ source_value_extra = (source_value.keys - [:time, :value]).collect do |attribute_name|
267
+ [attribute_name, source_value[attribute_name]]
268
+ end.to_h
280
269
 
281
- case source_value_value
282
- when Hash
283
- result = {}
284
- source_value_value.each_pair do |key, value|
285
- result[key] = { time: time, value: value }.extend(Musa::Datasets::AbsTimed)
270
+ case source_value_value
271
+ when Hash
272
+ result = {}
273
+ source_value_value.each_pair do |key, value|
274
+ result[key] = { time: time, value: value }.extend(Musa::Datasets::AbsTimed)
286
275
 
287
- source_value_extra.each do |attribute_name, attribute_value|
288
- result[key][attribute_name] = attribute_value[key]
289
- end
276
+ source_value_extra.each do |attribute_name, attribute_value|
277
+ result[key][attribute_name] = attribute_value[key]
290
278
  end
279
+ end
291
280
 
292
- when Array
293
- result = []
294
- source_value_value.each_index do |index|
295
- result[index] = { time: time, value: source_value_value[index] }.extend(Musa::Datasets::AbsTimed)
281
+ when Array
282
+ result = []
283
+ source_value_value.each_index do |index|
284
+ result[index] = { time: time, value: source_value_value[index] }.extend(Musa::Datasets::AbsTimed)
296
285
 
297
- source_value_extra.each do |attribute_name, attribute_value|
298
- result[index][attribute_name] = attribute_value[index]
299
- end
286
+ source_value_extra.each do |attribute_name, attribute_value|
287
+ result[index][attribute_name] = attribute_value[index]
300
288
  end
301
- else
302
- result = source_value.clone.extend(Musa::Datasets::AbsTimed)
303
289
  end
304
-
305
- result.extend(Musa::Datasets::AbsTimed)
306
290
  else
307
- nil
291
+ result = source_value.clone.extend(Musa::Datasets::AbsTimed)
308
292
  end
309
- end
310
293
 
311
- def infinite?
312
- @source.infinite?
294
+ result.extend(Musa::Datasets::AbsTimed)
295
+ else
296
+ nil
313
297
  end
314
298
  end
315
299
 
316
- private_constant :TimedFlattener
300
+ def infinite?
301
+ @source.infinite?
302
+ end
317
303
  end
318
304
 
319
- class TimedCompacter
320
- include Serie
305
+ private_constant :TimedFlattener
306
+ end
321
307
 
322
- attr_reader :source
308
+ class TimedCompacter
309
+ include Series::Serie.with(source: true)
323
310
 
324
- def initialize(serie)
325
- @source = serie
326
- mark_regarding! @source
327
- end
311
+ def initialize(serie)
312
+ self.source = serie
313
+ init
314
+ end
328
315
 
329
- def _restart
330
- @source.restart
331
- end
316
+ private def _restart
317
+ @source.restart
318
+ end
332
319
 
333
- def _next_value
334
- while (source_value = @source.next_value) && skip_value?(source_value[:value]); end
335
- source_value
336
- end
320
+ private def _next_value
321
+ while (source_value = @source.next_value) && skip_value?(source_value[:value]); end
322
+ source_value
323
+ end
337
324
 
338
- def infinite?
339
- @source.infinite?
340
- end
325
+ def infinite?
326
+ @source.infinite?
327
+ end
341
328
 
342
- private def skip_value?(timed_value)
343
- case timed_value
344
- when Hash
345
- timed_value.all? { |_, v| v.nil? }
346
- when Array
347
- timed_value.all?(&:nil?)
348
- else
349
- timed_value.nil?
350
- end
329
+ private def skip_value?(timed_value)
330
+ case timed_value
331
+ when Hash
332
+ timed_value.all? { |_, v| v.nil? }
333
+ when Array
334
+ timed_value.all?(&:nil?)
335
+ else
336
+ timed_value.nil?
351
337
  end
352
338
  end
353
-
354
- private_constant :TimedCompacter
355
339
  end
340
+
341
+ private_constant :TimedCompacter
356
342
  end
343
+
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.22.6'
4
- s.date = '2020-11-25'
3
+ s.version = '0.23.0'
4
+ s.date = '2021-06-29'
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']
@@ -10,6 +10,16 @@ Gem::Specification.new do |s|
10
10
  s.homepage = 'https://github.com/javier-sy/musa-dsl'
11
11
  s.license = 'LGPL-3.0'
12
12
 
13
+ s.required_ruby_version = '~> 2.7'
14
+
15
+ # TODO
16
+ #s.metadata = {
17
+ # "source_code_uri" => "https://",
18
+ # "homepage_uri" => "",
19
+ # "documentation_uri" => "",
20
+ # "changelog_uri" => ""
21
+ #}
22
+
13
23
  s.add_runtime_dependency 'citrus', '~> 3.0.0', '>= 3.0.0'
14
24
 
15
25
  s.add_runtime_dependency 'midi-message', '~> 0.4', '>= 0.4.9'
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.22.6
4
+ version: 0.23.0
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: 2020-11-25 00:00:00.000000000 Z
11
+ date: 2021-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: citrus
@@ -78,7 +78,6 @@ extensions: []
78
78
  extra_rdoc_files: []
79
79
  files:
80
80
  - ".gitignore"
81
- - ".ruby-version"
82
81
  - Gemfile
83
82
  - LICENSE.md
84
83
  - README.md
@@ -179,13 +178,14 @@ files:
179
178
  - lib/musa-dsl/series.rb
180
179
  - lib/musa-dsl/series/array-to-serie.rb
181
180
  - lib/musa-dsl/series/base-series.rb
181
+ - lib/musa-dsl/series/buffer-serie.rb
182
182
  - lib/musa-dsl/series/hash-or-array-serie-splitter.rb
183
- - lib/musa-dsl/series/holder-serie.rb
184
183
  - lib/musa-dsl/series/main-serie-constructors.rb
185
184
  - lib/musa-dsl/series/main-serie-operations.rb
186
185
  - lib/musa-dsl/series/proxy-serie.rb
187
186
  - lib/musa-dsl/series/quantizer-serie.rb
188
187
  - lib/musa-dsl/series/queue-serie.rb
188
+ - lib/musa-dsl/series/series-composer.rb
189
189
  - lib/musa-dsl/series/series.rb
190
190
  - lib/musa-dsl/series/timed-serie.rb
191
191
  - lib/musa-dsl/transcription.rb
@@ -212,16 +212,16 @@ require_paths:
212
212
  - lib
213
213
  required_ruby_version: !ruby/object:Gem::Requirement
214
214
  requirements:
215
- - - ">="
215
+ - - "~>"
216
216
  - !ruby/object:Gem::Version
217
- version: '0'
217
+ version: '2.7'
218
218
  required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - ">="
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
223
  requirements: []
224
- rubygems_version: 3.1.4
224
+ rubygems_version: 3.1.6
225
225
  signing_key:
226
226
  specification_version: 4
227
227
  summary: A simple Ruby DSL for making complex music
@@ -1,87 +0,0 @@
1
- module Musa
2
- module Series
3
- # TODO: adapt to series prototyping
4
-
5
- def HOLDER(serie = nil)
6
- Holder.new(serie)
7
- end
8
-
9
- class Holder
10
- include Serie
11
-
12
- attr_reader :hold, :next
13
-
14
- def initialize(serie)
15
- @hold = serie.instance if serie
16
- @next = []
17
-
18
- mark_as_instance!
19
- end
20
-
21
- def hold=(serie)
22
- @hold = serie.instance
23
- end
24
-
25
- def <<(serie)
26
- if @hold.nil?
27
- @hold = serie.instance
28
- else
29
- @next << serie.instance
30
- end
31
-
32
- self
33
- end
34
-
35
- def _prototype!
36
- raise PrototypingSerieError, 'Cannot get prototype of a proxy serie'
37
- end
38
-
39
- def restart
40
- if @next.empty? && @hold
41
- @hold.restart
42
- else
43
- @hold = @next.shift
44
- end
45
-
46
- self
47
- end
48
-
49
- def current_value
50
- @hold.current_value if @hold
51
- end
52
-
53
- def next_value
54
- @hold.next_value if @hold
55
- end
56
-
57
- def peek_next_value
58
- @hold.peek_next_value if @hold
59
- end
60
-
61
- def infinite?
62
- @hold.infinite? if @hold
63
- end
64
-
65
- private
66
-
67
- def method_missing(method_name, *args, **key_args, &block)
68
- if @hold && @hold.respond_to?(method_name)
69
- @hold.send method_name, *args, **key_args, &block
70
- else
71
- super
72
- end
73
- end
74
-
75
- def respond_to_missing?(method_name, include_private)
76
- @hold && @hold.respond_to?(method_name, include_private) || super
77
- end
78
- end
79
- end
80
-
81
- module SerieOperations
82
- # TODO add test case
83
- def hold
84
- Series::Holder.new self
85
- end
86
- end
87
- end