musa-dsl 0.22.2 → 0.22.3

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: 700593377e2427ac571b039197f3fdb0c3d904dbe0ed74725e54f1c4421f074c
4
- data.tar.gz: a0bb8dbf80d824eaf5543db333964d5cb449819c22a60fb54670a007c9b327b6
3
+ metadata.gz: 193117ba393c58eaf2387d7b0a5ba54bc7fbad0c6ac2e5a7171997b1629d5f69
4
+ data.tar.gz: 5ac3515f62f3c5d8ea34cd91552fb6d0f8d53e40f60d1383fa34a28c0b11289d
5
5
  SHA512:
6
- metadata.gz: de57aaaf8a10d8a1b6ab68ae8ae9e6660488cbc3efce53fa7a1c9a4bd84872a8225ab6d854f9101deb5c7b872389789fbe653dc5b608c809cdd387f1351e53c5
7
- data.tar.gz: 2719f0f97281138feb53542ea842759e965d0c1f756fdbd92797935963c9adaffe91e67212f5efd3ac2e3e2ef2d956da60cce73efbefce764aef224d8042f0bf
6
+ metadata.gz: 13ec912683ee5e0f0f0865ff9197e641671c430ed5a59d438b15acb5423f6d18f3f57624d5dd4c348daa69c93ac1d47428809cea84953893a4cb7f9b224613f9
7
+ data.tar.gz: b64ee9f844989e4db527787f763089c6bcd5aa050254da270c2c5c3461145aefef9b701da6944cda20b53286bfee2e42650c2a21de864ee8ea53f5d48aff0791
@@ -1,5 +1,5 @@
1
1
  module Musa
2
- VERSION = '0.22.2'
2
+ VERSION = '0.22.3'
3
3
  end
4
4
 
5
5
  require_relative 'musa-dsl/core-ext'
@@ -30,6 +30,7 @@ module Musa
30
30
  else
31
31
  @logger = Musa::Logger::Logger.new(sequencer: self, position_format: log_position_format)
32
32
 
33
+ @logger.fatal!
33
34
  @logger.error! if do_error_log || do_error_log.nil?
34
35
  @logger.debug! if do_log
35
36
  end
@@ -1,3 +1,3 @@
1
- require_relative 'base-sequencer-public'
1
+ require_relative 'base-sequencer'
2
2
  require_relative 'base-sequencer-implementation'
3
3
  require_relative 'sequencer-dsl'
@@ -6,6 +6,8 @@ module Musa
6
6
  end
7
7
 
8
8
  class Splitter
9
+ include Enumerable
10
+
9
11
  def initialize(proxy)
10
12
  @proxy = proxy
11
13
  @series = {}
@@ -19,6 +21,30 @@ module Musa
19
21
  end
20
22
  end
21
23
 
24
+ def each
25
+ if block_given?
26
+ if @proxy.hash_mode?
27
+ @proxy.components.each do |key|
28
+ yield [key, self[key]]
29
+ end
30
+ elsif @proxy.array_mode?
31
+ @proxy.components.each do |index|
32
+ yield self[index]
33
+ end
34
+ else
35
+ # do nothing
36
+ end
37
+ else
38
+ if @proxy.hash_mode?
39
+ @proxy.components.collect { |key| [key, self[key]] }.each
40
+ elsif @proxy.array_mode?
41
+ @proxy.components.collect { |index| self[index] }.each
42
+ else
43
+ [].each
44
+ end
45
+ end
46
+ end
47
+
22
48
  class BufferedProxy
23
49
  include SeriePrototyping
24
50
 
@@ -29,6 +55,11 @@ module Musa
29
55
  mark_regarding! @source
30
56
  end
31
57
 
58
+ attr_reader :components
59
+
60
+ def hash_mode?; @hash_mode; end
61
+ def array_mode?; @array_mode; end
62
+
32
63
  protected def _instance!
33
64
  super
34
65
  restart
@@ -36,22 +67,39 @@ module Musa
36
67
 
