Subversion Repositories svn.mios32

Rev

Rev 2053 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2053 Rev 2251
Line 1... Line 1...
1
/* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
1
/* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
2
// $Id: OscHelper.cpp 2053 2014-09-12 20:44:16Z tk $
2
// $Id: OscHelper.cpp 2251 2015-12-22 23:32:13Z tk $
3
/*
3
/*
4
 * OSC Help Routines
4
 * OSC Help Routines
5
 * (taken from MIOS32_OSC)
5
 * (taken from MIOS32_OSC)
6
 * Documentation: see there
6
 * Documentation: see there
7
 *
7
 *
Line 240... Line 240...
240
    unsigned char *buffer = new unsigned char(str.length() + 4);
240
    unsigned char *buffer = new unsigned char(str.length() + 4);
241
    unsigned char *endPtr = buffer;
241
    unsigned char *endPtr = buffer;
242
#if JUCE_MAJOR_VERSION == 1 && JUCE_MINOR_VERSION < 51
242
#if JUCE_MAJOR_VERSION == 1 && JUCE_MINOR_VERSION < 51
243
    endPtr = putString(buffer, (const char *)str);
243
    endPtr = putString(buffer, (const char *)str);
244
#else
244
#else
245
    endPtr = putString(buffer, str.toUTF8().getAddress());
245
    endPtr = putString(buffer, (const char *)str.toUTF8());
246
#endif
246
#endif
247
    Array<uint8> tmp = Array<uint8>(buffer, endPtr-buffer);
247
    Array<uint8> tmp = Array<uint8>(buffer, endPtr-buffer);
248
    delete buffer;
248
    delete buffer;
249
    return tmp;
249
    return tmp;
250
}
250
}
Line 278... Line 278...
278
// \return buffer pointer behind the inserted entry
278
// \return buffer pointer behind the inserted entry
279
/////////////////////////////////////////////////////////////////////////////
279
/////////////////////////////////////////////////////////////////////////////
280
unsigned char *OscHelper::putBlob(unsigned char *buffer, unsigned char *data, unsigned len)
280
unsigned char *OscHelper::putBlob(unsigned char *buffer, unsigned char *data, unsigned len)
281
{
281
{
282
  // ensure that length considers word alignment
282
  // ensure that length considers word alignment
283
  unsigned aligned_len = (len+3) & 0xfffffffc;
283
  unsigned aligned_len = (len+3) & ~3;
284
284
285
  // add length
285
  // add length
286
  buffer = putWord(buffer, aligned_len);
286
  buffer = putWord(buffer, aligned_len);
287
287
288
  // add bytes
288
  // add bytes
Line 555... Line 555...
555
    if( *path != '/' )
555
    if( *path != '/' )
556
        return -2; // invalid element format
556
        return -2; // invalid element format
557
557
558
    // tags are starting at word aligned offset
558
    // tags are starting at word aligned offset
559
    // add +1 to pathLen, since \0 terminator is counted as well
559
    // add +1 to pathLen, since \0 terminator is counted as well
560
    size_t tagsPos = (pathLen+1 + 3) & 0xfffffc;
560
    size_t tagsPos = (pathLen+1 + 3) & ~3;
561
561
562
    // check that tags are at valid position
562
    // check that tags are at valid position
563
    if( tagsPos >= len )
563
    if( tagsPos >= len )
564
        return -2; // invalid element format
564
        return -2; // invalid element format
565
565
Line 582... Line 582...
582
    if( numArgs > MIOS32_OSC_MAX_ARGS )
582
    if( numArgs > MIOS32_OSC_MAX_ARGS )
583
        numArgs = MIOS32_OSC_MAX_ARGS;
583
        numArgs = MIOS32_OSC_MAX_ARGS;
584
584
585
    // arguments are starting at word aligned offset
585
    // arguments are starting at word aligned offset
586
    // add +1 to tagsLen, since \0 terminator is counted as well
586
    // add +1 to tagsLen, since \0 terminator is counted as well
587
    size_t argPos = (tagsPos + tagsLen+1 + 3) & 0xfffffc;
587
    size_t argPos = (tagsPos + tagsLen+1 + 3) & ~3;
588
588
589
    // parse arguments
589
    // parse arguments
590
    oscArgs->numArgs = 0;
590
    oscArgs->numArgs = 0;
591
    unsigned arg;
591
    unsigned arg;
592
    for(arg=0; arg<numArgs; ++arg) {
592
    for(arg=0; arg<numArgs; ++arg) {
Line 618... Line 618...
618
            // check for valid string
618
            // check for valid string
619
            if( strLen == 0 || str[strLen] != 0 )
619
            if( strLen == 0 || str[strLen] != 0 )
620
                return -2; // invalid element format
620
                return -2; // invalid element format
621
            // next argument at word aligned offset
621
            // next argument at word aligned offset
622
            // add +1 to strLen, since \0 terminator is counted as well
622
            // add +1 to strLen, since \0 terminator is counted as well
623
            argPos = (argPos + strLen+1 + 3) & 0xfffffc;
623
            argPos = (argPos + strLen+1 + 3) & ~3;
624
        } break;
624
        } break;
625
625
626
        case 'b': { // OSC-blob
626
        case 'b': { // OSC-blob
627
            knownArg = 1;
627
            knownArg = 1;
628
            unsigned blobLen = getBlobLength((unsigned char *)(buffer + argPos));
628
            unsigned blobLen = getBlobLength((unsigned char *)(buffer + argPos));
629
            // next argument at word aligned offset
629
            // next argument at word aligned offset
630
            argPos = (argPos + 4 + blobLen + 3) & 0xfffffc;
630
            argPos = (argPos + 4 + blobLen + 3) & ~3;
631
        } break;
631
        } break;
632
632
633
        case 'h': // long64
633
        case 'h': // long64
634
        case 't': // OSC timetag
634
        case 't': // OSC timetag
635
        case 'd': // float64 (double)
635
        case 'd': // float64 (double)
Line 922... Line 922...
922
                unsigned seconds;
922
                unsigned seconds;
923
                unsigned fraction;
923
                unsigned fraction;
924
#if JUCE_MAJOR_VERSION == 1 && JUCE_MINOR_VERSION < 51
924
#if JUCE_MAJOR_VERSION == 1 && JUCE_MINOR_VERSION < 51
925
                if( sscanf((const char*)word, "@%u.%u", &seconds, &fraction) != 2 ) {
925
                if( sscanf((const char*)word, "@%u.%u", &seconds, &fraction) != 2 ) {
926
#else
926
#else
927
                if( sscanf((const char*)word.toUTF8().getAddress(), "@%u.%u", &seconds, &fraction) != 2 ) {
927
                if( sscanf((const char*)word.toUTF8(), "@%u.%u", &seconds, &fraction) != 2 ) {
928
#endif
928
#endif
929
                    statusMessage = String("syntax: <seconds>.<fraction>");
929
                    statusMessage = String("syntax: <seconds>.<fraction>");
930
                    return Array<uint8>();
930
                    return Array<uint8>();
931
                } else {
931
                } else {
932
                    timetag.seconds = seconds;
932
                    timetag.seconds = seconds;
Line 982... Line 982...
982
            int len;
982
            int len;
983
            unsigned value;
983
            unsigned value;
984
#if JUCE_MAJOR_VERSION == 1 && JUCE_MINOR_VERSION < 51
984
#if JUCE_MAJOR_VERSION == 1 && JUCE_MINOR_VERSION < 51
985
            if( sscanf((const char*)word.substring(1), "%d:%x", &len, &value) != 2 ) {
985
            if( sscanf((const char*)word.substring(1), "%d:%x", &len, &value) != 2 ) {
986
#else
986
#else
987
            if( sscanf((const char*)word.substring(1).toUTF8().getAddress(), "%d:%x", &len, &value) != 2 ) {
987
            if( sscanf((const char*)word.substring(1).toUTF8(), "%d:%x", &len, &value) != 2 ) {
988
#endif
988
#endif
989
                statusMessage = String("please enter blob length and hex value (syntax: <len>:<data>)");
989
                statusMessage = String("please enter blob length and hex value (syntax: <len>:<data>)");
990
                return Array<uint8>();
990
                return Array<uint8>();
991
            } else if( len != 4 ) {
991
            } else if( len != 4 ) {
992
                statusMessage = String(":-/ only 4 byte blobs supported yet! :-/");
992
                statusMessage = String(":-/ only 4 byte blobs supported yet! :-/");
Line 1017... Line 1017...
1017
                unsigned seconds;
1017
                unsigned seconds;
1018
                unsigned fraction;
1018
                unsigned fraction;
1019
#if JUCE_MAJOR_VERSION == 1 && JUCE_MINOR_VERSION < 51
1019
#if JUCE_MAJOR_VERSION == 1 && JUCE_MINOR_VERSION < 51
1020
                if( sscanf((const char*)word.substring(1), "%u.%u", &seconds, &fraction) != 2 ) {
1020
                if( sscanf((const char*)word.substring(1), "%u.%u", &seconds, &fraction) != 2 ) {
1021
#else
1021
#else
1022
                if( sscanf((const char*)word.substring(1).toUTF8().getAddress(), "%u.%u", &seconds, &fraction) != 2 ) {
1022
                if( sscanf((const char*)word.substring(1).toUTF8(), "%u.%u", &seconds, &fraction) != 2 ) {
1023
#endif
1023
#endif
1024
                    statusMessage = String("syntax: <seconds>.<fraction>");
1024
                    statusMessage = String("syntax: <seconds>.<fraction>");
1025
                    return Array<uint8>();
1025
                    return Array<uint8>();
1026
                } else {
1026
                } else {
1027
                    oscArgsString += arg;
1027
                    oscArgsString += arg;
Line 1063... Line 1063...
1063
            } else {
1063
            } else {
1064
                unsigned value;
1064
                unsigned value;
1065
#if JUCE_MAJOR_VERSION == 1 && JUCE_MINOR_VERSION < 51
1065
#if JUCE_MAJOR_VERSION == 1 && JUCE_MINOR_VERSION < 51
1066
                if( sscanf((const char*)word.substring(1), "%x", &value) != 1 ) {
1066
                if( sscanf((const char*)word.substring(1), "%x", &value) != 1 ) {
1067
#else
1067
#else
1068
                if( sscanf((const char*)word.substring(1).toUTF8().getAddress(), "%x", &value) != 1 ) {
1068
                if( sscanf((const char*)word.substring(1).toUTF8(), "%x", &value) != 1 ) {
1069
#endif
1069
#endif
1070
                    statusMessage = String("ERROR: expecting hex value for '") + arg + String("' argument!");
1070
                    statusMessage = String("ERROR: expecting hex value for '") + arg + String("' argument!");
1071
                    return Array<uint8>();
1071
                    return Array<uint8>();
1072
                } else {
1072
                } else {
1073
                    oscArgsString += arg;
1073
                    oscArgsString += arg;