Class: Topaz::ExternalMIDITempo

Inherits:
Object
  • Object
show all
Includes:
TempoSource
Defined in:
lib/topaz/external_midi_tempo.rb

Overview

trigger an event based on received midi clock messages

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TempoSource

#do_midi_clock, #do_tick, #stop?

Constructor Details

#initialize(actions, input, options = {}) ⇒ ExternalMIDITempo

Returns a new instance of ExternalMIDITempo.



11
12
13
14
15
16
17
18
# File 'lib/topaz/external_midi_tempo.rb', line 11

def initialize(actions, input, options = {})
  @actions = actions
  self.interval = options[:interval] || 4
  @tempo_calculator = TempoCalculator.new
  @clock = MIDIEye::Listener.new(input)
  
  initialize_clock 
end

Instance Attribute Details

#clockObject (readonly)

Returns the value of attribute clock.



9
10
11
# File 'lib/topaz/external_midi_tempo.rb', line 9

def clock
  @clock
end

Instance Method Details

#intervalObject

return the interval at which the tick event is fired



60
61
62
# File 'lib/topaz/external_midi_tempo.rb', line 60

def interval
  4 * (24 / @per_tick)
end

#interval=(val) ⇒ Object

change the clock interval defaults to click once every 24 ticks or one quarter note which is the MIDI standard. however, if you wish to fire the on_tick event twice as often (or once per 12 clicks), pass 8

 1 = whole note
 2 = half note
 4 = quarter note
 6 = dotted quarter
 8 = eighth note
16 = sixteenth note
etc


54
55
56
57
# File 'lib/topaz/external_midi_tempo.rb', line 54

def interval=(val)
  per_qn = val / 4
  @per_tick = 24 / per_qn
end

#joinObject



35
36
37
38
# File 'lib/topaz/external_midi_tempo.rb', line 35

def join
  @clock.join
  self
end

#start(*a) ⇒ Object



25
26
27
28
# File 'lib/topaz/external_midi_tempo.rb', line 25

def start(*a)      
  @clock.start(*a)
  self
end

#stop(*a) ⇒ Object



30
31
32
33
# File 'lib/topaz/external_midi_tempo.rb', line 30

def stop(*a)
  @clock.stop
  self
end

#tempoObject

this will return a calculated tempo



21
22
23
# File 'lib/topaz/external_midi_tempo.rb', line 21

def tempo
  @tempo_calculator.find_tempo
end