midi-topaz 0.2.1 → 0.2.2

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
  SHA1:
3
- metadata.gz: 0ce370c533a7d6bf26395da93632c35985e939c3
4
- data.tar.gz: 2d225a7fd71f4fe2390278fd63c1c50e4ac3e3b1
3
+ metadata.gz: c9f83fa43c38e0489f38bec2e2270421bd87d2e6
4
+ data.tar.gz: 2c4f5c820ce0eaf0fd330b8c232a47f6fcca0d5c
5
5
  SHA512:
6
- metadata.gz: 563c0fcec28ebd826488239e42b95ebab118b1d35f13bf50e590f2d44adff102da9a434c63990f370cbb9b1df20fa3ec8969a9269119a7b860e653c0ba31e4e2
7
- data.tar.gz: 8205a2ec2232efb86edb38d2ec0280cd4c69516ad6334e861fc8160ca03b19367551dc3fa3bc40c335b3121c1cd29814c022fe132d550b88cab964a9b123cc2f
6
+ metadata.gz: c2a78d859d6e086983421936fb68e7ccf7a780adf79eefa82189fc9c1380cac3bc0bd19187053c54c384b415dca482b83996f0e86ddb30f7f3f8045a3f8ba3de
7
+ data.tar.gz: 37ab0b21755412718141df5d1cf21c2ecdaadc68ba8b5e0b4e6e33cd880a0da041d39140002eea7fea09e7618aba23e41df27b4e592305fe136e65e293c79c16
data/README.md CHANGED
@@ -33,74 +33,63 @@ end
33
33
  sequencer = Sequencer.new
34
34
  ```
35
35
 
36
- The simplest application of Topaz is to create a clock to step that sequencer at a given rate. Using timing generated internally by your computer, the passed in block will be called repeatedly at 130 BPM
36
+ The Topaz clock can now be used to step that sequencer. Timed by Topaz, the passed in block will be called repeatedly at 130 BPM
37
37
 
38
38
  ```ruby
39
- @tempo = Topaz::Clock.new(130) { sequencer.step }
39
+ @clock = Topaz::Clock.new(130) { sequencer.step }
40
40
  ```
41
41
 
42
- You may also use another MIDI device to generate timing and control the tempo. The unimidi input to which that device is connected can be passed to the Tempo constructor
42
+ A MIDI device can be used to time and control the tempo. To accomplish this, pass a [unimidi](https://github.com/arirusso/unimidi) input to the Clock constructor
43
43
 
44
44
  ```ruby
45
- @input = UniMIDI::Input.first.open # an midi input
45
+ @input = UniMIDI::Input.gets # select a midi input
46
46
 
47
- @tempo = Topaz::Clock.new(@input) { sequencer.step }
47
+ @clock = Topaz::Clock.new(@input) { sequencer.step }
48
48
  ```
49
49
 
50
- Topaz can also act as a master clock. If a MIDI output is passed to Topaz, MIDI start, stop and clock signals will automatically be sent to that output at the appropriate time
50
+ Topaz can also act as a MIDI master clock. If a MIDI output is passed to Topaz, MIDI clock messages will automatically be sent to that output at the appropriate time
51
51
 
52
52
  ```ruby
53
- @output = UniMIDI::Output.first.open # a midi output
53
+ @output = UniMIDI::Output.gets # select a midi output
54
54
 
55
- @tempo = Topaz::Clock.new(120, :midi => @output) do
55
+ @clock = Topaz::Clock.new(120, :midi => @output) do
56
56
  sequencer.step
57
57
  end
58
58
  ```
59
59
 
60
- Input and multiple outputs can be used simultaneously
60
+ Input and multiple outputs can be used simultaneously, for MIDI thru
61
61
 
62
62
  ```ruby
63
- @tempo = Topaz::Clock.new(@input, :midi => [@output1, @output2]) do
63
+ @clock = Topaz::Clock.new(@input, :midi => [@output1, @output2]) do
64
64
  sequencer.step
65
65
  end
66
66
  ```
67
67
 
68
- Once the Tempo object is initialized, start the clock
68
+ Once the Clock object is initialized, start the clock
69
69
 
70
70
  ```ruby
