class Topaz::MIDIClockOutput

Send clock messages via MIDI

Attributes

devices[R]

Public Class Methods

new(options) click to toggle source

@param [Hash] options @option options [Array<UniMIDI::Output>, UniMIDI::Output] :device

# File lib/topaz/midi_clock_output.rb, line 10
def initialize(options)
  device = options[:device] || options[:devices]
  @devices = [device].flatten.compact
end

Public Instance Methods

do_clock(*a) click to toggle source

Send a clock tick message @return [Boolean] Whether a message was emitted

# File lib/topaz/midi_clock_output.rb, line 33
def do_clock(*a)
  clock = MIDIMessage::SystemRealtime["Clock"].new
  emit(clock)
  !@devices.empty?
end
do_start(*a) click to toggle source

Send a start message @return [Boolean] Whether a message was emitted

# File lib/topaz/midi_clock_output.rb, line 17
def do_start(*a)
  start = MIDIMessage::SystemRealtime["Start"].new
  emit(start)
  !@devices.empty?
end
do_stop(*a) click to toggle source

Send a stop message @return [Boolean] Whether a message was emitted

# File lib/topaz/midi_clock_output.rb, line 25
def do_stop(*a)
  stop = MIDIMessage::SystemRealtime["Stop"].new
  emit(stop)
  !@devices.empty?
end

Private Instance Methods

emit(message) click to toggle source

Emit a message to the devices @param [MIDIMessage] message

# File lib/topaz/midi_clock_output.rb, line 43
def emit(message)
  @devices.each { |device| device.puts(*message.to_bytes) }
end