user3105700
user3105700

Reputation: 355

SysEx will not send byte "AD"

Ok, trying this on two different systems(Mac and PC) in two different programs(my own and QLab) written in two different languages(Java and Cocoa) yield the same results. So I'm stumped.

Essentially, I'm trying to send the following Sysex message:

F0 43 10 3E 12 01 00 33 00 00 00 00 AD 00 00 00 AD F7

And when I send it, my Midi monitoring program(two different ones, again) either says that this got sent:

F0 43 10 3E 12 01 00 33 00 00 00 00 F7

and then this got sent:

Aftertouch Ch14 C-2 0
Invalid 1 Byte
Invalid 1 Byte

or the other one just says three aftertouches and then the channel closures from Java.

So then, troubleshooting on just the Mac program, I sent the following message:

F0 43 10 3E 12 01 00 33 00 00 00 00 00 00 00 00 AD F7

and it says that I sent this:

F0 43 10 3E 12 01 00 33 00 00 00 00 00 00 00 00 F7

and then this:

Invalid 1 Byte

If it helps, I am attempting to send the message kInputFader the the Yamaha LS9.

Does Sysex not like the AD byte?

Upvotes: 2

Views: 240

Answers (2)

Christian Hujer
Christian Hujer

Reputation: 17945

MIDI is mostly 7-Bit only

Have a look at this table: http://midi.org/techspecs/midimessages.php

As it says, the SysEx message

  • starts with F0
  • may contain only bytes which are in the range [00 .. 7F]
  • except for F7 which ends the SysEx message.

MIDI is mostly a 7-Bit encoding sent in Bytes. Only a few special bytes like the start bytes of messages have the high-bit set.

When a controller supports values beyond the range of [0..127], the value needs to be split into multiple bytes.

Identifying the range

The following table helps identifying the range.

                Range                         |Data|Bytes
     unsigned     |           signed          |Bits|req'd
------------------+---------------------------+----+------
 0 ..         127 |         -64 ..         63 |  7 |  1
 0 ..       16383 |       -8192 ..       8191 | 14 |  2
 0 ..     2097151 |    -1048576 ..    1048575 | 21 |  3
 0 ..   134217728 |   -67108864 ..   67108863 | 26 |  4
 0 .. 17179869184 | -8589934592 .. 8589934591 | 34 |  5

The significance is with the value range supported by that particular controller, not the actual value. For example, if a controller supports a value range [0..1023], 2 bytes are required always, even if the value to be sent is 0 and 0 would need one byte only.

Determining the length in a Java program

If you know maxValue, you can determine the length with the following algorithm:

public static int getDataLengthUnsigned(final int maxValue) {
    int ret = 1;
    while ((1 << (ret * 7)) <= maxValue) ret++;
    return ret;
}

Converting an int into a byte[] for MIDI

This assumes that your MIDI device operates on messages in Little Endian format. In general this is the case because MIDI message Pitch Bend is LSB first. Maybe the Spec even says somewhere that stuff should be Little Endian, I don't know.

public static byte[] encodeAsSysExUnsigned(int value, final int maxValue) {
    if (value > maxValue || value < 0)
        throw new IllegalArgumentException(String.format("Value %d out of range [0 .. %d]", value, maxValue));
    final int dataLength = getDataLengthUnsigned(maxValue);
    final byte[] sysExData = new byte[dataLength];
    for (int i = 0; i < dataLength; i++, value >>>= 7)
        sysExData[i] = (byte) (value & 0x7F);
    return sysExData;
}   

Upvotes: 2

user3105700
user3105700

Reputation: 355

Ok, forgot for a minute that this was MIDI. Please correct me if I'm wrong, but other than the header, Sysex messages can only contain 00-7F(0-127 dec).

Source: http://beatwise.proboards.com/thread/1705/sysex-hardware-clips-help

Upvotes: 0

Related Questions