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.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/topaz/midi_clock_input.rb', line 16 def initialize(input, = {}) @event = [:event] @use_transport = !![:midi_transport] @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
85 86 87 |
# File 'lib/topaz/midi_clock_input.rb', line 85 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
79 80 81 |
# File 'lib/topaz/midi_clock_input.rb', line 79 def interval=(interval) @tick_threshold = interval_to_ticks(interval) end |
#join ⇒ MIDIInputClock
Join the listener thread
60 61 62 63 |
# File 'lib/topaz/midi_clock_input.rb', line 60 def join @listener.join self end |
#start(options = {}) ⇒ MIDIInputClock
Start the listener
40 41 42 43 44 45 46 47 48 |
# File 'lib/topaz/midi_clock_input.rb', line 40 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
52 53 54 55 56 |
# File 'lib/topaz/midi_clock_input.rb', line 52 def stop(*a) @listening = false @listener.stop self end |
#tempo ⇒ Fixnum
This will return a calculated tempo
31 32 33 |
# File 'lib/topaz/midi_clock_input.rb', line 31 def tempo @tempo_calculator.calculate end |