Class: Topaz::ExternalMIDITempo

Inherits:
Object
  • Object
show all
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

Constructor Details

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



8
9
10
11
12
13
14
15
# File 'lib/topaz/external_midi_tempo.rb', line 8

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

  initialize_clock 
end

Instance Attribute Details

#clockObject (readonly)

Returns the value of attribute clock.



6
7
8
# File 'lib/topaz/external_midi_tempo.rb', line 6

def clock
  @clock
end

Instance Method Details

#intervalObject

Return the interval at which the tick event is fired



57
58
59
# File 'lib/topaz/external_midi_tempo.rb', line 57

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


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

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

#joinObject



32
33
34
35
# File 'lib/topaz/external_midi_tempo.rb', line 32

def join
  @clock.join
  self
end

#start(*a) ⇒ Object



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

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

#stop(*a) ⇒ Object



27
28
29
30
# File 'lib/topaz/external_midi_tempo.rb', line 27

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

#tempoObject

This will return a calculated tempo



18
19
20
# File 'lib/topaz/external_midi_tempo.rb', line 18

def tempo
  @tempo_calculator.find_tempo
end