Class: Topaz::Timer

Inherits:
Gamelan::Timer
  • Object
show all
Includes:
Pausable
Defined in:
lib/topaz/timer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pausable

#pause, #paused?, #toggle_pause, #unpause

Constructor Details

#initialize(tempo, options = {}) ⇒ Timer

Returns a new instance of Timer.

Parameters:

  • tempo (Fixnum)
  • options (Hash) (defaults to: {})

Options Hash (options):



13
14
15
16
17
18
19
20
21
22
# File 'lib/topaz/timer.rb', line 13

def initialize(tempo, options = {})
  @event = options[:event]
  @last_tick_event = 0
  @last_midi_clock = 0
  @pause = false
  @running = false
  self.interval = options[:interval] || 4 
  
  super({ :tempo => tempo })
end

Instance Attribute Details

#phaseObject (readonly)

Returns the value of attribute phase.



7
8
9
# File 'lib/topaz/timer.rb', line 7

def phase
  @phase
end

#runningObject (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

#intervalFixnum

The timer’s click interval

Returns:

  • (Fixnum)


44
45
46
# File 'lib/topaz/timer.rb', line 44

def interval
  @interval * 4
end

#interval=(value) ⇒ Fixnum

Set the timer’s click interval

Parameters:

  • value (Fixnum)

Returns:

  • (Fixnum)


38
39
40
# File 'lib/topaz/timer.rb', line 38

def interval=(value)
  @interval = value / 4
end

#joinTimer

Join the timer thread

Returns:



58
59
60
61
# File 'lib/topaz/timer.rb', line 58

def join
  super()
  self
end

#start(options = {}) ⇒ Timer

Start the internal timer

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :background (Boolean)

    Whether to run the timer in a background thread (default: false)

Returns:



28
29
30
31
32
33
# File 'lib/topaz/timer.rb', line 28

def start(options = {})
  run
  !@event.nil? && @event.do_start
  join unless !!options[:background]
  self
end

#stop(*a) ⇒ Timer

Stop the timer

Returns:



50
51
52
53
54
# File 'lib/topaz/timer.rb', line 50

def stop(*a)
  super()
  !@event.nil? && @event.do_stop
  self
end