musa-dsl 0.14.26 → 0.14.29

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: 9fda568f7b4eef0b94479ab3f9e5833a130d82ba2386687607a0a4193c292f0e
4
- data.tar.gz: e7366f81def8b65c0977c004ef02a50ce01472a1c5a29b5b9ec0916ff1989538
3
+ metadata.gz: 8f74dd3331fee5343754a2a50d2a8b449588e2bf4355bcc0c040aae1d3947ed4
4
+ data.tar.gz: '009c5e942ef81604a8c0742deb8ad0c54e196a4236e0f3d5635948754194d7d1'
5
5
  SHA512:
6
- metadata.gz: 1d78176e99d1746d2eba617fac89602c56bc4aa8a165d7f0ee1e696b726f52c0b7a89347b313e47d2d5e6252cb3f2c5d0627af0a68a6ccb0deb10d3f1c3a4ceb
7
- data.tar.gz: c16e547be13a8c6592722afbc6cb6a8b571a8930b0c0079b9067baee43c4c237b1123fff554674bd572c68a662d718f10c0402dd0fe5d01a779560d3f1b5bf76
6
+ metadata.gz: 1b731f4fc517e25458f7592ef2e79b6ed4b15ef9ba2e08d099879cb1ba83075da8fdb677a76ac937a42efad4e99f4d40b1e43949cc0b06e11d8c396cd31beea2
7
+ data.tar.gz: e245ea33a9f473a8676c9ace488287f33977bb66e8dc0bfc24fc3737ef4fcabe461ba05303aa96bafe974b85127f0fc258b81100ea0dbdd8d954f1c5aa73e228
@@ -7,6 +7,54 @@ require_relative 'base-sequencer-implementation-play-helper'
7
7
  class Musa::BaseSequencer
8
8
  private
9
9
 
10
+ def _tick
11
+ position_to_run = @position_mutex.synchronize { @position += 1 }
12
+
13
+ @before_tick.each { |block| block.call Rational(position_to_run, @ticks_per_bar) }
14
+
15
+ if @score[position_to_run]
16
+ @score[position_to_run].each do |command|
17
+
18
+ if command.key?(:parent_control) && !command[:parent_control].stopped?
19
+ @event_handlers.push command[:parent_control]
20
+
21
+ @@tick_mutex.synchronize do
22
+ original_stdout = $stdout
23
+ original_stderr = $stderr
24
+
25
+ $stdout = command[:parent_control].stdout
26
+ $stderr = command[:parent_control].stderr
27
+
28
+ command[:block]._call command[:value_parameters], command[:key_parameters] if command[:block]
29
+
30
+ $stdout = original_stdout
31
+ $stderr = original_stderr
32
+ end
33
+
34
+ @event_handlers.pop
35
+ else
36
+ @@tick_mutex.synchronize do
37
+ command[:block]._call command[:value_parameters], command[:key_parameters] if command[:block]
38
+ end
39
+ end
40
+ end
41
+
42
+ @score.delete position_to_run
43
+ end
44
+
45
+ Thread.pass
46
+ end
47
+
48
+ def _hold_public_ticks
49
+ @hold_public_ticks = true
50
+ end
51
+
52
+ def _release_public_ticks
53
+ @hold_ticks.times { _tick }
54
+ @hold_ticks = 0
55
+ @hold_public_ticks = false
56
+ end
57
+
10
58
  def _raw_numeric_at(bar_position, force_first: nil, &block)
11
59
  force_first ||= false
12
60
 
@@ -24,6 +24,10 @@ class Musa::BaseSequencer
24
24
  @ticks_per_bar = Rational(beats_per_bar * ticks_per_beat)
25
25
  @tick_duration = Rational(1, @ticks_per_bar)
26
26
 
27
+ @position_mutex = Mutex.new
28
+ @hold_public_ticks = false
29
+ @hold_ticks = 0
30
+
27
31
  @score = {}
28
32
 
29
33
  @everying = []
@@ -43,42 +47,14 @@ class Musa::BaseSequencer
43
47
 
44
48
  @event_handlers = [EventHandler.new]
45
49
 
46
- @position = @ticks_per_bar - 1
50
+ @position = @position_mutex.synchronize { @ticks_per_bar - 1 }
47
51
  end
48
52
 
49
53
  def tick
50
- position_to_run = (@position += 1)
51
-
52
- @before_tick.each { |block| block.call Rational(position_to_run, @ticks_per_bar) }
53
-
54
- if @score[position_to_run]
55
- @score[position_to_run].each do |command|
56
-
57
- if command.key?(:parent_control) && !command[:parent_control].stopped?
58
- @event_handlers.push command[:parent_control]
59
-
60
- @@tick_mutex.synchronize do
61
- original_stdout = $stdout
62
- original_stderr = $stderr
63
-
64
- $stdout = command[:parent_control].stdout
65
- $stderr = command[:parent_control].stderr
66
-
67
- command[:block]._call command[:value_parameters], command[:key_parameters] if command[:block]
68
-
69
- $stdout = original_stdout
70
- $stderr = original_stderr
71
- end
72
-
73
- @event_handlers.pop
74
- else
75
- @@tick_mutex.synchronize do
76
- command[:block]._call command[:value_parameters], command[:key_parameters] if command[:block]
77
- end
78
- end
79
- end
80
-
81
- @score.delete position_to_run
54
+ if @hold_public_ticks
55
+ @hold_ticks += 1
56
+ else
57
+ _tick
82
58
  end
83
59
  end
84
60
 
@@ -123,11 +99,13 @@ class Musa::BaseSequencer
123
99
 
124
100
  raise ArgumentError, "Sequencer #{self}: cannot move back. current position: #{@position} new position: #{position}" if position < @position
125
101
 
102
+ _hold_public_ticks
126
103
  @on_fast_forward.each { |block| block.call(true) }
127
104
 
128
- tick while @position < position
105
+ _tick while @position < position
129
106
 
130
107
  @on_fast_forward.each { |block| block.call(false) }
108
+ _release_public_ticks
131
109
  end
132
110
 
133
111
  def on(event, &block)
@@ -82,24 +82,23 @@ module Musa
82
82
 
83
83
  raise ArgumentError, "undefined new position" unless position
84
84
 
85
- tick_before_position = position - @sequencer.tick_duration
86
-
87
85
  warn "Transport: received message position change to #{position}" if @do_log
88
86
 
89
87
  start_again_later = false
90
88
 
91
- if @sequencer.position > tick_before_position
89
+ if @sequencer.position > position
92
90
  do_stop
93
91
  start_again_later = true
94
92
  end
95
93
 
96
- warn "Transport: setting sequencer position #{tick_before_position}" if @do_log
97
- @sequencer.position = tick_before_position
94
+ warn "Transport: setting sequencer position #{position}" if @do_log
98
95
 
99
96
  @sequencer.raw_at position, force_first: true do
100
97
  @on_change_position.each { |block| block.call @sequencer }
101
98
  end
102
99
 
100
+ @sequencer.position = position
101
+
103
102
  do_on_start if start_again_later
104
103
  end
105
104
 
data/musa-dsl.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'musa-dsl'
3
- s.version = '0.14.26'
3
+ s.version = '0.14.29'
4
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)'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musa-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.26
4
+ version: 0.14.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Sánchez Yeste