basic-sequencer 0.0.9 → 0.0.10
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 +4 -4
- data/lib/sequencer.rb +1 -1
- data/lib/sequencer/clock.rb +2 -99
- data/test/clock_test.rb +19 -25
- 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: 722856e8bef08a89038e702c392acc46669073da
|
4
|
+
data.tar.gz: 2b46f59d3783cce98365db2f86bf6dddfa555fdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3cc680925ca28a6271df0e2940d386ac8e373ff7680ada22a703b298512cc16cdeda0011116b426e41686769e10960b543faa3bea9d35b486407000de22c6bd
|
7
|
+
data.tar.gz: 15461e615f8c311657104dd77d504db9f277443c0a2ee6132bc48078ea2d7dc5e249f826fb3b288e991b7eab2181cb063a8a240f92c6478853a27d7c435f30d3
|
data/lib/sequencer.rb
CHANGED
data/lib/sequencer/clock.rb
CHANGED
@@ -1,103 +1,6 @@
|
|
1
1
|
module Sequencer
|
2
2
|
|
3
|
-
#
|
4
|
-
|
3
|
+
# Alias
|
4
|
+
Clock = Topaz::Clock
|
5
5
|
|
6
|
-
extend Forwardable
|
7
|
-
|
8
|
-
attr_reader :event
|
9
|
-
def_delegators :@clock, :pause, :stop, :tempo, :tempo=, :unpause
|
10
|
-
|
11
|
-
# @param [Fixnum, UniMIDI::Input] tempo_or_input
|
12
|
-
# @param [Hash] options
|
13
|
-
# @option options [Array<UniMIDI::Output>, UniMIDI::Output] :output (also: :outputs) MIDI output device(s)
|
14
|
-
def initialize(tempo_or_input, options = {})
|
15
|
-
@event = Event.new
|
16
|
-
outputs = options[:output] || options[:outputs]
|
17
|
-
resolution = options.fetch(:resolution, 128)
|
18
|
-
initialize_clock(tempo_or_input, resolution, :output => outputs)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Start the clock
|
22
|
-
# @param [Hash] options
|
23
|
-
# @option options [Boolean] :background Whether to run in the background
|
24
|
-
# @option options [Boolean] :blocking Whether to run in the foreground (also :focus, :foreground)
|
25
|
-
# @option options [Boolean] :suppress_clock Whether this clock is a sync-slave
|
26
|
-
# @return [Boolean]
|
27
|
-
def start(options = {})
|
28
|
-
clock_options = {}
|
29
|
-
clock_options[:background] = !!options[:background]
|
30
|
-
clock_options[:background] ||= ![:blocking, :focus, :foreground].any? { |key| !!options[key] }
|
31
|
-
@clock.start(clock_options) unless !!options[:suppress_clock]
|
32
|
-
Thread.abort_on_exception = true
|
33
|
-
end
|
34
|
-
|
35
|
-
# Add a MIDI clock output
|
36
|
-
# @param [Array<UniMIDI::Output>, UniMIDI::Output] output
|
37
|
-
# @return [Array<UniMIDI::Output>]
|
38
|
-
def add_midi_output(output)
|
39
|
-
outputs = [output].flatten
|
40
|
-
@clock.add_destination(outputs)
|
41
|
-
midi_outputs
|
42
|
-
end
|
43
|
-
|
44
|
-
# Remove a MIDI clock output
|
45
|
-
# @param [Array<UniMIDI::Output>, UniMIDI::Output] output
|
46
|
-
# @return [Array<UniMIDI::Output>]
|
47
|
-
def remove_midi_output(output)
|
48
|
-
outputs = [output].flatten
|
49
|
-
@clock.remove_destination(outputs)
|
50
|
-
midi_outputs
|
51
|
-
end
|
52
|
-
|
53
|
-
# The MIDI outputs
|
54
|
-
# @return [Array<UniMIDI::Output>]
|
55
|
-
def midi_outputs
|
56
|
-
@clock.destinations.map(&:output)
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
# Action taken by the clock on a tick. Fires the tick event
|
62
|
-
def on_tick
|
63
|
-
@event.do_tick
|
64
|
-
end
|
65
|
-
|
66
|
-
# Instantiate the underlying clock object
|
67
|
-
# @param [Fixnum, UniMIDI::Input] tempo_or_input
|
68
|
-
# @param [Fixnum] resolution
|
69
|
-
# @param [Hash] options
|
70
|
-
# @option options [Array<UniMIDI::Output>, UniMIDI::Output] :output MIDI output device(s)
|
71
|
-
def initialize_clock(tempo_or_input, resolution, options = {})
|
72
|
-
@clock = Topaz::Tempo.new(tempo_or_input, :midi => options[:output])
|
73
|
-
@clock.interval = @clock.interval * (resolution / @clock.interval)
|
74
|
-
@clock.on_tick { on_tick }
|
75
|
-
end
|
76
|
-
|
77
|
-
# Clock event callbacks
|
78
|
-
class Event
|
79
|
-
|
80
|
-
def initialize
|
81
|
-
@tick = []
|
82
|
-
end
|
83
|
-
|
84
|
-
# Access the tick event callback
|
85
|
-
# @param [Proc] block
|
86
|
-
# @return [Proc]
|
87
|
-
def tick(&block)
|
88
|
-
if block_given?
|
89
|
-
@tick.clear
|
90
|
-
@tick << block
|
91
|
-
end
|
92
|
-
@tick
|
93
|
-
end
|
94
|
-
|
95
|
-
# Fire the tick event callback
|
96
|
-
# @return [Boolean]
|
97
|
-
def do_tick
|
98
|
-
!@tick.empty? && @tick.map(&:call)
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
end
|
103
6
|
end
|
data/test/clock_test.rb
CHANGED
@@ -8,42 +8,36 @@ class Sequencer::ClockTest < Test::Unit::TestCase
|
|
8
8
|
@clock = Sequencer::Clock.new(120)
|
9
9
|
end
|
10
10
|
|
11
|
-
context "Clock#
|
11
|
+
context "Clock#midi_output" do
|
12
12
|
|
13
13
|
should "get MIDI output" do
|
14
14
|
output = Object.new
|
15
|
-
@clock = Sequencer::Clock.new(120, :
|
16
|
-
assert_not_nil @clock.
|
17
|
-
assert_not_empty @clock.
|
18
|
-
assert @clock.
|
15
|
+
@clock = Sequencer::Clock.new(120, :midi => output)
|
16
|
+
assert_not_nil @clock.midi_output.devices
|
17
|
+
assert_not_empty @clock.midi_output.devices
|
18
|
+
assert @clock.midi_output.devices.include?(output)
|
19
19
|
end
|
20
20
|
|
21
|
-
end
|
22
|
-
|
23
|
-
context "Clock#add_midi_output" do
|
24
|
-
|
25
21
|
should "add MIDI output" do
|
26
22
|
output = Object.new
|
27
|
-
refute @clock.
|
28
|
-
@clock.
|
29
|
-
assert_not_nil @clock.
|
30
|
-
assert_not_empty @clock.
|
31
|
-
assert @clock.
|
23
|
+
refute @clock.midi_output.devices.include?(output)
|
24
|
+
@clock.midi_output.devices << output
|
25
|
+
assert_not_nil @clock.midi_output.devices
|
26
|
+
assert_not_empty @clock.midi_output.devices
|
27
|
+
assert @clock.midi_output.devices.include?(output)
|
32
28
|
end
|
33
29
|
|
34
|
-
end
|
35
|
-
|
36
|
-
context "Clock#remove_midi_output" do
|
37
|
-
|
38
30
|
should "remove MIDI output" do
|
39
31
|
output = Object.new
|
40
|
-
refute @clock.
|
41
|
-
@clock.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@clock.
|
46
|
-
|
32
|
+
refute @clock.midi_output.devices.include?(output)
|
33
|
+
@clock.midi_output.devices << output
|
34
|
+
|
35
|
+
assert_not_nil @clock.midi_output.devices
|
36
|
+
assert_not_empty @clock.midi_output.devices
|
37
|
+
assert @clock.midi_output.devices.include?(output)
|
38
|
+
|
39
|
+
@clock.midi_output.devices.delete(output)
|
40
|
+
refute @clock.midi_output.devices.include?(output)
|
47
41
|
end
|
48
42
|
|
49
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basic-sequencer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
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-
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: midi-topaz
|