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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/musa-dsl/core-ext/with.rb +4 -3
  3. data/lib/musa-dsl/datasets/gdv.rb +2 -2
  4. data/lib/musa-dsl/datasets/gdvd.rb +2 -1
  5. data/lib/musa-dsl/datasets/helper.rb +1 -1
  6. data/lib/musa-dsl/datasets/score/queriable.rb +43 -42
  7. data/lib/musa-dsl/datasets/score/render.rb +24 -20
  8. data/lib/musa-dsl/datasets/score/to-mxml/to-mxml.rb +120 -122
  9. data/lib/musa-dsl/generative/backboner.rb +2 -2
  10. data/lib/musa-dsl/generative/generative-grammar.rb +2 -0
  11. data/lib/musa-dsl/generative/markov.rb +1 -2
  12. data/lib/musa-dsl/generative/variatio.rb +6 -10
  13. data/lib/musa-dsl/logger/logger.rb +22 -22
  14. data/lib/musa-dsl/matrix/matrix.rb +3 -5
  15. data/lib/musa-dsl/midi/midi-recorder.rb +3 -4
  16. data/lib/musa-dsl/midi/midi-voices.rb +3 -3
  17. data/lib/musa-dsl/music/chords.rb +26 -29
  18. data/lib/musa-dsl/musicxml/builder/direction.rb +2 -2
  19. data/lib/musa-dsl/neumalang/neumalang.rb +25 -67
  20. data/lib/musa-dsl/neumas/array-to-neumas.rb +2 -2
  21. data/lib/musa-dsl/repl/repl.rb +1 -1
  22. data/lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb +12 -11
  23. data/lib/musa-dsl/sequencer/base-sequencer-implementation-move.rb +53 -52
  24. data/lib/musa-dsl/sequencer/base-sequencer-implementation-play-helper.rb +2 -4
  25. data/lib/musa-dsl/sequencer/base-sequencer-implementation-play-timed.rb +43 -39
  26. data/lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb +5 -7
  27. data/lib/musa-dsl/sequencer/base-sequencer-implementation.rb +6 -14
  28. data/lib/musa-dsl/sequencer/base-sequencer-tick-based.rb +4 -3
  29. data/lib/musa-dsl/sequencer/base-sequencer.rb +5 -5
  30. data/lib/musa-dsl/sequencer/sequencer-dsl.rb +11 -6
  31. data/lib/musa-dsl/series/array-to-serie.rb +5 -3
  32. data/lib/musa-dsl/series/base-series.rb +2 -2
  33. data/lib/musa-dsl/series/buffer-serie.rb +0 -5
  34. data/lib/musa-dsl/series/main-serie-constructors.rb +16 -6
  35. data/lib/musa-dsl/series/main-serie-operations.rb +2 -2
  36. data/lib/musa-dsl/series/quantizer-serie.rb +47 -51
  37. data/lib/musa-dsl/series/series-composer.rb +16 -6
  38. data/lib/musa-dsl/series/timed-serie.rb +49 -48
  39. data/lib/musa-dsl/transcription/from-gdv-to-midi.rb +5 -7
  40. data/lib/musa-dsl/transcription/from-gdv-to-musicxml.rb +1 -4
  41. data/lib/musa-dsl/transcription/from-gdv.rb +1 -3
  42. data/lib/musa-dsl/transcription/transcription.rb +2 -4
  43. data/lib/musa-dsl/transport/input-midi-clock.rb +7 -4
  44. data/lib/musa-dsl/transport/transport.rb +10 -12
  45. data/lib/musa-dsl.rb +1 -1
  46. data/musa-dsl.gemspec +2 -2
  47. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aedf1b2e55be310702169b869ff68a41c79d0d787002b21918c096ad18373dcf
4
- data.tar.gz: 4bc6bd9694bffe3c97040e2d33e4a451accdeb5e621346c030fc699c2325ba5d
3
+ metadata.gz: 83e058435542d40d1947cb484686b8b78b67c39e0a00f88d60d3b1c534620401
4
+ data.tar.gz: eef1c767f85c7ad1c174986eee492f7588d6c6c32e57b3fa13f8dcb7e8a8db23
5
5
  SHA512:
