I'm trying to communicate with an usb midi controller using the midi classes from javax.sound package. I successfully got input from device, but i can't work out how to communicate with device.
The device is livid OhmRGB.
According to wiki i should send some SysEx messages to get response with parameters. I didn't work with java libraries before, so maybe i use it in the wrong way. You'll see the method below to request some data from device, but device doesn't respond on any system messages.
Pseudo-code(jython):
class Communicator:
def __init__(self):
self.outputs = []
self.inputs = []
self.input = None
self.output = None
def getMidiDevices(self):
devices = MidiSystem.getMidiDeviceInfo()
for dev in devices:
midi = MidiSystem.getMidiDevice(dev)
# get outputs
if midi.getMaxReceivers() != 0: #(-1 or positive)
self.outputs.append(dev)
if midi.getMaxTransmitters() != 0:
self.inputs.append(dev)
def openOutput(self, dev): #!right device resolved somewhere
self.output = MidiSystem.getMidiDevice( dev )
self.output.open()
def openInput(self, dev):
self.input = MidiSystem.getMidiDevice( dev )
inReceiver = SomeReciever()
self.input.getTransmitter().setReceiver(inReceiver)
self.input.open() #input open and receiver print messages from dev.
def requestDevice(self):
device = self.resolveOutput()
self.openOutput(device)
data = [240, 0, 1, 97, 0, 7, 8, 247]
_bytes = bytearray(b"")
for i in data: _bytes.append(i)
# create message from array
message = SysexMessage(str(_bytes), len(_bytes)) # it works correctly
self.output.getReceiver().send(message,-1L)
self.output.close()
communacate = Communicator()
communacate.openInput()
time.sleep(2)
communicate.requestDevice()
When I open the input, the receiver class handle incoming midi messages. When i request device i do not see any response from device (i expect it on input receiver). I requested all available output ports and even sent messages on input receiver for any case. I also reproduced it in java and got the same result. I think i use the wrong way to get response from device.
Huge thanks,
Anton