View Single Post
Old 04-17-2014, 06:17 PM   #92
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by Banned View Post
Quote:
@oscmsg
// oscparm(x,v) will get parameter value x, setting v to $'f', $'i', $'s', or 0 if invalid, etc. if $'s', you can get individual chars from the string using ((str_offs<<16) + parm_idx)
Ok, I figured some of this string stuff out... and now have a little script that can be used to monitor the OSC output from REAPER, which is quite cool for debugging:

Code:
///////////////////////////////////////////////////////////////////////////////
// ReaperOSC-Log.txt
// (by Banned)
// v0.1
// script for OSCII-bot v0.2
// For logging the output of an 'OSC Control Surface' configuration from REAPER
///////////////////////////////////////////////////////////////////////////////

// Use an OSC Control Surface configuration in REAPER which is 
// configured to *send* OSC messages to this network address/port:
@input localhost OSC "localhost:9000" // localhost = 127.0.0.1 (IPv4)

@oscmsg 
oscmatch("*") ? (
    fmt0 = oscstr;
    printf("\n[OSC output from REAPER] %s");
    
    x = 0; // reset: parameter value number
    v = 0; // reset: parameter value type
    while(
        // oscparm(x,v) will get parameter value x, setting v to $'f', $'i', $'s', or 0 if invalid, etc.
        fmt0 = oscparm(x,v);
        
        x && v ? printf(", "); // when multiple values are received, add a comma between the values
        
        v == $'f' ? printf(" [f] %f"); // $'f' = 102 (ascii) = float type parameter value
        
        v == $'i' ? printf(" [i] %d"); // $'i' = 105 (ascii) = int type parameter value
        
        // you would expect that this one-liner would work, too; but unfortunately, it does not... :(
//      v == $'s' ? printf(" [s] %s"); // $'s' = 115 (ascii) = string type parameter value
        
        // ... so we have to get the characters in the string one by one :(
        v == $'s' ? (
            printf(" [s] "); // $'s' = 115 (ascii) = string type parameter value
            
            // if $'s', you can get individual chars from the string using ((str_offs<<16) + parm_idx)
            str_offs = 0; // reset offset to start at first character in string
            oscparm_val_str = ""; // reset: create empty string to copy in characters one by one
            while(
                fmt0 = oscparm((str_offs<<16) + x, s); // get an individual character from the string
            //  fmt0 ? printf("%c"); // print string, one ascii character at a time
                fmt0 ? str_setlen(oscparm_val_str, (strlen(oscparm_val_str)+1)); // increase string length by one character
                str_setchar(oscparm_val_str, str_offs, fmt0); // copy another character into string
                str_offs += 1; // increment offset: move to next character in string
                fmt0; // return character (0 = string termination)
            );
            
            fmt0 = oscparm_val_str;
            printf("%s"); // now we finally have the entire string, print it
            
            // THIS PART DOES NOT WORK !?!
            // if the string contains an integer numeric value, print it
//          matchi("*%d*", oscparm_val_str) ? printf("\n==> parameter value is formatted as string, but contains a numeric value: %d");
        );
        
        x += 1; // next parameter value
        v; // return parameter value type (0 = invalid, last parameter value reached on previous loop cycle already)
    );
);
However, I'm still stuck at the end: I'm failing to get an int (or float) value from the string using matchi(), see line 54 (commented out). This now only gives me a single digit, the last one found in the string. I would have expected that I can get integer numbers of multiple digits into the fmt0 variable like this too, though (since that's how it seems to work with oscmatch(), which aliases to matchi(parm, oscparm). Can anyone help out and tell me what I'm missing here?

(Also, any other suggestions for improvements are very welcome!)
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ

Last edited by Banned; 04-17-2014 at 09:03 PM.
Banned is offline   Reply With Quote