71
- @tempo.start
71
+ @clock.start
72
72
  ```
73
73
 
74
- If you are syncing to external clock, nothing will happen until a "start" or "clock" message is received
75
-
76
- #### Other things to note
77
-
78
- Whether or not you are using an internal or external clock source, the event block will be called at quarter note intervals by default. If you wish to change this set the option :interval. In this case, the event will be fired 4 times per beat (16th notes) at 138 BPM
74
+ Topaz will run in a background thread if the option `:background => true` is passed in.
79
75
 
80
76
  ```ruby
81
- @tempo = Topaz::Clock.new(138, :interval => 16) do
82
- sequencer.step
83
- end
77
+ @clock.start(:background => true)
84
78
  ```
79
+
80
+ If you are syncing to an external MIDI source, this will start the listener waiting for MIDI clock messages.
85
81
 
86
- View the current tempo, which is calculated by Topaz if you're using an external MIDI source.
87
- (this feature is currently in-progress and may return some low values - 5/26/2011)
82
+ You can view the current tempo:
88
83
 
89
84
  ```ruby
90
- @tempo.tempo
85
+ @clock.tempo
91
86
  => 132.422000
92
87
  ```
93
-
94
- Run the generator in a background thread by passing :background => true to Tempo#start
95
-
96
- ```ruby
97
- @tempo.start(:background => true)
98
- ```
99
88
 
100
89
  Pass in a block that will stop the clock when it evaluates to true
101
90
 
102
91
  ```ruby
