New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do SysEx events actually work? #95
Comments
|
Ok, after analyzing the output of a generated mid file with sysex data in it, I finally found out how this works. So, for example, if the complete original message is this: I hope this helps anybody struggling with the same problem. UPDATE: For example, with a data length of 390 bytes, the length byte should be 391, counting the terminal 0xF7, and is represented as The first value is obtained by shifting the length by seven bits to the right, then adding the leading 1 (bitwise OR for 128): 391 is "110000111", shifting its bits to the right 7 times makes it "11" (3); since 3 is less than 127 we don't need to make further conversions; the "|" operator OR adds "10000000" (128), which makes it "10000011" (131). If the result of the shifting were greater than 127 (for example, for an original value greater than 16383) we'd need to take the result of the shifting and do the same operation again. The "&" operator returns only the bits that are equal to "1" in both values, since 391 is "110000111" and 127 is "11111111" (or "001111111"), only the last three bytes are considered ("111" is 7): This simple function converts any 32bit positive integer to 7 bit sysex values, even when greater than 16383: The reverse (obtaining the integer values from a full sysex data list) can be something like this: I hope this helps... |
|
so, in other words, you just had to write your data to an array and everything else just worked? 👍 |
|
Well, that seemed to work, until I run into a strange bug yesterday. For this track, kMidimon says: "Unexpected byte (16) at 38 at offset 39Unexpected byte ( 0) at 40 at offset 41Unexpected byte ( 0) at 43 at offset 44". |
I'm trying to understand how to write actual SysEx events, but, so far, I wasn't able to.
I tried appending midi.SysexEvent(data=[list of values]) but it doesn't seem to create a valid MIDI file (at least, not for aplaymidi).
I also tried adding/stripping the leading 240 and trailing 247 SysEx values in different combinations, still with no result.
I was thinking about using struct, but, according to the code, that's not the case.
The text was updated successfully, but these errors were encountered: