Class: Musa::Clock::TimerClock
- Inherits:
-
Clock
- Object
- Clock
- Musa::Clock::TimerClock
show all
- Defined in:
- lib/musa-dsl/transport/timer-clock.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Clock
#on_change_position, #on_start, #on_stop, #running?
Constructor Details
#initialize(period = nil, ticks_per_beat: nil, bpm: nil, correction: nil, delayed_ticks_error: nil, logger: nil, do_log: nil) ⇒ TimerClock
Returns a new instance of TimerClock.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/musa-dsl/transport/timer-clock.rb', line 6
def initialize(period = nil, ticks_per_beat: nil, bpm: nil, correction: nil, delayed_ticks_error: nil, logger: nil, do_log: nil)
do_log ||= false
super()
@correction = correction
self.period = period if period
self.ticks_per_beat = ticks_per_beat if ticks_per_beat
self.bpm = bpm if bpm
self.bpm ||= 120
self.ticks_per_beat ||= 24
@started = false
@paused = false
@delayed_ticks_error = delayed_ticks_error
@logger = logger
@do_log = do_log
end
|
Instance Attribute Details
#bpm ⇒ Object
Returns the value of attribute bpm.
28
29
30
|
# File 'lib/musa-dsl/transport/timer-clock.rb', line 28
def bpm
@bpm
end
|
#period ⇒ Object
Returns the value of attribute period.
28
29
30
|
# File 'lib/musa-dsl/transport/timer-clock.rb', line 28
def period
@period
end
|
#ticks_per_beat ⇒ Object
Returns the value of attribute ticks_per_beat.
28
29
30
|
# File 'lib/musa-dsl/transport/timer-clock.rb', line 28
def ticks_per_beat
@ticks_per_beat
end
|
Instance Method Details
#continue ⇒ Object
98
99
100
101
102
103
|
# File 'lib/musa-dsl/transport/timer-clock.rb', line 98
def continue
if @started && @paused
@paused = false
@timer.continue
end
end
|
#pause ⇒ Object
91
92
93
94
95
96
|
# File 'lib/musa-dsl/transport/timer-clock.rb', line 91
def pause
if @started && !@paused
@timer.stop
@paused = true
end
end
|
#paused? ⇒ Boolean
52
53
54
|
# File 'lib/musa-dsl/transport/timer-clock.rb', line 52
def paused?
@paused
end
|
#run ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/musa-dsl/transport/timer-clock.rb', line 56
def run
@run = true
while @run
@timer = Timer.new(@period,
correction: @correction,
stop: true,
delayed_ticks_error: @delayed_ticks_error,
logger: @logger,
do_log: @do_log)
@timer.run do
yield if block_given?
end
end
end
|
#start ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/musa-dsl/transport/timer-clock.rb', line 73
def start
unless @started
@on_start.each(&:call)
@started = true
@paused = false
@timer.continue
end
end
|
#started? ⇒ Boolean
48
49
50
|
# File 'lib/musa-dsl/transport/timer-clock.rb', line 48
def started?
@started
end
|
#stop ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/musa-dsl/transport/timer-clock.rb', line 82
def stop
if @started
@timer.stop
@started = false
@paused = false
@on_stop.each(&:call)
end
end
|
#terminate ⇒ Object
105
106
107
|
# File 'lib/musa-dsl/transport/timer-clock.rb', line 105
def terminate
@run = false
end
|