musa-dsl 0.14.18 → 0.14.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d4df51d6162aef04ab11bd89ad57d36542c6eb2ef5e9b3e0ad2e66b18c75f76
4
- data.tar.gz: 31387f0b48ddb90cb3ed3ec628bcb6c60fea207a73350d3664c657bff5cc3ab9
3
+ metadata.gz: 9fda568f7b4eef0b94479ab3f9e5833a130d82ba2386687607a0a4193c292f0e
4
+ data.tar.gz: e7366f81def8b65c0977c004ef02a50ce01472a1c5a29b5b9ec0916ff1989538
5
5
  SHA512:
6
- metadata.gz: d04c5711e673f5d26b17132506648915676fcee7994f6ecf770abdb810972a59a209e2ff21e8cbdd9c535de5e36c43944c29db2fa28d1ccd1725f1ec6a560aa9
7
- data.tar.gz: 845cdd7371bc3db81090bf380ef38244ffd2debc0cfacbf07f8a13171f48bf850f318b99eb08d19cc2288395825ebe16877dd148de6eb6e8716c2be258f0d388
6
+ metadata.gz: 1d78176e99d1746d2eba617fac89602c56bc4aa8a165d7f0ee1e696b726f52c0b7a89347b313e47d2d5e6252cb3f2c5d0627af0a68a6ccb0deb10d3f1c3a4ceb
7
+ data.tar.gz: c16e547be13a8c6592722afbc6cb6a8b571a8930b0c0079b9067baee43c4c237b1123fff554674bd572c68a662d718f10c0402dd0fe5d01a779560d3f1b5bf76
@@ -4,7 +4,7 @@ require 'musa-dsl/core-ext/key-parameters-procedure-binder'
4
4
  require 'musa-dsl/series'
5
5
 
6
6
  class Musa::BaseSequencer
7
- attr_reader :ticks_per_bar, :tick_duration, :running_position
7
+ attr_reader :beats_per_bar, :ticks_per_beat, :ticks_per_bar, :tick_duration, :running_position
8
8
  attr_reader :everying, :playing, :moving
9
9
 
10
10
  @@tick_mutex = Mutex.new
@@ -13,9 +13,14 @@ class Musa::BaseSequencer
13
13
  do_log ||= false
14
14
 
15
15
  @on_debug_at = []
16
- @on_fast_forward = []
17
16
  @on_block_error = []
18
17
 
18
+ @before_tick = []
19
+ @on_fast_forward = []
20
+
21
+ @beats_per_bar = Rational(beats_per_bar)
22
+ @ticks_per_beat = Rational(ticks_per_beat)
23
+
19
24
  @ticks_per_bar = Rational(beats_per_bar * ticks_per_beat)
20
25
  @tick_duration = Rational(1, @ticks_per_bar)
21
26
 
@@ -44,6 +49,8 @@ class Musa::BaseSequencer
44
49
  def tick
45
50
  position_to_run = (@position += 1)
46
51
 
52
+ @before_tick.each { |block| block.call Rational(position_to_run, @ticks_per_bar) }
53
+
47
54
  if @score[position_to_run]
48
55
  @score[position_to_run].each do |command|
49
56
 
@@ -92,15 +99,19 @@ class Musa::BaseSequencer
92
99
  end
93
100
 
94
101
  def on_debug_at(&block)
95
- @on_debug_at << block
102
+ @on_debug_at << KeyParametersProcedureBinder.new(block)
96
103
  end
97
104
 
98
105
  def on_block_error(&block)
99
- @on_block_error << block
106
+ @on_block_error << KeyParametersProcedureBinder.new(block)
100
107
  end
101
108
 
102
109
  def on_fast_forward(&block)
103
- @on_fast_forward << block
110
+ @on_fast_forward << KeyParametersProcedureBinder.new(block)
111
+ end
112
+
113
+ def before_tick(&block)
114
+ @before_tick << KeyParametersProcedureBinder.new(block)
104
115
  end
105
116
 
106
117
  def position
@@ -3,8 +3,8 @@ require 'forwardable'
3
3
  class Musa::Sequencer
4
4
  extend Forwardable
5
5
 
6
- def_delegators :@sequencer, :raw_at, :tick, :on_debug_at, :on_block_error
7
- def_delegators :@sequencer, :on_fast_forward, :ticks_per_bar, :round, :position=, :size, :event_handler, :empty?
6
+ def_delegators :@sequencer, :raw_at, :tick, :on_debug_at, :on_block_error, :on_fast_forward, :before_tick
7
+ def_delegators :@sequencer, :beats_per_bar, :ticks_per_beat, :ticks_per_bar, :tick_duration, :round, :position=, :size, :event_handler, :empty?
8
8
 
9
9
  def_delegators :@context, :position, :log
10
10
  def_delegators :@context, :with, :now, :at, :wait, :play, :every, :move
@@ -6,7 +6,7 @@ module Musa
6
6
  @run = nil
7
7
  @on_start = []
8
8
  @on_stop = []
9
- @on_song_position_pointer = []
9
+ @on_change_position = []
10
10
  end
11
11
 
12
12
  def running?
@@ -21,8 +21,8 @@ module Musa
21
21
  @on_stop << block
22
22
  end
23
23
 
24
- def on_song_position_pointer(&block)
25
- @on_song_position_pointer << block
24
+ def on_change_position(&block)
25
+ @on_change_position << block
26
26
  end
27
27
 
28
28
  def run
@@ -112,12 +112,12 @@ module Musa
112
112
  yield if block_given? && @started
113
113
 
