Ok, I think I finally got it, much thanks to
ijijn's hint here.
Here's what I did (the commented out part between /* and */ now does what I wanted to achieve):
Code:
///////////////////////////////////////////////////////////////////////////////
// OSC-input-logger.txt
// (by Banned)
// v0.2
// script for OSCII-bot v0.2
///////////////////////////////////////////////////////////////////////////////
// For logging the output of an 'OSC Control Surface' configuration from REAPER,
// make sure that it sends OSC messages to the network address/port defined here:
@input localhost OSC "localhost:9000" // localhost = 127.0.0.1 (IPv4)
@oscmsg
oscmatch("*") ? (
fmt0 = oscstr;
printf("\n[OSC input] %s"); // print OSC message address (without parameters; see below)
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
strcpy(oscparm_val_str, ""); // reset: create empty string to copy in characters one by one
//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, str_offs+1); // increase string length by one character, padding with space
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;
strlen(oscparm_val_str) ? printf(" %s"); // now we finally have the entire string, print it (if its length is not 0)
/*
// THIS PART DOES NOT QUITE WORK AS EXPECTED...
// if the string contains a numeric value, print it (NB: this misses numbers preceded by '.' in the string; e.g. track name is "Instr. 15")
// THIS GIVES THE USER STRING SLOT NUMBER :(
// matchi("*+f*", oscparm_val_str) ? printf("\n==> parameter value is formatted as string, but contains a numeric value: %f\n");
// THIS MISSES THE SIGN FOR NEGATIVE VALUES :( -- but it's good enough for unsigned values
// matchi("*?%f*?", oscparm_val_str) ? printf("\n==> parameter value is formatted as string, but contains a numeric value: %f\n");
matchi("*?-*?%f*?", oscparm_val_str) ? ( // first, try to match for a negative value (i.e. directly preceded with '-' character)
fmt0 *= -1; // apply negative sign
printf("\n==> parameter value is formatted as string, but contains a numeric value: %f");
) : ( // else, just try to match a value
matchi("*?%f*?", oscparm_val_str) ? printf("\n==> parameter value is formatted as string, but contains a numeric value: %f\n");
);
*/ );
x += 1; // next parameter value
v; // return parameter value type (0 = invalid, last parameter value reached on previous loop cycle already)
);
);