class MIDIJRuby::API::InputReceiver

Input event handler class

Attributes

stream[R]

Public Class Methods

new() click to toggle source
# File lib/midi-jruby/api.rb, line 125
def initialize
  @buffer = []
end

Public Instance Methods

close() click to toggle source
# File lib/midi-jruby/api.rb, line 152
def close
end
read() click to toggle source

Pluck messages from the buffer @return [Array<Array<Fixnum>>]

# File lib/midi-jruby/api.rb, line 131
def read
  messages = @buffer.dup
  @buffer.clear
  messages
end
send(message, timestamp = -1) click to toggle source

Add a new message to the buffer @param [Array<Fixnum>] message @param [Fixnum] timestamp @return [Array<Array<Fixnum>>]

# File lib/midi-jruby/api.rb, line 141
def send(message, timestamp = -1)
  bytes = if message.respond_to?(:get_packed_message)
    packed = message.get_packed_message
    unpack(packed)
  else
    string = String.from_java_bytes(message.get_message)
    string.unpack("C" * string.length)
  end
  @buffer << bytes
end

Private Instance Methods

unpack(message) click to toggle source

@param [String] @return [Array<Fixnum>]

# File lib/midi-jruby/api.rb, line 159
def unpack(message)
  bytes = []
  string = message.to_s(16)
  string = "0#{s}" if string.length.divmod(2).last > 0
  string = string.rjust(6,"0")
  while string.length > 0
    string_byte = string.slice!(0,2)
    bytes << string_byte.hex
  end
  bytes.reverse        
end