103
- @tempo.stop_when { @i.eql?(20) }
92
+ @clock.trigger.stop { @i == 20 }
104
93
  ```
105
94
 
106
95
  ## Documentation
data/lib/topaz/timer.rb CHANGED
@@ -69,10 +69,7 @@ module Topaz
69
69
  @thread = Thread.new do
70
70
  begin
71
71
  initialize_running_state
72
- loop do
73
- dispatch
74
- advance
75
- end
72
+ loop { perform }
76
73
  rescue Exception => exception
77
74
  Thread.main.raise(exception)
78
75
  end
@@ -88,22 +85,38 @@ module Topaz
88
85
  # @return [Boolean]
89
86
  def dispatch
90
87
  # Stuff to do on every tick
91
- if time_for_midi_clock?
92
- # look for stop
93
- !@event.nil? && @event.do_clock
94
- @last_midi_clock = (@phase * 24).to_i
95
- true
96
- end
88
+ clock if clock?
97
89
  # Stuff to do on @interval
98
- if time_for_tick?
99
- !@event.nil? && !@pause && @event.do_tick
100
- @last_tick_event = (@phase * @interval).to_i
101
- true
102
- end
90
+ tick if tick?
91
+ true
103
92
  end
104
93
 
105
94
  private
106
95
 
96
+ # Perform the timer function
97
+ # @return [Boolean]
98
+ def perform
99
+ dispatch
100
+ advance
101
+ true
102
+ end
103
+
104
+ # Perform a tick
105
+ # @return [Boolean]
106
+ def tick
107
+ !@event.nil? && !@pause && @event.do_tick
108
+ @last_tick_event = (@phase * @interval).to_i
109
+ true
110
+ end
111
+
112
+ # Perform MIDI clock
113
+ # @return [Boolean]
114
+ def clock
115
+ !@event.nil? && @event.do_clock
116
+ @last_midi_clock = (@phase * 24).to_i
117
+ true
118
+ end
119
+
107
120
  # Initialize the variables that handle the running process of the timer
108
121
  # @return [Boolean]
109
122
  def initialize_running_state
@@ -115,14 +128,14 @@ module Topaz
115
128
 
116
129
  # Is the current phase appropriate for MIDI clock output?
117
130
  # @return [Boolean]
118
- def time_for_midi_clock?
131
+ def clock?
119
132
  phase = (@phase * 24).to_i
120
133
  !@last_midi_clock.eql?(phase)
121
134
  end
122
135
 
123
136
  # Is the current phase appropriate for the tick event?
124
137
  # @return [Boolean]
125
- def time_for_tick?
138
+ def tick?
126
139
  phase = (@phase * @interval).to_i
127
140
  !@last_tick_event.eql?(phase)
128
141
  end
data/lib/topaz.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # MIDI syncable tempo module in Ruby
3
3
  # (c)2011-2014 Ari Russo and licensed under the Apache 2.0 License
4
- #
4
+ #
5
5
 
6
6
  # libs
7
7
  require "forwardable"
@@ -22,7 +22,7 @@ require "topaz/tempo_calculator"
22
22
  require "topaz/timer"
23
23
 
24
24
  module Topaz
25
-
26
- VERSION = "0.2.1"
27
-
25
+
26
+ VERSION = "0.2.2"
27
+
28
28
  end
data/test/clock_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class Topaz::ClockTest < Test::Unit::TestCase
3
+ class Topaz::ClockTest < Minitest::Test
4
4
 
5
5
  context "Clock" do
6
6
 
@@ -60,4 +60,3 @@ class Topaz::ClockTest < Test::Unit::TestCase
60
60
 
61
61
  end
62
62
  end
63
-
data/test/helper.rb CHANGED
@@ -1,20 +1,20 @@
1
1
  dir = File.dirname(File.expand_path(__FILE__))
2
2
  $LOAD_PATH.unshift dir + "/../lib"
3
3
 
4
- require "test/unit"
4
+ require "minitest/autorun"
5
5
  require "mocha/test_unit"
6
6
  require "shoulda-context"
7
7
  require "topaz"
8
8
 
9
9
  module TestHelper
10
-
10
+
11
11
  def self.select_devices
12
12
  $test_device ||= {}
13
13
  { :input => UniMIDI::Input, :output => UniMIDI::Output }.each do |type, klass|
14
14
  $test_device[type] = klass.gets
15
15
  end
16
16
  end
17
-
17
+
18
18
  end
19
19
 
20
20
  TestHelper.select_devices
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class Topaz::MIDIClockInputTest < Test::Unit::TestCase
3
+ class Topaz::MIDIClockInputTest < Minitest::Test
4
4
 
5
5
  context "MIDIClockInput" do
6
6
 
@@ -32,7 +32,7 @@ class Topaz::MIDIClockInputTest < Test::Unit::TestCase
32
32
 
33
33
  should "tick when counter has reached tick threshold" do
34
34
  assert_equal 4, @clock.interval
35
- 23.times do
35
+ 23.times do
36
36
  refute @clock.send(:tick?)
37
37
  @clock.send(:advance)
38
38
  end
@@ -45,7 +45,3 @@ class Topaz::MIDIClockInputTest < Test::Unit::TestCase
45
45
  end
46
46
 
47
47
  end
48
-
49
-
50
-
51
-
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class Topaz::MIDIClockOutputTest < Test::Unit::TestCase
3
+ class Topaz::MIDIClockOutputTest < Minitest::Test
4
4
 
5
5
  context "MIDIClockOutput" do
6
6
 
@@ -10,34 +10,52 @@ class Topaz::MIDIClockOutputTest < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  context "#do_start" do
13
-
14
- should "emit start message" do
13
+
14
+ setup do
15
15
  @output.expects(:puts).once.with(250)
16
+ end
17
+
18
+ teardown do
19
+ @output.unstub(:puts)
20
+ end
21
+
22
+ should "emit start message" do
16
23
  result = @clock.do_start
17
24
  assert result
18
- @output.unstub(:puts)
19
25
  end
20
26
 
21
27
  end
22
28
 
23
29
  context "#do_stop" do
24
30
 
25
- should "emit stop message" do
31
+ setup do
26
32
  @output.expects(:puts).once.with(252)
33
+ end
34
+
35
+ teardown do
36
+ @output.unstub(:puts)
37
+ end
38
+
39
+ should "emit stop message" do
27
40
  result = @clock.do_stop
28
41
  assert result
29
- @output.unstub(:puts)
30
42
  end
31
43
 
32
44
  end
33
45
 
34
46
  context "#do_clock" do
35
47
 
36
- should "emit clock message" do
48
+ setup do
37
49
  @output.expects(:puts).once.with(248)
50
+ end
51
+
52
+ teardown do
53
+ @output.unstub(:puts)
54
+ end
55
+
56
+ should "emit clock message" do
38
57
  result = @clock.do_clock
39
58
  assert result
40
- @output.unstub(:puts)
41
59
  end
42
60
 
43
61
  end
@@ -45,6 +63,3 @@ class Topaz::MIDIClockOutputTest < Test::Unit::TestCase
45
63
  end
46
64
 
47
65
  end
48
-
49
-
50
-
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class Topaz::TempoCalculatorTest < Test::Unit::TestCase
3
+ class Topaz::TempoCalculatorTest < Minitest::Test
4
4
 
5
5
  context "TempoCalculator" do
6
6
 
@@ -15,7 +15,7 @@ class Topaz::TempoCalculatorTest < Test::Unit::TestCase
15
15
  assert_nil @calc.calculate
16
16
  @calc.timestamps << 2
17
17
  @calc.timestamps << 3
18
- assert_not_nil @calc.calculate
18
+ refute_nil @calc.calculate
19
19
  end
20
20
 
21
21
  should "limit timestamps do within the threshold" do
@@ -27,7 +27,7 @@ class Topaz::TempoCalculatorTest < Test::Unit::TestCase
27
27
  should "express tempo" do
28
28
  5.times { |i| @calc.timestamps << Time.now.to_f; sleep(1.0 / 24.0) }
29
29
  result = @calc.calculate
30
- assert_not_nil result
30
+ refute_nil result
31
31
  assert (58..62).include?(result)
32
32
  end
33
33
 
@@ -36,4 +36,3 @@ class Topaz::TempoCalculatorTest < Test::Unit::TestCase
36
36
  end
37
37
 
38
38
  end
39
-
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class Topaz::TempoSourceTest < Test::Unit::TestCase
3
+ class Topaz::TempoSourceTest < Minitest::Test
4
4
 
5
5
  context "TempoSource" do
6
6
 
@@ -8,18 +8,18 @@ class Topaz::TempoSourceTest < Test::Unit::TestCase
8
8
 
9
9
  should "construct a timer" do
10
10
  result = Topaz::TempoSource.new(120)
11
- assert_not_nil result
11
+ refute_nil result
12
12
  assert_equal Topaz::Timer, result.class
13
13
  end
14
14
 
15
15
  should "construct a midi input clock" do
16
16
  result = Topaz::TempoSource.new($test_device[:input])
17
- assert_not_nil result
17
+ refute_nil result
18
18
  assert_equal Topaz::MIDIClockInput, result.class
19
19
  end
20
20
 
21
21
  should "throw an exception" do
22
- assert_raise RuntimeError do
22
+ assert_raises RuntimeError do
23
23
  Topaz::TempoSource.new("something")
24
24
  end
25
25
  end
@@ -29,5 +29,3 @@ class Topaz::TempoSourceTest < Test::Unit::TestCase
29
29
  end
30
30
 
31
31
  end
32
-
33
-
data/test/timer_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- class Topaz::TimerTest < Test::Unit::TestCase
3
+ class Topaz::TimerTest < Minitest::Test
4
4
 
5
5
  context "Timer" do
6
6
 
@@ -14,15 +14,16 @@ class Topaz::TimerTest < Test::Unit::TestCase
14
14
  @event = Object.new
15
15
  @timer = Topaz::Timer.new(120, :event => @event)
16
16
  @timer.send(:initialize_running_state)
17
+ @event.expects(:do_clock).once.returns(true)
18
+ @event.expects(:do_tick).once.returns(true)
17
19
  end
18
20
 
19
- should "fire MIDI clock event" do
20
- @event.expects(:do_clock).once.returns(true)
21
- @timer.send(:dispatch)
21
+ teardown do
22
+ @event.unstub(:do_clock)
23
+ @event.unstub(:do_tick)
22
24
  end
23
25
 
24
- should "fire tick event" do
25
- @event.expects(:do_tick).once.returns(true)
26
+ should "fire MIDI clock/tick events" do
26
27
  @timer.send(:dispatch)
27
28
  end
28
29
 
@@ -36,8 +37,8 @@ class Topaz::TimerTest < Test::Unit::TestCase
36
37
  loop until @timer.running?
37
38
 
38
39
  assert @timer.running?
39
- assert_not_nil @timer.phase
40
- assert_not_equal 0.0, @timer.phase
40
+ refute_nil @timer.phase
41
+ refute_equal 0.0, @timer.phase
41
42
  end
42
43
 
43
44
  end
@@ -53,14 +54,14 @@ class Topaz::TimerTest < Test::Unit::TestCase
53
54
  end
54
55
 
55
56
  should "stop running" do
56
- assert_not_nil @timer.phase
57
- assert_not_equal 0.0, @timer.phase
57
+ refute_nil @timer.phase
58
+ refute_equal 0.0, @timer.phase
58
59
  @timer.stop
59
60
  refute @timer.running?
60
61
  end
61
62
 
62
63
  end
63
-
64
+
64
65
  context "#interval=" do
65
66
 
66
67
  should "change interval" do
metadata CHANGED
@@ -1,15 +1,95 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midi-topaz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-25 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.5'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.5.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.5'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.5.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: mocha
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.1.0
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.1.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '10.4'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 10.4.2
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.4'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 10.4.2
73
+ - !ruby/object:Gem::Dependency
74
+ name: shoulda-context
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '1.2'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.2.1
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 1.2.1
13
93
  - !ruby/object:Gem::Dependency
14
94
  name: gamelan
15
95
  requirement: !ruby/object:Gem::Requirement
@@ -17,6 +97,9 @@ dependencies:
17
97
  - - "~>"
18
98
  - !ruby/object:Gem::Version
19
99
  version: '0'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0.3'
20
103
  type: :runtime
21
104
  prerelease: false
22
105
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,66 +107,69 @@ dependencies:
24
107
  - - "~>"
25
108
  - !ruby/object:Gem::Version
26
109
  version: '0'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0.3'
27
113
  - !ruby/object:Gem::Dependency
28
114
  name: midi-message
29
115
  requirement: !ruby/object:Gem::Requirement
30
116
  requirements:
31
117
  - - "~>"
32
118
  - !ruby/object:Gem::Version
33
- version: '0.0'
119
+ version: '0.4'
34
120
  - - ">="
35
121
  - !ruby/object:Gem::Version
36
- version: 0.0.4
122
+ version: 0.4.4
37
123
  type: :runtime
38
124
  prerelease: false
39
125
  version_requirements: !ruby/object:Gem::Requirement
40
126
  requirements:
41
127
  - - "~>"
42
128
  - !ruby/object:Gem::Version
43
- version: '0.0'
129
+ version: '0.4'
44
130
  - - ">="
45
131
  - !ruby/object:Gem::Version
46
- version: 0.0.4
132
+ version: 0.4.4
47
133
  - !ruby/object:Gem::Dependency
48
134
  name: midi-eye
49
135
  requirement: !ruby/object:Gem::Requirement
50
136
  requirements:
51
137
  - - "~>"
52
138
  - !ruby/object:Gem::Version
53
- version: '0.0'
139
+ version: '0.3'
54
140
  - - ">="
55
141
  - !ruby/object:Gem::Version
56
- version: 0.0.7
142
+ version: 0.3.7
57
143
  type: :runtime
58
144
  prerelease: false
59
145
  version_requirements: !ruby/object:Gem::Requirement
60
146
  requirements:
61
147
  - - "~>"
62
148
  - !ruby/object:Gem::Version
63
- version: '0.0'
149
+ version: '0.3'
64
150
  - - ">="
65
151
  - !ruby/object:Gem::Version
66
- version: 0.0.7
152
+ version: 0.3.7
67
153
  - !ruby/object:Gem::Dependency
68
154
  name: unimidi
69
155
  requirement: !ruby/object:Gem::Requirement
70
156
  requirements:
71
157
  - - "~>"
72
158
  - !ruby/object:Gem::Version
73
- version: '0.1'
159
+ version: '0.4'
74
160
  - - ">="
75
161
  - !ruby/object:Gem::Version
76
- version: 0.1.10
162
+ version: 0.4.6
77
163
  type: :runtime
78
164
  prerelease: false
79
165
  version_requirements: !ruby/object:Gem::Requirement
80
166
  requirements:
81
167
  - - "~>"
82
168
  - !ruby/object:Gem::Version
83
- version: '0.1'
169
+ version: '0.4'
84
170
  - - ">="
85
171
  - !ruby/object:Gem::Version
86
- version: 0.1.10
172
+ version: 0.4.6
87
173
  description: A flexible tempo source that is capable of synchronizing with MIDI clocks.
88
174
  email:
89
175
  - ari.russo@gmail.com