Class: Topaz::MIDIClockInput
- Inherits:
-
Object
- Object
- Topaz::MIDIClockInput
- Includes:
- Pausable
- Defined in:
- lib/topaz/midi_clock_input.rb
Overview
Trigger an event based on received midi clock messages
Instance Attribute Summary collapse
-
#clock ⇒ Object
readonly
Returns the value of attribute clock.
-
#listening ⇒ Object
(also: #listening?)
readonly
Returns the value of attribute listening.
-
#running ⇒ Object
(also: #running?)
readonly
Returns the value of attribute running.
Instance Method Summary collapse
-
#initialize(input, options = {}) ⇒ MIDIClockInput
constructor
A new instance of MIDIClockInput.
-
#interval ⇒ Fixnum
Return the interval at which the tick event is fired.
-
#interval=(interval) ⇒ Fixnum
Change the clock interval Defaults to 4, which means click once every 24 ticks or one quarter note (per MIDI spec).
-
#join ⇒ MIDIInputClock
Join the listener thread.
-
#start(options = {}) ⇒ MIDIInputClock
Start the listener.
-
#stop(*a) ⇒ MIDIInputClock
Stop the listener.
-
#tempo ⇒ Fixnum
This will return a calculated tempo.
Methods included from Pausable
#pause, #paused?, #toggle_pause, #unpause
Constructor Details
#initialize(input, options = {}) ⇒ MIDIClockInput
Returns a new instance of MIDIClockInput.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/topaz/midi_clock_input.rb', line 15 def initialize(input, = {}) @event = [:event] @tick_counter = 0 @pause = false @listening = false @running = false @tempo_calculator = TempoCalculator.new @tick_threshold = interval_to_ticks(.fetch(:interval, 4)) initialize_listener(input) end |
Instance Attribute Details
#clock ⇒ Object (readonly)
Returns the value of attribute clock.
8 9 10 |
# File 'lib/topaz/midi_clock_input.rb', line 8 def clock @clock end |
#listening ⇒ Object (readonly) Also known as: listening?
Returns the value of attribute listening.
8 9 10 |
# File 'lib/topaz/midi_clock_input.rb', line 8 def listening @listening end |
#running ⇒ Object (readonly) Also known as: running?
Returns the value of attribute running.
8 9 10 |
# File 'lib/topaz/midi_clock_input.rb', line 8 def running @running end |
Instance Method Details
#interval ⇒ Fixnum
Return the interval at which the tick event is fired
83 84 85 |
# File 'lib/topaz/midi_clock_input.rb', line 83 def interval ticks_to_interval(@tick_threshold) end |
#interval=(interval) ⇒ Fixnum
Change the clock interval Defaults to 4, which means click once every 24 ticks or one quarter note (per MIDI spec). Therefore, to fire the on_tick event twice as often, pass 8
1 = whole note
2 = half note
4 = quarter note
6 = dotted quarter
8 = eighth note
16 = sixteenth note
etc
77 78 79 |
# File 'lib/topaz/midi_clock_input.rb', line 77 def interval=(interval) @tick_threshold = interval_to_ticks(interval) end |
#join ⇒ MIDIInputClock
Join the listener thread
58 59 60 61 |
# File 'lib/topaz/midi_clock_input.rb', line 58 def join @listener.join self end |
#start(options = {}) ⇒ MIDIInputClock
Start the listener
38 39 40 41 42 43 44 45 46 |
# File 'lib/topaz/midi_clock_input.rb', line 38 def start( = {}) @listening = true blocking = [:focus] || [:blocking] background = !blocking unless blocking.nil? background = [:background] if background.nil? background = false if background.nil? @listener.start(:background => background) self end |
#stop(*a) ⇒ MIDIInputClock
Stop the listener
50 51 52 53 54 |
# File 'lib/topaz/midi_clock_input.rb', line 50 def stop(*a) @listening = false @listener.stop self end |
#tempo ⇒ Fixnum
This will return a calculated tempo
29 30 31 |
# File 'lib/topaz/midi_clock_input.rb', line 29 def tempo @tempo_calculator.calculate end |