6
- metadata.gz: 30173d87a84a7d4288ddd00f5b212a9178f6f1836f673972f4c29c6528d57231588c4e9152ce06ba24319e834aac087a25f793ca8bf862d83d8bfae898c7d620
7
- data.tar.gz: de0f34c68858de9629d2e65f9c0d794c2bb122855716476130b35f921297b731facd1b039c339235ec7168bedafa1652611722cc9ac684e3f66748b5275fa101
6
+ metadata.gz: ce2bbb09377ad73191994790009429f469a7c46edaa47bdf5dd7cbc04b4541cfeef36006bc9b68c0f5baf2598e9c52acf339dd3b166702cef102e96209cb5013
7
+ data.tar.gz: 0c787f3da1d3beddbf09dcf20493c0cb0ed97868a49ea26432307093df222ec69ef9128cf2ce9d58a0211ccd2ec3a4ea59446fb14026b00f90dd41691c4cbf3a
@@ -6,12 +6,13 @@ module Musa
6
6
  def with(*value_parameters, **key_parameters, &block)
7
7
  binder = Musa::Extension::SmartProcBinder::SmartProcBinder.new(block)
8
8
 
9
- keep_block_context = binder.parameters[0][1] == :_ unless binder.parameters.empty?
10
- keep_block_context ||= false
9
+ keep_proc_context = @keep_proc_context_on_with
10
+ keep_proc_context ||= binder.parameters[0][1] == :_ unless binder.parameters.empty?
11
+ keep_proc_context ||= false
11
12
 
12
13
  effective_value_parameters, effective_key_parameters = binder._apply(value_parameters, key_parameters)
13
14
 
14
- if keep_block_context
15
+ if keep_proc_context
15
16
  binder.call(self, *effective_value_parameters, **effective_key_parameters)
16
17
  else
17
18
  if effective_value_parameters.empty? && effective_key_parameters.empty?
@@ -4,10 +4,10 @@ require_relative 'pdv'
4
4
 
5
5
  require_relative 'helper'
6
6
 
7
- using Musa::Extension::InspectNice
8
-
9
7
  module Musa::Datasets
10
8
  module GDV
9
+ using Musa::Extension::InspectNice
10
+
11
11
  include AbsD
12
12
 
13
13
  include Helper
@@ -3,7 +3,6 @@ require_relative 'gdv'
3
3
 
4
4
  require_relative 'helper'
5
5
 
6
- using Musa::Extension::InspectNice
7
6
 
8
7
  module Musa::Datasets
9
8
  module GDVd
@@ -12,6 +11,8 @@ module Musa::Datasets
12
11
 
13
12
  include Helper
14
13
 