37
68
  def restart(restart_source: true)
38
69
  @source.restart if restart_source
39
- @values = nil
70
+
71
+ source = @source.instance
72
+ sample = source.current_value || source.peek_next_value
73
+
74
+ case sample
75
+ when Array
76
+ @components = (0..sample.size-1).to_a
77
+ @values = []
78
+ @array_mode = true
79
+ @hash_mode = false
80
+ when Hash
81
+ @components = sample.keys.clone
82
+ @values = {}
83
+ @array_mode = false
84
+ @hash_mode = true
85
+ else
86
+ @components = []
87
+ @values = nil
88
+ @array_mode = @hash_mode = false
89
+ end
40
90
  end
41
91
 
42
92
  def next_value(key_or_index)
43
- if @values.nil? || @values[key_or_index].nil? || @values[key_or_index].empty?
93
+ if @values[key_or_index].nil? || @values[key_or_index].empty?
44
94
  hash_or_array_value = @source.next_value
45
95
 
46
96
  case hash_or_array_value
47
97
  when Hash
48
- @values ||= {}
49
98
  hash_or_array_value.each do |k, v|
50
99
  @values[k] ||= []
51
100
  @values[k] << v
52
101
  end
53
102
  when Array
54
- @values ||= []
55
103
  hash_or_array_value.each_index do |i|
56
104
  @values[i] ||= []
57
105
  @values[i] << hash_or_array_value[i]
@@ -268,9 +268,7 @@ module Musa
268
268
  @to.nil?
269
269
  end
270
270
 
271
- private
272
-
273
- def sign_adjust_step
271
+ private def sign_adjust_step
274
272
  @step = (-@step if @to && (@from < @to && @step < 0 || @from > @to && @step > 0)) || @step
275
273
  end
276
274
  end
@@ -337,9 +335,7 @@ module Musa
337
335
  end
338
336
  end
339
337
 
340
- private
341
-
342
- def adjust_step
338
+ private def adjust_step
343
339
  @step = (-@step if @from < @to && @step < 0 || @from > @to && @step > 0) || @step
344
340
  @step_count = ((@to - @from) / @step).to_i
345
341
  end
@@ -411,9 +407,7 @@ module Musa
411
407
  value
412
408
  end
413
409
 
414
- private
415
-
416
- def adjust_step
410
+ private def adjust_step
417
411
  @step = (-@step if @from < @to && @step < 0 || @from > @to && @step > 0) || @step
418
412
  @step_count = ((@to - @from) / @step).to_i
419
413
  end
@@ -13,3 +13,4 @@ require_relative 'hash-or-array-serie-splitter'
13
13
 
14
14
  require_relative 'quantizer-serie'
15
15
  require_relative 'flattener-timed-serie'
