Synchronized send receive function

I need to create a generic function that is able to send a sysex message and that awaits the return of the sysex response from the equipment. Since the addlistener function is a listener, it has become somewhat complex to obtain the return and return it to a function. At least for me it got a little complex and I haven't gotten an effective result. I tried with async / await, however the listerner does not behave like a traditional function, since it depends on an interruption of the input buffer or something similar.

I think of creating a simple function that sends a request for any parameter of the device and it can respond using the return of the function itself.

for example:

I want to receive the feedback from the midi device parameter regarding the oscillator 1 waveform. The answer will be a set of sysex bytes with this information in the function's return variable.

// fictional values

var portOut = 4;

var portIn = 4;

var dataRawSysexToSend = [0xF0, 0x43, 0x7F. 0x0A, 0x01,0xF7]

var dataRawSysexReceived = sendAndGetSysex (portOut, portIn, dataRawSysextoSend); // return a array 

var oscType = dataRawSysexReceived [6];

The problem is that dataRawReceived always returns undefined even using async / await due to the fact that there is a fully asynchronous listener.

Would anyone have any suggestions for a solution to create an efficient function for this?

thank you.



Sign In or Register to comment.