How can I get a label displaying the Sysex data I’m receiving through a midiin port ?
I’m trying to build an array of the SysexData … but sending this to a text String is not working ?
[code]char anArray[100] ;
for (int iii = 0 ; iii <= message.getSysExDataSize() ; iii++)
{
ptr++ ;
anArray[iii] = *ptr ;
String text = anArray;
label4->setText(text, false);
}
[/code]
I can’t quite see how you’re expecting the data to be formatted. Even of you wanted to make this into a (mostly garbage) string you’d need to null terminate the C string before constructing the Juce String. You also need to be careful updating GUI items from other threads (e.g., the midi thread).
[quote=“Salvator”]
String midiData;
midiData =String::toHexString(message.getRawData(),message.getRawDataSize()).removeCharacters(" ");
Looks like
f000201f0046200000040d04100503f7
but you can also keep the spacing for a view like this :
f0 00 20 1f 00 46 20 00 00 04 0d 04 10 05 03 f7
Salvator[/quote]
Thanks Salavator, this works !
Now the Sysex data is representing ascii characters, is there an ascii equivalent to “toHexString” ?
I’ve gone through the Juce String class and the things I found are :
String (const char *text, size_t maxChars)
Creates a string from a string of 8-bit ascii characters.
and
copyToUTF8 (CharPointer_UTF8::CharType *destBuffer, int maxBufferSizeBytes) const noexcept
Copies the string to a buffer as UTF-8 characters.
Thanks Atom, but how would you display Ascii characters out of sysex data ? The sysex data contains for the most part Ascii characters .
I thought the “createStringFromData” would give me those characters .
you can use %c instead of %d but be careful i did that in my program and you will get crashes if you try to show non-printable characters, i use a special function before i print any sysex data as ascii
static const char *asciiSpecials[] = {"[NUL]", "[SOH]", "[STX]", "[ETX]", "[EOT]", "[ENQ]", "[ACK]", "[BEL]", "[BS]", "[HT]", "[LF]", "[VT]", "[FF]", "[CR]", "[SO]", "[SI]", "[DLE]", "[DC1]", "[DC2]", "[DC3]", "[DC4]", "[NAK]", "[SYN]", "[ETB]", "[CAN]", "[EM]", "[SUB]", "[ESC]", "[FS]", "[GS]", "[RS]", "[US]", 0};
const String removeInvalidChars(const String &dataToValidate, const bool showSpecials, const char characterToReplace)
{
String ret;
StringArray specials(asciiSpecials);
for (int i=0; i<dataToValidate.length(); i++)
{
juce_wchar c = dataToValidate[i];
if (c < 0x20 && c != 0xd && c != 0x0b && c != 0x09 && c != 0x0a )
{
if (showSpecials)
{
ret << specials[(int)c];
}
else
{
ret << characterToReplace;
}
}
else
{
ret << c;
}
}
return (ret);
}
I’ll check that out Atom ! I just discoverd the “%.c” thing myself and this works although I still need to remove the non ascii part of the sysex , but for the moment these are not causing a crash …