Module: MIDIJRuby::API
Overview
Access to javax.sound.midi
Defined Under Namespace
Classes: InputReceiver
Instance Method Summary collapse
-
#close_input(device) ⇒ Boolean
Close the given input device.
-
#close_output(device) ⇒ Boolean
Close the given output device.
-
#enable_input(device) ⇒ Boolean
Enable the given input device to receive MIDI messages.
-
#enable_output(device) ⇒ Boolean
Enable the given output to emit MIDI messages.
-
#get_devices ⇒ Array<Hash>
Get all MIDI devices that are available via javax.sound.midi.
-
#get_inputs ⇒ Array<Input>
Get all MIDI inputs that are available via javax.sound.midi.
-
#get_outputs ⇒ Array<Output>
Get all MIDI outputs that are available via javax.sound.midi.
-
#read_input(device) ⇒ Array<Array<Fixnum>>
Read any new MIDI messages from the given input device.
-
#write_output(device, data) ⇒ Boolean
Write the given MIDI message to the given output device.
Instance Method Details
#close_input(device) ⇒ Boolean
Close the given input device
79 80 81 82 83 84 85 |
# File 'lib/midi-jruby/api.rb', line 79 def close_input(device) # http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4914667 # @transmitter[device].close # device.close @transmitter.delete(device) true end |
#close_output(device) ⇒ Boolean
Close the given output device
69 70 71 72 73 74 |
# File 'lib/midi-jruby/api.rb', line 69 def close_output(device) @receiver[device].close @receiver.delete(device) device.close true end |
#enable_input(device) ⇒ Boolean
Enable the given input device to receive MIDI messages
48 49 50 51 52 53 54 |
# File 'lib/midi-jruby/api.rb', line 48 def enable_input(device) device.open @transmitter ||= {} @transmitter[device] = device.get_transmitter @transmitter[device].set_receiver(InputReceiver.new) true end |
#enable_output(device) ⇒ Boolean
Enable the given output to emit MIDI messages
59 60 61 62 63 64 |
# File 'lib/midi-jruby/api.rb', line 59 def enable_output(device) @receiver ||= {} @receiver[device] = device.get_receiver device.open true end |
#get_devices ⇒ Array<Hash>
Get all MIDI devices that are available via javax.sound.midi
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/midi-jruby/api.rb', line 18 def get_devices MidiSystem.get_midi_device_info.map do |info| jdevice = MidiSystem.get_midi_device(info) { :device => jdevice, :id => get_uuid, :name => info.get_name, :description => info.get_description, :vendor => info.get_vendor } end end |
#get_inputs ⇒ Array<Input>
Get all MIDI inputs that are available via javax.sound.midi
33 34 35 36 |
# File 'lib/midi-jruby/api.rb', line 33 def get_inputs jinputs = get_devices.select { |device| !device[:device].get_max_transmitters.zero? } jinputs.map { |jinput| Input.new(jinput[:id], jinput[:device], jinput) } end |
#get_outputs ⇒ Array<Output>
Get all MIDI outputs that are available via javax.sound.midi
40 41 42 43 |
# File 'lib/midi-jruby/api.rb', line 40 def get_outputs joutputs = get_devices.select { |device| !device[:device].get_max_receivers.zero? } joutputs.map { |joutput| Output.new(joutput[:id], joutput[:device], joutput) } end |
#read_input(device) ⇒ Array<Array<Fixnum>>
Read any new MIDI messages from the given input device
90 91 92 |
# File 'lib/midi-jruby/api.rb', line 90 def read_input(device) @transmitter[device].get_receiver.read end |
#write_output(device, data) ⇒ Boolean
Write the given MIDI message to the given output device
98 99 100 101 102 103 104 105 |
# File 'lib/midi-jruby/api.rb', line 98 def write_output(device, data) bytes = Java::byte[data.size].new data.each_with_index { |byte, i| bytes.ubyte_set(i, byte) } = data.first.eql?(0xF0) ? SysexMessage.new : ShortMessage.new .(bytes, data.length.to_java(:int)) @receiver[device].send(, 0) true end |