14
+ using Musa::Extension::InspectNice
15
+
15
16
  NaturalKeys = (NaturalKeys +
16
17
  [:abs_grade, :abs_sharps, :abs_octave,
17
18
  :delta_grade, :delta_sharps, :delta_interval_sign, :delta_interval, :delta_octave,
@@ -1,6 +1,6 @@
1
1
  module Musa::Datasets
2
2
  module Helper
3
- protected
3
+ private
4
4
 
5
5
  def positive_sign_of(x)
6
6
  x >= 0 ? '+' : ''
@@ -1,48 +1,49 @@
1
- module Musa::Datasets; class Score
2
- module Queriable
3
- module QueryableByTimeSlot
4
- def group_by_attribute(attribute)
5
- group_by { |e| e[attribute] }.transform_values! { |e| e.extend(QueryableByTimeSlot) }
1
+ module Musa::Datasets
2
+ class Score
3
+ module Queriable
4
+ module QueryableByTimeSlot
5
+ def group_by_attribute(attribute)
6
+ group_by { |e| e[attribute] }.transform_values! { |e| e.extend(QueryableByTimeSlot) }
7
+ end
8
+
9
+ def select_by_attribute(attribute, value = nil)
10
+ if value.nil?
11
+ select { |e| !e[attribute].nil? }
12
+ else
13
+ select { |e| e[attribute] == value }
14
+ end.extend(QueryableByTimeSlot)
15
+ end
16
+
17
+ def sort_by_attribute(attribute)
18
+ select_by_attribute(attribute).sort_by { |e| e[attribute] }.extend(QueryableByTimeSlot)
19
+ end
6
20
  end
7
21
 
8
- def select_by_attribute(attribute, value = nil)
9
- if value.nil?
10
- select { |e| !e[attribute].nil? }
11
- else
12
- select { |e| e[attribute] == value }
13
- end.extend(QueryableByTimeSlot)
22
+ private_constant :QueryableByTimeSlot
23
+
24
+ module QueryableByDataset
25
+ def group_by_attribute(attribute)
26
+ group_by { |e| e[:dataset][attribute] }.transform_values! { |e| e.extend(QueryableByDataset) }
27
+ end
28
+
29
+ def select_by_attribute(attribute, value = nil)
30
+ if value.nil?
31
+ select { |e| !e[:dataset][attribute].nil? }
32
+ else
33
+ select { |e| e[:dataset][attribute] == value }
34
+ end.extend(QueryableByDataset)
35
+ end
36
+
37
+ def subset
38
+ raise ArgumentError, "subset needs a block with the inclusion condition on the dataset" unless block_given?
39
+ select { |e| yield e[:dataset] }.extend(QueryableByDataset)
40
+ end
41
+
42
+ def sort_by_attribute(attribute)
43
+ select_by_attribute(attribute).sort_by { |e| e[:dataset][attribute] }.extend(QueryableByDataset)
44
+ end
14
45
  end
15
46
 
16
- def sort_by_attribute(attribute)
17
- select_by_attribute(attribute).sort_by { |e| e[attribute] }.extend(QueryableByTimeSlot)
18
- end
19
- end
20
-
21
- private_constant :QueryableByTimeSlot
22
-
23
- module QueryableByDataset
24
- def group_by_attribute(attribute)
25
- group_by { |e| e[:dataset][attribute] }.transform_values! { |e| e.extend(QueryableByDataset) }
26
- end
27
-
28
- def select_by_attribute(attribute, value = nil)
29
- if value.nil?
30
- select { |e| !e[:dataset][attribute].nil? }
31
- else
32
- select { |e| e[:dataset][attribute] == value }
33
- end.extend(QueryableByDataset)
34
- end
35
-
36
- def subset
37
- raise ArgumentError, "subset needs a block with the inclusion condition on the dataset" unless block_given?
38
- select { |e| yield e[:dataset] }.extend(QueryableByDataset)
39
- end
40
-
41
- def sort_by_attribute(attribute)
42
- select_by_attribute(attribute).sort_by { |e| e[:dataset][attribute] }.extend(QueryableByDataset)
43
- end
47
+ private_constant :QueryableByDataset
44
48
  end
45
-
46
- private_constant :QueryableByDataset
47
- end
48
49
  end; end
@@ -1,31 +1,35 @@
1
1
  require_relative '../../sequencer'
2
2
  require_relative '../../series'
3
3
 
4
- module Musa::Datasets; class Score
5
- module Render
6
- def render(on:, &block)
7
- @score.keys.each do |score_at|
8
- effective_wait = score_at - 1r
4
+ module Musa
5
+ module Datasets
6
+ class Score
7
+ module Render
8
+ def render(on:, &block)
9
+ @score.keys.each do |score_at|
10
+ effective_wait = score_at - 1r
9
11
 
10
- @score[score_at].each do |element|
11
- case element
12
- when Score
13
- on.wait effective_wait do
14
- element.render(on: on, &block)
15
- end
12
+ @score[score_at].each do |element|
13
+ case element
14
+ when Score
15
+ on.wait effective_wait do
16
+ element.render(on: on, &block)
17
+ end
16
18
 
17
- when Abs
18
- on.wait effective_wait do
19
- block.call(element)
20
- end
19
+ when Abs
20
+ on.wait effective_wait do
21
+ block.call(element)
22
+ end
21
23
 
22
- else
23
- raise ArgumentError, "Can't sequence #{element} because it's not an Abs dataset"
24
+ else
25
+ raise ArgumentError, "Can't sequence #{element} because it's not an Abs dataset"
26
+ end
27
+ end
24
28
  end
29
+
30
+ nil
25
31
  end
26
32
  end
27
-
28
- nil
29
33
  end
30
34
  end
31
- end; end
35
+ end
@@ -6,167 +6,165 @@ require_relative 'process-time'
6
6
  require_relative 'process-pdv'
7
7
  require_relative 'process-ps'
8
8
 
9
- module Musa::Datasets; class Score
10
- module ToMXML
11
- include Musa::MusicXML::Builder
12
- include Musa::Datasets
13
-
14
- using Musa::Extension::InspectNice
15
-
16
- def to_mxml(beats_per_bar, ticks_per_beat,
17
- bpm: nil,
18
- title: nil,
19
- creators: nil,
20
- encoding_date: nil,
21
- parts:,
22
- logger: nil,
23
- do_log: nil)
24
-
25
- bpm ||= 90
26
- title ||= 'Untitled'
27
- creators ||= { composer: 'Unknown' }
28
-
29
- if logger.nil?
30
- logger = Musa::Logger::Logger.new
31
- logger.debug! if do_log
32
- end
9
+ module Musa::Datasets
10
+ class Score
11
+ module ToMXML
12
+ using Musa::Extension::InspectNice
13
+
14
+ def to_mxml(beats_per_bar, ticks_per_beat,
15
+ bpm: nil,
16
+ title: nil,
17
+ creators: nil,
18
+ encoding_date: nil,
19
+ parts:,
20
+ logger: nil,
21
+ do_log: nil)
22
+
23
+ bpm ||= 90
24
+ title ||= 'Untitled'
25
+ creators ||= { composer: 'Unknown' }
26
+
27
+ if logger.nil?
28
+ logger = Musa::Logger::Logger.new
29
+ logger.debug! if do_log
30
+ end
33
31
 
34
- do_log ||= nil
32
+ do_log ||= nil
35
33
 
36
- mxml = ScorePartwise.new do |_|
37
- _.work_title title
38
- _.creators **creators
39
- _.encoding_date encoding_date if encoding_date
34
+ mxml = Musa::MusicXML::Builder::ScorePartwise.new do |_|
35
+ _.work_title title
36
+ _.creators **creators
37
+ _.encoding_date encoding_date if encoding_date
40
38
 
41
- parts.each_pair do |id, part_info|
42
- _.part id,
43
- name: part_info&.[](:name),
44
- abbreviation: part_info&.[](:abbreviation) do |_|
39
+ parts.each_pair do |id, part_info|
40
+ _.part id,
41
+ name: part_info&.[](:name),
42
+ abbreviation: part_info&.[](:abbreviation) do |_|
45
43
 
46
- _.measure do |_|
47
- _.attributes do |_|
48
- _.divisions ticks_per_beat
44
+ _.measure do |_|
45
+ _.attributes do |_|
46
+ _.divisions ticks_per_beat
49
47
 
50
- i = 0
51
- (part_info&.[](:clefs) || { g: 2 }).each_pair do |clef, line|
52
- i += 1
53
- _.clef i, sign: clef.upcase, line: line
54
- _.time i, beats: beats_per_bar, beat_type: 4
48
+ i = 0
49
+ (part_info&.[](:clefs) || { g: 2 }).each_pair do |clef, line|
50
+ i += 1
51
+ _.clef i, sign: clef.upcase, line: line
52
+ _.time i, beats: beats_per_bar, beat_type: 4
53
+ end
55
54
  end
56
- end
57
55
 
58
- _.metronome placement: 'above', beat_unit: 'quarter', per_minute: bpm
56
+ _.metronome placement: 'above', beat_unit: 'quarter', per_minute: bpm
57
+ end
59
58
  end
60
59
  end
61
60
  end
62
- end
63
61
 
64
- if do_log
65
- logger.debug ""
66
- logger.debug"score.to_mxml log:"
67
- logger.debug"------------------"
68
- end
62
+ if do_log
63
+ logger.debug ""
64
+ logger.debug"score.to_mxml log:"
65
+ logger.debug"------------------"
66
+ end
69
67
 
70
- parts.each_key do |part_id|
71
- fill_part mxml.parts[part_id],
72
- beats_per_bar * ticks_per_beat,
73
- (parts.size > 1 ? part_id : nil),
74
- logger, do_log
75
- end
68
+ parts.each_key do |part_id|
69
+ fill_part mxml.parts[part_id],
70
+ beats_per_bar * ticks_per_beat,
71
+ (parts.size > 1 ? part_id : nil),
72
+ logger, do_log
73
+ end
76
74
 
77
- mxml
78
- end
75
+ mxml
76
+ end
79
77
 
80
- private
78
+ private
81
79
 
82
- def fill_part(part, divisions_per_bar, instrument, logger, do_log)
83
- measure = nil
84
- dynamics_context = nil
80
+ def fill_part(part, divisions_per_bar, instrument, logger, do_log)
81
+ measure = nil
82
+ dynamics_context = nil
85
83
 
86
- (1..finish || 0).each do |bar|
87
- if do_log
88
- logger.debug ""
89
- logger.debug msg = "filling part #{part.name} (#{instrument || 'nil'}): processing bar #{bar}"
90
- logger.debug "-" * msg.size
91
- end
84
+ (1..finish || 0).each do |bar|
85
+ if do_log
86
+ logger.debug ""
87
+ logger.debug msg = "filling part #{part.name} (#{instrument || 'nil'}): processing bar #{bar}"
88
+ logger.debug "-" * msg.size
89
+ end
92
90
 
93
- measure = part.add_measure if measure
94
- measure ||= part.measures.last
91
+ measure = part.add_measure if measure
92
+ measure ||= part.measures.last
95
93
 
96
- pointer = 0r
94
+ pointer = 0r
97
95
 
98
- instrument_score = subset { |dataset| instrument.nil? || dataset[:instrument] == instrument }
96
+ instrument_score = subset { |dataset| instrument.nil? || dataset[:instrument] == instrument }
99
97
 
100
- bar_elements = \
101
- (instrument_score.changes_between(bar, bar + 1).select { |p| p[:dataset].is_a?(PS) } +
102
- (pdvs = instrument_score.between(bar, bar + 1).select { |p| p[:dataset].is_a?(PDV) }))
103
- .sort_by { |e| [ e[:time_in_interval] || e[:start_in_interval],
104
- e[:dataset].is_a?(PS) ? 0 : 1 ] }
98
+ bar_elements = \
99
+ (instrument_score.changes_between(bar, bar + 1).select { |p| p[:dataset].is_a?(Musa::Datasets::PS) } +
100
+ (pdvs = instrument_score.between(bar, bar + 1).select { |p| p[:dataset].is_a?(Musa::Datasets::PDV) }))
101
+ .sort_by { |e| [ e[:time_in_interval] || e[:start_in_interval],
102
+ e[:dataset].is_a?(Musa::Datasets::PS) ? 0 : 1 ] }
105
103
 
106
- if pdvs.empty?
107
- logger.debug "\nadding full bar silence..." if do_log
104
+ if pdvs.empty?
105
+ logger.debug "\nadding full bar silence..." if do_log
108
106
 
109
- process_pdv(measure, bar, divisions_per_bar,
110
- { start: bar,
111
- finish: bar + 1,
112
- dataset: { pitch: :silence, duration: 1 }.extend(PDV) },
113
- pointer,
114
- logger,
115
- do_log)
116
- else
117
- first = bar_elements.first
107
+ process_pdv(measure, bar, divisions_per_bar,
108
+ { start: bar,
109
+ finish: bar + 1,
110
+ dataset: { pitch: :silence, duration: 1 }.extend(Musa::Datasets::PDV) },
111
+ pointer,
112
+ logger,
113
+ do_log)
114
+ else
115
+ first = bar_elements.first
118
116
 
119
- logger.debug "\nfirst element #{first.inspect}" if do_log
117
+ logger.debug "\nfirst element #{first.inspect}" if do_log
120
118
 
121
- # TODO habrá que arreglar el cálculo de pointer cuando haya avances y retrocesos para que
122
- # TODO no añada silencios incorrectos al principio o al final
119
+ # TODO habrá que arreglar el cálculo de pointer cuando haya avances y retrocesos para que
120
+ # TODO no añada silencios incorrectos al principio o al final
123
121
 
124
- if (first[:time_in_interval] || first[:start_in_interval]) > bar
122
+ if (first[:time_in_interval] || first[:start_in_interval]) > bar
125
123
 
126
- silence_duration = first[:start_in_interval] - bar
124
+ silence_duration = first[:start_in_interval] - bar
127
125
 
128
- logger.debug "\nadding initial silence for duration #{silence_duration}..." if do_log
126
+ logger.debug "\nadding initial silence for duration #{silence_duration}..." if do_log
129
127
 
130
- pointer = process_pdv(measure, bar, divisions_per_bar,
131
- { start: bar,
132
- finish: first[:start_in_interval],
133
- dataset: { pitch: :silence, duration: silence_duration }.extend(PDV) },
134
- pointer,
135
- logger,
136
- do_log)
137
- end
128
+ pointer = process_pdv(measure, bar, divisions_per_bar,
129
+ { start: bar,
130
+ finish: first[:start_in_interval],
131
+ dataset: { pitch: :silence, duration: silence_duration }.extend(Musa::Datasets::PDV) },
132
+ pointer,
133
+ logger,
134
+ do_log)
135
+ end
138
136
 
139
- logger.debug "\nadding PDV and PS elements..." if do_log
137
+ logger.debug "\nadding PDV and PS elements..." if do_log
140
138
 
141
- bar_elements.each do |element|
142
- case element[:dataset]
143
- when PDV
144
- pointer = process_pdv(measure, bar, divisions_per_bar, element, pointer, logger, do_log)
139
+ bar_elements.each do |element|
140
+ case element[:dataset]
141
+ when Musa::Datasets::PDV
142
+ pointer = process_pdv(measure, bar, divisions_per_bar, element, pointer, logger, do_log)
145
143
 
146
- when PS
147
- dynamics_context = process_ps(measure, element, dynamics_context, logger, do_log)
144
+ when Musa::Datasets::PS
145
+ dynamics_context = process_ps(measure, element, dynamics_context, logger, do_log)
148
146
 
149
- else
150
- # ignored
147
+ else
148
+ # ignored
149
+ end
151
150
  end
152
- end
153
151
 
154
- if pointer < 1r
155
- silence_duration = 1r - pointer
152
+ if pointer < 1r
153
+ silence_duration = 1r - pointer
156
154
 
157
- logger.debug "\nadded ending silence for duration #{silence_duration}..." if do_log
155
+ logger.debug "\nadded ending silence for duration #{silence_duration}..." if do_log
158
156
 
159
- process_pdv(measure, bar, divisions_per_bar,
160
- { start: bar + pointer,
161
- finish: bar + 1 - Rational(1, divisions_per_bar),
162
- dataset: { pitch: :silence, duration: silence_duration }.extend(PDV) },
163
- pointer,
164
- logger,
165
- do_log)
157
+ process_pdv(measure, bar, divisions_per_bar,
158
+ { start: bar + pointer,
159
+ finish: bar + 1 - Rational(1, divisions_per_bar),
160
+ dataset: { pitch: :silence, duration: silence_duration }.extend(Musa::Datasets::PDV) },
161
+ pointer,
162
+ logger,
163
+ do_log)
166
164
 
165
+ end
167
166
  end
168
167
  end
169
168
  end
170
169
  end
171
- end
172
170
  end; end