Class: Topaz::Clock
Overview
The main tempo clock
Defined Under Namespace
Classes: Event, EventTrigger
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#midi_output ⇒ Object
readonly
Returns the value of attribute midi_output.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#trigger ⇒ Object
readonly
Returns the value of attribute trigger.
Instance Method Summary collapse
-
#initialize(tempo_or_input, options = {}, &tick_event) ⇒ Clock
constructor
A new instance of Clock.
-
#start(options = {}) ⇒ Boolean
This will start the clock source.
-
#stop(options = {}) ⇒ Boolean
This will stop the clock source.
-
#tempo=(value) ⇒ ExternalMIDITempo, InternalTempo
Set the tempo.
-
#time ⇒ Float
Seconds since start was called.
Methods included from API
Constructor Details
#initialize(tempo_or_input, options = {}, &tick_event) ⇒ Clock
Returns a new instance of Clock.
14 15 16 17 18 19 20 21 22 |
# File 'lib/topaz/clock.rb', line 14 def initialize(tempo_or_input, = {}, &tick_event) # The MIDI clock output is initialized regardless of whether there are devices # so that it is ready if any are added during the running process. @midi_output = MIDIClockOutput.new(:devices => [:midi]) @event = Event.new @trigger = EventTrigger.new @source = TempoSource.new(tempo_or_input, .merge({ :event => @event })) initialize_events(&tick_event) end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
8 9 10 |
# File 'lib/topaz/clock.rb', line 8 def event @event end |
#midi_output ⇒ Object (readonly)
Returns the value of attribute midi_output.
8 9 10 |
# File 'lib/topaz/clock.rb', line 8 def midi_output @midi_output end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
8 9 10 |
# File 'lib/topaz/clock.rb', line 8 def source @source end |
#trigger ⇒ Object (readonly)
Returns the value of attribute trigger.
8 9 10 |
# File 'lib/topaz/clock.rb', line 8 def trigger @trigger end |
Instance Method Details
#start(options = {}) ⇒ Boolean
This will start the clock source
In the case that external midi tempo is being used, this will instead start the process of waiting for a start or clock message
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/topaz/clock.rb', line 46 def start( = {}) @start_time = Time.now begin @source.start() rescue SystemExit, Interrupt => exception stop raise exception end true end |
#stop(options = {}) ⇒ Boolean
This will stop the clock source
60 61 62 63 64 |
# File 'lib/topaz/clock.rb', line 60 def stop( = {}) @source.stop() @start_time = nil true end |
#tempo=(value) ⇒ ExternalMIDITempo, InternalTempo
Set the tempo
If external MIDI tempo is being used, this will switch to internal tempo at the desired rate.
30 31 32 33 34 35 36 |
# File 'lib/topaz/clock.rb', line 30 def tempo=(value) if @source.respond_to?(:tempo=) @source.tempo = value else @source = TempoSource.new(event, tempo_or_input) end end |
#time ⇒ Float
Seconds since start was called
68 69 70 |
# File 'lib/topaz/clock.rb', line 68 def time (Time.now - @start_time).to_f unless @start_time.nil? end |