how to use variables in a message that contains a file path
I'm trying to write a patch that uses sfplay and sfrecord to record and playback files.
When sending messages to these objects that contain filenames I'm running into a confusing issue.
If I create a message that looks like:
open $1.aiff
And then send that message a number with a number box, it will print out as expected, such as:
open 0.aiff
open 1.aiff
...
But if I change the message to have a path, such as:
open /Users/somebody/$1.aiff
Then the printed out message doesn't use arg, and I get:
open /Users/somebody/$1.aiff
open /Users/somebody/$1.aiff
...
What am I doing wrong? I tried inserting backslashes to escape the slashes but that didn't change anything. Can't find what else.
I find the somewhat obscure "sprintf" object to be helpful for this sort of thing.
I like the way the action (open) the path, the file number (or name), and the extension are all separate. This example is set to generate the command each time the number is changed.
you could either put your files in the root directory of the patch so you don't need a path, or redo your patch with umenus with auto populate. Send the umenu a "prefix" message with the path to where your files are stored. Then select the file to play by calling up the index number of the file in the umenu.
I ALWAYS forget about "sprintf". I have had to re-discover it like 5 times! Lance's code is probably better for plugging in to what you already have.
I have used both sprintf and umenu together. umenu to hold a list of distinct names, e.g., "foo" and "bar", and sprintf to prepend and append with something like "myPic_" and ".png", so the results would be "myPic_foo.png" and "myPic_bar.png".