16
+ require_relative 'union-timed-series'
@@ -0,0 +1,109 @@
1
+ require_relative '../datasets/e'
2
+
3
+ module Musa
4
+ module Series
5
+
6
+ extend self
7
+
8
+ def TIMED_UNION(*timed_series)
9
+ TimedUnion.new(timed_series)
10
+ end
11
+
12
+ class TimedUnion
13
+ include Serie
14
+
15
+ attr_reader :sources
16
+
17
+ def initialize(series)
18
+ @sources = if series[0].prototype?
19
+ series.collect(&:prototype).freeze
20
+ else
21
+ series.collect(&:instance)
22
+ end
23
+
24
+ _restart false
25
+
26
+ mark_regarding! series[0]
27
+ end
28
+
29
+ private def _restart(restart_sources = true)
30
+ @sources.each { |serie| serie.restart } if restart_sources
31
+ @sources_next_values = Array.new(@sources.size)
32
+
33
+ @components = nil
34
+ @hash_mode = @array_mode = nil
35
+ end
36
+
37
+ private def _next_value
38
+ sources_values = @sources_next_values.each_index.collect do |i|
39
+ @sources_next_values[i] || (@sources_next_values[i] = @sources[i].next_value)
40
+ end
41
+
42
+ infer_components(sources_values) if !@components
43
+
44
+ time = sources_values.collect { |_| _&.[](:time) }.compact.min
45
+
46
+ if time
47
+ selected_values = sources_values.collect { |_| _ if _&.[](:time) == time }
48
+
49
+ @sources_next_values.each_index do |i|
50
+ if @sources_next_values[i]&.[](:time) == time
51
+ @sources_next_values[i] = nil
52
+ end
53
+ end
54
+
55
+ if @hash_mode
56
+ result = {}
57
+ elsif @array_mode
58
+ result = []
59
+ else # value mode
60
+ result = []
61
+ end
62
+
63
+ @components.each do |target_key_or_index, source_placement|
64
+ result[target_key_or_index] = selected_values.dig(*source_placement)
65
+ end
66
+
67
+ { time: time,
68
+ value: result }
69
+ else
70
+ nil
71
+ end
72
+ end
73
+
74
+ def infinite?
75
+ !!@sources.find(&:infinite?)
76
+ end
77
+ end
78
+
79
+ private def infer_components(sources_values)
80
+ @components = {}
81
+ target_index = 0
82
+
83
+ sources_values.each_with_index do |source_value, i|
84
+ case source_value[:value]
85
+ when Hash
86
+ @hash_mode = true
87
+
88
+ source_value[:value].keys.each do |key|
89
+ @components[key] = [i, :value, key]
90
+ end
91
+ when Array
92
+ @array_mode = true
93
+
94
+ (0..source_value[:value].size - 1).each do |index|
95
+ @components[target_index] = [i, :value, index]
96
+ target_index += 1
97
+ end
98
+ else
99
+ @components[target_index] = [i, :value]
100
+ target_index += 1
101
+ end
102
+ end
103
+
104
+ raise RuntimeError, "source series values are of incompatible type (can't combine Hash and Array values)" if @array_mode && @hash_mode
105
+ end
106
+
107
+ private_constant :TimedUnion
108
+ end
109
+ end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'musa-dsl'
3
- s.version = '0.22.2'
4
- s.date = '2020-11-11'
3
+ s.version = '0.22.3'
4
+ s.date = '2020-11-12'
5
5
  s.summary = 'A simple Ruby DSL for making complex music'
6
6
  s.description = 'Musa-DSL: A Ruby DSL for algorithmic music composition, device language neutral (MIDI, OSC, etc)'
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.22.2
4
+ version: 0.22.3
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-11 00:00:00.000000000 Z
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: citrus
@@ -170,9 +170,9 @@ files:
170
170
  - lib/musa-dsl/sequencer/base-sequencer-implementation-play-timed.rb
171
171
  - lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb
172
172
  - lib/musa-dsl/sequencer/base-sequencer-implementation.rb
173
- - lib/musa-dsl/sequencer/base-sequencer-public.rb
174
173
  - lib/musa-dsl/sequencer/base-sequencer-tick-based.rb
175
174
  - lib/musa-dsl/sequencer/base-sequencer-tickless-based.rb
175
+ - lib/musa-dsl/sequencer/base-sequencer.rb
176
176
  - lib/musa-dsl/sequencer/sequencer-dsl.rb
177
177
  - lib/musa-dsl/sequencer/sequencer.rb
178
178
  - lib/musa-dsl/sequencer/timeslots.rb
@@ -188,6 +188,7 @@ files:
188
188
  - lib/musa-dsl/series/quantizer-serie.rb
189
189
  - lib/musa-dsl/series/queue-serie.rb
190
190
  - lib/musa-dsl/series/series.rb
191
+ - lib/musa-dsl/series/union-timed-series.rb
191
192
  - lib/musa-dsl/transcription.rb
192
193
  - lib/musa-dsl/transcription/from-gdv-to-midi.rb
193
194
  - lib/musa-dsl/transcription/from-gdv-to-musicxml.rb