Checking Input buffer
HI,
In Sysex communication some devices often respond using several sysex blocks. Example when responding to a Dump Request. In this case, it is necessary to get the contents until the end of all blocks and for this it is necessary to make sure that all blocks have been received. I thought about checking if the buffer input is empty or not. Is there a way to check this? or some other way of ensuring that all blocks referring to the same data request have been received?
For now I am using a procedure of giving a window of time when the first message is received by the listener. I give approximately 300ms which is enough time to receive the dump, but I believe that with a buffer checker we can have a more efficient routine, because shorter messages would not have to wait that long. I understand that the listener is completely asynchronous, however in the case of sysex there is this situation that the blocks need to be collected synchronously and have a definite ending.
best regards
Comments
In order to know when a dump is done, you would have to know the format used by the manufacturer and/or device before the dump starts. If the device breaks the dump into several sysex MIDI messages, it's up to the developer to know what that particular device is sending and how it's sending it (you may want to check that device's documentation).
The only scenario in which we can know in advance some information about the structure of sysex messages is when Universal System Exclusive Messages are used. Unfortunately, as of now, this is not something that has been added to WebMidi.js. I will add it to my to do list but it will be considered low priority for now.
Hello Côté
Thanks for the answer.
As for knowing the structure of the message in advance, this would indeed be the standard.
However, I am developing an application with several generic functions to work with different models of midi equipment and even different manufacturers with as little advance information as possible about the equipment.
For this reason, I intend to create functions that automatically adapt to any equipment. This is the goal. For this reason I am checking several strategies to obtain the best possible result.
Your information helped me to define another logical model so that I can continue developing within this concept. An application to exchange MIDI information with a specific device would be really simple, but that is not the case.
Thanks for your help.
If you ever think of a way WebMidi.js could be improved, I'd love to hear it. However, as far as I know, there's not much I can do to help you if you want to work with all these different devices without knowing in advance how they operate.
It's all right.
My expectation of the webmidi would not be to work this way,
I understand that this is a challenge for the application that I am assembling.
My question was only if there would be any parameters in the webmidi that could inform if the input buffer is empty or not. If it existed I could go the way using this feature.
You are doing great with the webmidi project. I will definitely continue using it and sure I will be pleased to suggest improvements
You've already helped me a lot.
Thank you very much.
There is no buffer per se, at least it's not visible directly in the browser. The MIDI messages data get delivered to WebMidi.js through the Web MIDI API. Beyond that, the system is handling the communication and we do not have access to that in the browser. Basically, the Web MIDI API delivers messages and WebMidi.js triggers an event that can be listened to.