Class: MIDIJRuby::API::InputReceiver

Inherits:
Object
  • Object
show all
Defined in:
lib/midi-jruby/api.rb

Overview

Input event handler class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInputReceiver

Returns a new instance of InputReceiver.



123
124
125
# File 'lib/midi-jruby/api.rb', line 123

def initialize
  @buffer = []
end

Instance Attribute Details

#streamObject (readonly)

Returns the value of attribute stream.



121
122
123
# File 'lib/midi-jruby/api.rb', line 121

def stream
  @stream
end

Instance Method Details

#closeObject



150
151
# File 'lib/midi-jruby/api.rb', line 150

def close
end

#readArray<Array<Fixnum>>

Pluck messages from the buffer

Returns:

  • (Array<Array<Fixnum>>)


129
130
131
132
133
# File 'lib/midi-jruby/api.rb', line 129

def read
  messages = @buffer.dup
  @buffer.clear
  messages
end

#send(message, timestamp = -1)) ⇒ Array<Array<Fixnum>>

Add a new message to the buffer

Parameters:

  • message (Array<Fixnum>)
  • timestamp (Fixnum) (defaults to: -1))

Returns:

  • (Array<Array<Fixnum>>)


139
140
141
142
143
144
145
146
147
148
# File 'lib/midi-jruby/api.rb', line 139

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