Apologies for spam; we've changed our policy by requiring approval for accounts, and deleted all existing spam and user - thanks for your help flagging content. We continue to test our forums and Vanilla software, aiming for release early in 2013. If you need to give us feedback outside the forum, contact us via http://createdigitalmusic.com/contact/ or on Facebook
Use writesf~ to app's Documents folder?
  • Hi, I just started learning PD a few days ago, and I'm loving it so far, I've been obsessed, going at it basically all the time for the better part of the past 5 days. :)
    I've been reading Peter Brinkman's book, and I have my first synth patch working as a Universal app on iOS with a basic interface: a 2 octave keyboard, sliders for LPF, a gain/overdrive of sorts, and buttons for tuning the 4 oscillators in my patch to different octaves. I sort of stopped reading for a bit, jumped in and just started patching and building the interface, so I still need to go back and finish the book and read more PD tutorials.

    Anyhow I can't seem to get writesf~ to work on the actual iOS devices. The patch is recording/playing back correctly in PD Vanilla on my Mac, and the same patch even writes/records correctly on the iOS Simulator, just not the devices.

    My short term goal is to be able to simply record an audio file into my app's Documents folder, as I assume this will allow sharing the files with Mac/PC via iTunes sharing.

    Is it possible to get writesf~ and readsf~ to record/read from the Documents folder of my app ON the device?
  • @Shmim Thanks! That got me on the right path, I figured it out after adjusting that code a bit so it works with writesf~ and readsf~  I'll share once I've played around with it a bit and make sure it's fairly solid.
  • Just remembered to follow up and share what I got working here, hope this helps a fellow newbie. This code works solid for me to record to the app's documents folder, which can then be shared through iTunes file sharing. *You need to enable file sharing in iTunes in your app's info.plist file in order to retrieve the recorded files when your device is connected to iTunes.


    -(void)recordToFile:(int)n { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [paths objectAtIndex:0]; NSString *samplePath = [path stringByAppendingPathComponent:@"sample.aiff"]; NSArray *readWriteArgs = [NSArray arrayWithObjects:samplePath,nil]; //write to aiff in documents folder [PdBase sendMessage:@"open" withArguments:readWriteArgs toReceiver:@"setuprecord"]; [PdBase sendBangToReceiver:@"startrec"]; }


    then use an IBAction:

    -(IBAction)startRecording:(id)sender { NSLog(@"Recording To File"); [self recordToFile:1]; }


    This part of the code sends the "open" message to a receiver named "setuprecording" which feeds to a writesf~ object in the pd patch. [PdBase sendMessage:@"open" withArguments:readWriteArgs toReceiver:@"setuprecording"];

    This part of the code to a receiver named "startrecording" which bangs a start message to the writesf~ object to start the recording. [PdBase sendBangToReceiver:@"startrec"];


    This code is used to playback the file you recorded within your app.

    -(void)playbackFile:(int)n { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [paths objectAtIndex:0]; NSString *samplePath = [path stringByAppendingPathComponent:@"sample.aiff"]; NSArray *readWriteArgs = [NSArray arrayWithObjects:samplePath,nil]; //playback aiff from documents folder [PdBase sendMessage:@"open" withArguments:readWriteArgs toReceiver:@"setupplayback"]; [PdBase sendBangToReceiver:@"startplayback"];


    To understand what's going there:

    This part of the code sends the "open" message to a receiver named "setupplayback" which feeds to a readsf~ object in the pd patch. [PdBase sendMessage:@"open" withArguments:readWriteArgs toReceiver:@"setupplayback"];

    This part of the code to a receiver named "startplayback" which bangs a start message to the readsf~ object to start the recording. [PdBase sendBangToReceiver:@"startplayback"];


    I'll post a simple example patch soon.

  • Here's the example pd patch to go with the comment above.


    N canvas 89 29 868 623 10;

    X obj 250 262 writesf~ 2;

    X msg 336 206 start;

    X msg 337 229 stop;

    X obj 401 205 r stoprecording;

    X obj 336 141 r setuprecording;

    X obj 336 164 r startrecording;

    X obj 87 528 dac~;

    X obj 79 199 osc~;

    X obj 79 175 mtof~;

    X obj 141 171 tgl 32 0 empty empty mute/unmute 0 -8 0 10 -4034 -1

    -1 1 1;

    X obj 169 77 hsl 128 15 0 127 0 1 empty empty noteslider -2 -8 0 10

    -262144 -1 -1 1600 1;

    X msg 230 393 start;

    X msg 230 419 stop;

    X obj 165 441 readsf~ 2;

    X obj 230 351 r triggerstartplay;

    X obj 283 395 r triggerstopplay;

    X obj 231 328 r setupplayback;

    X obj 79 223 *~;

    X connect 1 0 0 0;

    X connect 2 0 0 0;

    X connect 3 0 2 0;

    X connect 4 0 0 0;

    X connect 5 0 1 0;

    X connect 7 0 17 0;

    X connect 8 0 7 0;

    X connect 9 0 17 1;

    X connect 10 0 8 0;

    X connect 11 0 13 0;

    X connect 12 0 13 0;

    X connect 13 0 6 0;

    X connect 13 0 6 1;

    X connect 14 0 11 0;

    X connect 15 0 12 0;

    X connect 16 0 13 0;

    X connect 17 0 0 0;

    X connect 17 0 6 0;

    X connect 17 0 6 1;