Module: MIDIJRuby::API
Overview
Access to javax.sound.midi
Defined Under Namespace
Classes: InputReceiver
Constant Summary collapse
- SYSEX_STATUS_BYTES =
[0xF0, 0xF7].freeze
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
83 84 85 86 87 88 89 |
# File 'lib/midi-jruby/api.rb', line 83 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
71 72 73 74 75 76 77 78 |
# File 'lib/midi-jruby/api.rb', line 71 def close_output(device) unless @receiver[device].nil? @receiver[device].close @receiver.delete(device) end device.close true end |
#enable_input(device) ⇒ Boolean
Enable the given input device to receive MIDI messages
50 51 52 53 54 55 56 |
# File 'lib/midi-jruby/api.rb', line 50 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
61 62 63 64 65 66 |
# File 'lib/midi-jruby/api.rb', line 61 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
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/midi-jruby/api.rb', line 20 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
35 36 37 38 |
# File 'lib/midi-jruby/api.rb', line 35 def get_inputs jinputs = get_devices.reject { |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
42 43 44 45 |
# File 'lib/midi-jruby/api.rb', line 42 def get_outputs joutputs = get_devices.reject { |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
94 95 96 |
# File 'lib/midi-jruby/api.rb', line 94 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
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/midi-jruby/api.rb', line 102 def write_output(device, data) bytes = Java::byte[data.size].new data.each_with_index { |byte, i| bytes.ubyte_set(i, byte) } if SYSEX_STATUS_BYTES.include?(data.first) = SysexMessage.new .(bytes, data.length.to_java(:int)) else = ShortMessage.new begin .(*bytes) rescue # support older java versions .(bytes) end end @receiver[device].send(, device.get_microsecond_position) true end |