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.



136
137
138
# File 'lib/midi-jruby/api.rb', line 136

def initialize
  @buffer = []
end

Instance Attribute Details

#streamObject (readonly)

Returns the value of attribute stream.



134
135
136
# File 'lib/midi-jruby/api.rb', line 134

def stream
  @stream
end

Instance Method Details

#closeObject



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

def close; end

#readArray<Array<Fixnum>>

Pluck messages from the buffer

Returns:

  • (Array<Array<Fixnum>>)


142
143
144
145
146
# File 'lib/midi-jruby/api.rb', line 142

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 (javax.sound.midi.MidiMessage)
  • timestamp (Fixnum)

Returns:

  • (Array<Array<Fixnum>>)


152
153
154
155
156
157
158
159
160
161
# File 'lib/midi-jruby/api.rb', line 152

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