114
114
  when 'Song Position Pointer'
115
- midi_beat_position =
115
+ new_position_in_midi_beats =
116
116
  m.data[0] & 0x7F | ((m.data[1] & 0x7F) << 7)
117
117
 
118
- warn "InputMidiClock: processing Song Position Pointer midi_beat_position #{midi_beat_position}..." if @do_log
119
- @on_song_position_pointer.each { |block| block.call midi_beat_position }
120
- warn "InputMidiClock: processing Song Position Pointer midi_beat_position #{midi_beat_position}... done" if @do_log
118
+ warn "InputMidiClock: processing Song Position Pointer new_position_in_midi_beats #{new_position_in_midi_beats}..." if @do_log
119
+ @on_change_position.each { |block| block.call midi_beats: new_position_in_midi_beats }
120
+ warn "InputMidiClock: processing Song Position Pointer new_position_in_beats #{new_position_in_midi_beats}... done" if @do_log
121
121
  end
122
122
  end
123
123
  end
@@ -12,7 +12,6 @@ module Musa
12
12
  before_begin: nil,
13
13
  on_start: nil,
14
14
  after_stop: nil,
15
- before_each_tick: nil,
16
15
  on_position_change: nil,
17
16
  do_log: nil)
18
17
 
@@ -28,11 +27,8 @@ module Musa
28
27
  @on_start = []
29
28
  @on_start << KeyParametersProcedureBinder.new(on_start) if on_start
30
29
 
31
- @before_each_tick = []
32
- @before_each_tick << KeyParametersProcedureBinder.new(before_each_tick) if before_each_tick
33
-
34
- @on_position_change = []
35
- @on_position_change << KeyParametersProcedureBinder.new(on_position_change) if on_position_change
30
+ @on_change_position = []
31
+ @on_change_position << KeyParametersProcedureBinder.new(on_position_change) if on_position_change
36
32
 
37
33
  @after_stop = []
38
34
  @after_stop << KeyParametersProcedureBinder.new(after_stop) if after_stop
@@ -49,27 +45,8 @@ module Musa
49
45
  do_stop
50
46
  end
51
47
 
52
- @clock.on_song_position_pointer do |midi_beat_position|
53
- position = Rational(midi_beat_position, 4 * beats_per_bar) + 1
54
- tick_before_position = position - Rational(1, beats_per_bar * ticks_per_beat)
55
-
56
- warn "Transport: received message position change to #{position}" if @do_log
57
-
58
- start_again_later = false
59
-
60
- if @sequencer.position > tick_before_position
61
- do_stop
62
- start_again_later = true
63
- end
64
-
65
- warn "Transport: setting sequencer position #{tick_before_position}" if @do_log
66
- @sequencer.position = tick_before_position
67
-
68
- @sequencer.raw_at position, force_first: true do
69
- @on_position_change.each { |block| block.call @sequencer }
70
- end
71
-
72
- do_on_start if start_again_later
48
+ @clock.on_change_position do |bars: nil, beats: nil, midi_beats: nil|
49
+ change_position_to bars: bars, beats: beats, midi_beats: midi_beats
73
50
  end
74
51
  end
75
52
 
@@ -81,16 +58,12 @@ module Musa
81
58
  @on_start << KeyParametersProcedureBinder.new(block)
82
59
  end
83
60
 
84
- def before_each_tick(&block)
85
- @before_each_tick << KeyParametersProcedureBinder.new(block)
86
- end
87
-
88
61
  def after_stop(&block)
89
62
  @after_stop << KeyParametersProcedureBinder.new(block)
90
63
  end
91
64
 
92
- def on_position_change(&block)
93
- @on_position_change << KeyParametersProcedureBinder.new(block)
65
+ def on_change_position(&block)
66
+ @on_change_position << KeyParametersProcedureBinder.new(block)
94
67
  end
95
68
 
96
69
  def start
@@ -98,11 +71,38 @@ module Musa
98
71
 
99
72
  @clock.run do
100
73
  @before_begin_already_done = false
101
- @before_each_tick.each { |block| block.call @sequencer }
102
74
  @sequencer.tick
103
75
  end
104
76
  end
105
77
 
78
+ def change_position_to(bars: nil, beats: nil, midi_beats: nil)
79
+ position = bars.rationalize || 1r
80
+ position += Rational(midi_beats, 4 * @sequencer.beats_per_bar) if midi_beats
81
+ position += Rational(beats, @sequencer.beats_per_bar) if beats
82
+
83
+ raise ArgumentError, "undefined new position" unless position
84
+
85
+ tick_before_position = position - @sequencer.tick_duration
86
+
87
+ warn "Transport: received message position change to #{position}" if @do_log
88
+
89
+ start_again_later = false
90
+
91
+ if @sequencer.position > tick_before_position
92
+ do_stop
93
+ start_again_later = true
94
+ end
95
+
96
+ warn "Transport: setting sequencer position #{tick_before_position}" if @do_log
97
+ @sequencer.position = tick_before_position
98
+
99
+ @sequencer.raw_at position, force_first: true do
100
+ @on_change_position.each { |block| block.call @sequencer }
101
+ end
102
+
103
+ do_on_start if start_again_later
104
+ end
105
+
106
106
  def stop
107
107
  @clock.terminate
108
108
  end
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.14.18'
4
- s.date = '2019-09-29'
3
+ s.version = '0.14.26'
4
+ s.date = '2019-09-30'
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.14.18
4
+ version: 0.14.26
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: 2019-09-29 00:00:00.000000000 Z
11
+ date: 2019-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: citrus