I'm attempting to get JS to talk to my Kaossilator Pro+ and it's sort of working but the data dump contains some unexpected extra zero bytes and I don't understand why.
My question is
does midirecv_buf() add any padding? It looks like my device sends out seven bytes and an empty eighth byte is added to the end before the next lot of seven bytes is recorded. This is a single sysex message, not split over multiple messages.
The extra bytes mess up the indexing so where dump[32] should contain the MIDI channel, it's actually in dump[36] and where there should be four consecutive note assignments for pads, there's an unlisted zero after the first two. I've confirmed that dump[0] contains the first byte of the data so I know my indexing is correct.
I can't see any mention of this padding in the (frankly overly cryptic) MIDI implementation chart for the device but it's kind of hard to follow so maybe I've just failed to understand it properly.
This is the code I'm using (stripped of gfx to examine the data and slabs of text copied from the MIDI data sheet), in case someone clever can see an obvious mistake:
Code:
desc: Sysex Lab
slider1:send=0<0,1,{---,SEND}>Send message
slider2:clear=0<0,1,{---,CLEAR}>Clear buffers
@init
ext_noinit = 1;
sbuf = 0;
rbuf = 1024;
dump = 2048;
@slider
clear ?
(
memset(sbuf,0,1024);
memset(rbuf,0,1024);
memset(dump,0,1024);
recieved = 0;
clear = 0;
);
@block
// Helper to get the length of the sysex messages we send out
function GetSyxLength(buf)
local(c)
(
// Scan through buf until we hit the sysex stop byte 0x7F
c = 0;
while(buf[0] != $xF7)
(
c += 1;
buf += 1;
);
c += 1; // Count the stop byte
);
send ?
(
channel = 8;
func = $x0E; // Global Data Dump Request
mem_set_values(sbuf,$xF0,$x42,$x30|channel,$x00,$x01,$x1B,func,$xF7);
len = GetSyxLength(sbuf);
midisend_buf(0, sbuf, len);
recieved = 0;
send = 0;
);
while((rcount = midirecv_buf(offset, rbuf, 1024)))
(
(rbuf[0] == $xF0) && !recieved ?
(
recieved = rcount;
memcpy(dump,rbuf+8,rcount); // copy data minus header to dump location
);
);
recieved ?
(
// These are the byte numbers specified by the MIDI implementation
// chart but the data doesn't line up.
kop.channel = dump[32] & 0x0F;
kop.loopA = dump[33];
kop.loopB = dump[34];
kop.loopC = dump[35];
kop.loopD = dump[36];
kop.ccX = dump[37];
kop.ccY = dump[38];
kop.ccTouch = dump[39];
);