midi-topaz 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +17 -17
- data/lib/topaz/midi_clock_input.rb +21 -19
- data/lib/topaz.rb +6 -3
- data/test/tempo_calculator_test.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b9cba48a0b78793392c1fae95b1e3076efe30ac
|
4
|
+
data.tar.gz: 6af1e277ed9207f1f4f371a664e04006d8b12e0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 730961e16d0f611f3050a055ea75707745ab506104a7acb8785eede167097cc0ad5de9db9a2be2b8d7670d6b452c77091c28d7ab5628ef247322d40f06d76e01
|
7
|
+
data.tar.gz: 7130706af9d7f3c4eeb1f758cb94e54a0f884f807889169506e5c6c95b3d053d48e46419d34018171555a8b74e376fd940a6edd8fd7d04ac47efe67c0bbb2a95
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -7,10 +7,10 @@ MIDI syncable tempo in Ruby
|
|
7
7
|
## Installation
|
8
8
|
|
9
9
|
`gem install midi-topaz`
|
10
|
-
|
10
|
+
|
11
11
|
or with Bundler, add this to your Gemfile
|
12
|
-
|
13
|
-
`gem "midi-topaz"`
|
12
|
+
|
13
|
+
`gem "midi-topaz"`
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
@@ -22,14 +22,14 @@ For demonstration purposes, here's a mock sequencer class and object
|
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
class Sequencer
|
25
|
-
|
25
|
+
|
26
26
|
def step
|
27
27
|
@i ||= 0
|
28
28
|
puts "step #{@i+=1}"
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
sequencer = Sequencer.new
|
34
34
|
```
|
35
35
|
|
@@ -39,19 +39,19 @@ The Topaz clock can now be used to step that sequencer. Timed by Topaz, the pas
|
|
39
39
|
@clock = Topaz::Clock.new(130) { sequencer.step }
|
40
40
|
```
|
41
41
|
|
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
|
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.gets # select a midi input
|
46
|
-
|
45
|
+
@input = UniMIDI::Input.gets # select a midi input
|
46
|
+
|
47
47
|
@clock = Topaz::Clock.new(@input) { sequencer.step }
|
48
48
|
```
|
49
|
-
|
49
|
+
|
50
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.gets # select a midi output
|
54
|
-
|
53
|
+
@output = UniMIDI::Output.gets # select a midi output
|
54
|
+
|
55
55
|
@clock = Topaz::Clock.new(120, :midi => @output) do
|
56
56
|
sequencer.step
|
57
57
|
end
|
@@ -60,7 +60,7 @@ end
|
|
60
60
|
Input and multiple outputs can be used simultaneously, for MIDI thru
|
61
61
|
|
62
62
|
```ruby
|
63
|
-
@clock = 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
|
```
|
@@ -78,20 +78,20 @@ Topaz will run in a background thread if the option `:background => true` is pas
|
|
78
78
|
```
|
79
79
|
|
80
80
|
If you are syncing to an external MIDI source, this will start the listener waiting for MIDI clock messages.
|
81
|
-
|
81
|
+
|
82
82
|
You can view the current tempo:
|
83
83
|
|
84
84
|
```ruby
|
85
85
|
@clock.tempo
|
86
86
|
=> 132.422000
|
87
87
|
```
|
88
|
-
|
88
|
+
|
89
89
|
Pass in a block that will stop the clock when it evaluates to true
|
90
90
|
|
91
91
|
```ruby
|
92
92
|
@clock.trigger.stop { @i == 20 }
|
93
93
|
```
|
94
|
-
|
94
|
+
|
95
95
|
## Documentation
|
96
96
|
|
97
97
|
* [examples](http://github.com/arirusso/topaz/tree/master/examples)
|
@@ -105,4 +105,4 @@ Pass in a block that will stop the clock when it evaluates to true
|
|
105
105
|
|
106
106
|
Apache 2.0, See the file LICENSE
|
107
107
|
|
108
|
-
Copyright (c) 2011-
|
108
|
+
Copyright (c) 2011-2015 [Ari Russo](http://arirusso.com)
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module Topaz
|
2
|
-
|
2
|
+
|
3
3
|
# Trigger an event based on received midi clock messages
|
4
4
|
class MIDIClockInput
|
5
|
-
|
5
|
+
|
6
6
|
include Pausable
|
7
7
|
|
8
8
|
attr_reader :clock, :listening, :running
|
9
9
|
alias_method :listening?, :listening
|
10
10
|
alias_method :running?, :running
|
11
|
-
|
11
|
+
|
12
12
|
# @param [UniMIDI::Input] input
|
13
13
|
# @param [Hash] options
|
14
14
|
# @option options [Clock::Event] :event
|
@@ -23,26 +23,28 @@ module Topaz
|
|
23
23
|
|
24
24
|
initialize_listener(input)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
# This will return a calculated tempo
|
28
28
|
# @return [Fixnum]
|
29
29
|
def tempo
|
30
30
|
@tempo_calculator.calculate
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
# Start the listener
|
34
34
|
# @param [Hash] options
|
35
35
|
# @option options [Boolean] :background Whether to run the listener in a background process
|
36
36
|
# @option options [Boolean] :focus (or :blocking) Whether to run the listener in a foreground process
|
37
37
|
# @return [MIDIInputClock] self
|
38
|
-
def start(options = {})
|
38
|
+
def start(options = {})
|
39
39
|
@listening = true
|
40
40
|
blocking = options[:focus] || options[:blocking]
|
41
|
-
background =
|
41
|
+
background = !blocking unless blocking.nil?
|
42
|
+
background = options[:background] if background.nil?
|
43
|
+
background = false if background.nil?
|
42
44
|
@listener.start(:background => background)
|
43
45
|
self
|
44
46
|
end
|
45
|
-
|
47
|
+
|
46
48
|
# Stop the listener
|
47
49
|
# @return [MIDIInputClock] self
|
48
50
|
def stop(*a)
|
@@ -50,17 +52,17 @@ module Topaz
|
|
50
52
|
@listener.stop
|
51
53
|
self
|
52
54
|
end
|
53
|
-
|
55
|
+
|
54
56
|
# Join the listener thread
|
55
57
|
# @return [MIDIInputClock] self
|
56
58
|
def join
|
57
59
|
@listener.join
|
58
60
|
self
|
59
61
|
end
|
60
|
-
|
62
|
+
|
61
63
|
# Change the clock interval
|
62
64
|
# Defaults to 4, which means click once every 24 ticks or one quarter note (per MIDI spec).
|
63
|
-
# Therefore, to fire the on_tick event twice as often, pass 8
|
65
|
+
# Therefore, to fire the on_tick event twice as often, pass 8
|
64
66
|
#
|
65
67
|
# 1 = whole note
|
66
68
|
# 2 = half note
|
@@ -75,13 +77,13 @@ module Topaz
|
|
75
77
|
def interval=(interval)
|
76
78
|
@tick_threshold = interval_to_ticks(interval)
|
77
79
|
end
|
78
|
-
|
80
|
+
|
79
81
|
# Return the interval at which the tick event is fired
|
80
82
|
# @return [Fixnum]
|
81
83
|
def interval
|
82
84
|
ticks_to_interval(@tick_threshold)
|
83
85
|
end
|
84
|
-
|
86
|
+
|
85
87
|
private
|
86
88
|
|
87
89
|
# Convert a note interval to number of ticks
|
@@ -99,14 +101,14 @@ module Topaz
|
|
99
101
|
note_value = 24 / ticks
|
100
102
|
4 * note_value
|
101
103
|
end
|
102
|
-
|
104
|
+
|
103
105
|
# Initialize the MIDI input listener
|
104
106
|
# @param [UniMIDI::Input] input
|
105
107
|
# @return [MIDIEye::Listener]
|
106
108
|
def initialize_listener(input)
|
107
109
|
@listener = MIDIEye::Listener.new(input)
|
108
|
-
@listener.listen_for(:name => "Clock") { |message| handle_clock_message(message) }
|
109
|
-
@listener.listen_for(:name => "Start") { handle_start_message }
|
110
|
+
@listener.listen_for(:name => "Clock") { |message| handle_clock_message(message) }
|
111
|
+
@listener.listen_for(:name => "Start") { handle_start_message }
|
110
112
|
@listener.listen_for(:name => "Stop") { handle_stop_message }
|
111
113
|
@listener
|
112
114
|
end
|
@@ -178,9 +180,9 @@ module Topaz
|
|
178
180
|
# Should the tick event be fired given the current state?
|
179
181
|
# @return [Boolean]
|
180
182
|
def tick?
|
181
|
-
@tick_counter >=
|
183
|
+
@tick_counter >= @tick_threshold - 1
|
182
184
|
end
|
183
|
-
|
185
|
+
|
184
186
|
end
|
185
|
-
|
187
|
+
|
186
188
|
end
|
data/lib/topaz.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
#
|
2
|
-
#
|
3
|
-
#
|
2
|
+
# Topaz
|
3
|
+
# MIDI syncable tempo in Ruby
|
4
|
+
#
|
5
|
+
# (c)2011-2015 Ari Russo
|
6
|
+
# Apache 2.0 License
|
4
7
|
#
|
5
8
|
|
6
9
|
# libs
|
@@ -23,6 +26,6 @@ require "topaz/timer"
|
|
23
26
|
|
24
27
|
module Topaz
|
25
28
|
|
26
|
-
VERSION = "0.2.
|
29
|
+
VERSION = "0.2.4"
|
27
30
|
|
28
31
|
end
|
@@ -25,10 +25,10 @@ class Topaz::TempoCalculatorTest < Minitest::Test
|
|
25
25
|
end
|
26
26
|
|
27
27
|
should "express tempo" do
|
28
|
-
5.times { |i| @calc.timestamps <<
|
28
|
+
5.times { |i| @calc.timestamps << i * (1.0 / 24.0) }
|
29
29
|
result = @calc.calculate
|
30
30
|
refute_nil result
|
31
|
-
|
31
|
+
assert_equal 60, result
|
32
32
|
end
|
33
33
|
|
34
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midi-topaz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ari Russo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|