Old 04-16-2018, 12:02 PM   #1
Human being with feelings
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,346
Default JSFX: midirecv_buf()

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:
desc: Sysex Lab

slider1:send=0<0,1,{---,SEND}>Send message
slider2:clear=0<0,1,{---,CLEAR}>Clear buffers

ext_noinit = 1;
sbuf = 0;
rbuf = 1024;
dump = 2048;

clear ?
  recieved = 0;
  clear = 0;

// Helper to get the length of the sysex messages we send out
function GetSyxLength(buf)
  // 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
  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];
IXix is offline   Reply With Quote
Old 04-23-2018, 03:24 AM   #2
Human being with feelings
Join Date: Apr 2018
Location: UK
Posts: 2

Hi,the Kaossilator is a Korg device, right? If it's anything like my other Korgs (X5D, Triton) then the device itself adds the extra bytes in order to convert between internal format (where data values could exceed the 7-bit max of 7F) and 7-bit MIDI data.

Here's the conversion method, taken from the Triton MIDI implementation docs:
|  Internal 7byte data <--convert--> MIDI 8 byte data                                    |
|  example) Internal data(bit image) MIDI data(bit image)                                |
|                Aaaaaaaa            0GFEDCBA                                            |
|                Bbbbbbbb            0aaaaaaa                                            |
|                Cccccccc            0bbbbbbb                                            |
|                Dddddddd            0ccccccc                                            |
|                Eeeeeeee            0ddddddd                                            |
|                Ffffffff            0eeeeeee                                            |
|                Gggggggg            0fffffff                                            |
|                Hhhhhhhh            0ggggggg                                            |
|                Iiiiiiii            0NMLKJIH                                            |
|                   :                0hhhhhhh                                            |
|                   :                   :                                                |
|                Vvvvvvvv            000000WV                                            |
|                Wwwwwwww            0vvvvvvv                                            |
|                                    0wwwwwww                                            |
|                                    11110111 (EOX=7FH)                                  |
So each 7 byte block of internal format data becomes 8 bytes of MIDI data, with the first byte of each block holding the most significant bit of the following 7 bytes.

It'll look like padding with zeros if the internal data doesn't typically go above 7F but, from the description you give, I'd bet it's actually doing this ^^^.

Note that it's just the data portion of the dump that gets this treatment, starting after the sysex header bytes.

Hope this helps,
Digiel is offline   Reply With Quote
Old 04-23-2018, 04:48 AM   #3
Human being with feelings
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,346

Thanks, that is helpful and it confirms what I learned from another conversation on the same topic. I haven't tried any further sysex mangling as I got busy with other things but I'm better equipped to tackle it when I get the time.
IXix is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 03:38 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.