Class: Topaz::Timer
- Inherits:
-
Gamelan::Timer
- Object
- Gamelan::Timer
- Topaz::Timer
- Includes:
- Pausable
- Defined in:
- lib/topaz/timer.rb
Instance Attribute Summary collapse
-
#phase ⇒ Object
readonly
Returns the value of attribute phase.
-
#running ⇒ Object
(also: #running?)
readonly
Returns the value of attribute running.
Instance Method Summary collapse
-
#initialize(tempo, options = {}) ⇒ Timer
constructor
A new instance of Timer.
-
#interval ⇒ Fixnum
The timer’s click interval.
-
#interval=(value) ⇒ Fixnum
Set the timer’s click interval.
-
#join ⇒ Timer
Join the timer thread.
-
#start(options = {}) ⇒ Timer
Start the internal timer.
-
#stop(*a) ⇒ Timer
Stop the timer.
Methods included from Pausable
#pause, #paused?, #toggle_pause, #unpause
Constructor Details
#initialize(tempo, options = {}) ⇒ Timer
Returns a new instance of Timer.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/topaz/timer.rb', line 13 def initialize(tempo, = {}) @event = [:event] @last_tick_event = 0 @last_midi_clock = 0 @pause = false @running = false self.interval = [:interval] || 4 super({ :tempo => tempo }) end |
Instance Attribute Details
#phase ⇒ Object (readonly)
Returns the value of attribute phase.
7 8 9 |
# File 'lib/topaz/timer.rb', line 7 def phase @phase end |
#running ⇒ Object (readonly) Also known as: running?
Returns the value of attribute running.
7 8 9 |
# File 'lib/topaz/timer.rb', line 7 def running @running end |
Instance Method Details
#interval ⇒ Fixnum
The timer’s click interval
44 45 46 |
# File 'lib/topaz/timer.rb', line 44 def interval @interval * 4 end |
#interval=(value) ⇒ Fixnum
Set the timer’s click interval
38 39 40 |
# File 'lib/topaz/timer.rb', line 38 def interval=(value) @interval = value / 4 end |
#join ⇒ Timer
Join the timer thread
58 59 60 61 |
# File 'lib/topaz/timer.rb', line 58 def join super() self end |
#start(options = {}) ⇒ Timer
Start the internal timer
28 29 30 31 32 33 |
# File 'lib/topaz/timer.rb', line 28 def start( = {}) run !@event.nil? && @event.do_start join unless !![:background] self end |
#stop(*a) ⇒ Timer
Stop the timer
50 51 52 53 54 |
# File 'lib/topaz/timer.rb', line 50 def stop(*a) super() !@event.nil? && @event.do_stop self end |