Hi, I was reading this post... How to write a java program that writes a MIDI file
This Java code generate the contents of the File.
[positionFile]:Hex Byte(signed value Byte): Representation, ....
Below the content
[00]:4D( 77):M, [01]:54( 84):T, [02]:68( 104):h, [03]:64( 100):d, [04]:00( 0): , [05]:00( 0): , [06]:00( 0): , [07]:06( 6): ,
[08]:00( 0): , [09]:01( 1): , [10]:00( 0): , [11]:01( 1): , [12]:00( 0): , [13]:18( 24): , [14]:4D( 77):M, [15]:54( 84):T,
[16]:72( 114):r, [17]:6B( 107):k, [18]:00( 0): , [19]:00( 0): , [20]:00( 0): , [21]:37( 55):7,
[22]:00( 0): , [23]:F0( -16):ð, [24]:05( 5): , [25]:7E( 126):~, [26]:7F( 127):, [27]:09( 9): , [28]:01( 1): , [29]:F7( -9):÷,
[30]:00( 0): , [31]:FF( -1):ÿ, [32]:51( 81):Q, [33]:03( 3): , [34]:02( 2): , [35]:00( 0): , [36]:00( 0): ,
[37]:00( 0): , [38]:FF( -1):ÿ, [39]:03( 3): ,
[40]:0E( 14): , [41]:6D( 109):m, [42]:69( 105):i, [43]:64( 100):d, [44]:69( 105):i, [45]:66( 102):f, [46]:69( 105):i, [47]:6C( 108):l,
[48]:65( 101):e, [49]:20( 32): , [50]:74( 116):t, [51]:72( 114):r, [52]:61( 97):a, [53]:63( 99):c, [54]:6B( 107):k, [55]:00( 0): ,
[56]:B0( -80):°, [57]:7D( 125):}, [58]:00( 0): , [59]:00( 0): , [60]:7F( 127):, [61]:00( 0): , [62]:00( 0): , [63]:C0( -64):À,
[64]:00( 0): , [65]:01( 1): , [66]:90(-112): , [67]:3C( 60):<, [68]:60( 96):`, [69]:78( 120):x, [70]:80(-128):, [71]:3C( 60):<,
[72]:40( 64):@, [73]:13( 19): , [74]:FF( -1):ÿ, [75]:2F( 47):/, [76]:00( 0):
If you can see ...
[22]:00( 0): , [23]:F0( -16):ð, [24]:05( 5): , [25]:7E( 126):~, [26]:7F( 127):, [27]:09( 9): , [28]:01( 1): , [29]:F7( -9):÷,
like result of Java code:
[code type=markup]
byte[] b = {(byte) 0xF0, 0x7E, 0x7F, 0x09, 0x01, (byte) 0xF7};
SysexMessage sm = new SysexMessage();
sm.setMessage(b, 6);
MidiEvent me = new MidiEvent(sm, (long) 0);
t.add(me);
[/code]
The question is:
How determine the length of SysexMessage/SysexEventType, in order to parse correctly the File and obtain te next event?...
Hello,
As you're talking about parsing the data while reading the file, I assume you're talking about the overall SYSEX message. These can be any length, with various formats, depending on function, manufacturer, etc. The only way you can determine the length will be to count the bytes from the opening F0 to the closing F7.
However, some messages, for example those that contain explicit data for the receiving device, may include a length item, but there isn't any reliable way of determining that this is the case.
I think you must assume that each SYSEX message could be any length, and just count your way through it byte by byte.
Geoff
If you can see ...
[22]:00( 0): , [23]:F0( -16):ð, [24]:05( 5): , [25]:7E( 126):~, [26]:7F( 127):, [27]:09( 9): , [28]:01( 1): , [29]:F7( -9):÷,
How determine the length of SysexMessage/SysexEventType, in order to parse correctly the File and obtain te next event?...
Byte [24] is the length of the SysEx message in the file. However, it is not always a single byte, it is known as a "variable-length quantity."
See page 2 of the "Standard MIDI Files 1.0" official spec. It discusses how variable-length quantities work. Page 11 provides sample code in C that can easily be adapted for Java.