Skip to content
R. Kevin Nelson edited this page Jan 19, 2017 · 10 revisions

Pd for iOS

Xcode project setup

These steps will show you how to set up a new Xcode project with libpd.

In order to set up Pd for iOS, open a shell, go to the directory where you want to put your iOS Xcode projects, and perform the following steps:

git clone --recursive git://github.com/libpd/pd-for-ios.git

Xcode 4:

  • drag the libpd.xcodeproj file from the Finder into your project (drop it in the Project Navigator pane on the left)
  • go to project settings by clicking on your project's blue icon, then select the main target of your app under "Targets"
  • under "Build Phases", then "Target Dependencies", click the plus icon and add libpd
  • under "Build Phases", then "Link Binary With Libraries", click the
  • plus icon to choose the frameworks/libraries we need to add. Add libpd-ios.a, AVFoundation.framework, and AudioToolbox.framework.
  • under "Build Settings", find the entry "User Header Search Paths". Add a recursive entry for your base libpd directory (most likely pd-for-ios/libpd).

That's it. You should then be able to #import "PdAudioController.h" and instantiate it as an object within your App Delegate or anywhere else in your project.

libpd sample projects for iOS

Several sample projects are provided in the folder pd-for-ios. These demonstrate basic functions of using libpd on iOS. You can run the projects and study the code in order to get an idea how to build iOS apps with libpd.

Using compiled C-language Externals on iOS

Because iOS does not support dynamic libraries it is necessary to compile and statically link any C-language Pd externals in with your iOS app. It is also necessary to explicitly initialize any such external before it can be used from a Pd patch. This registers the external objects as available to Libpd.

For example, to use the C-language external lrshift~ with an iOS app. Add lrshift~.c to your project (it is located in the extra folder along with the Libpd source). Then call the lrshift_tilde_setup() function after initializing Libpd.

extern void lrshift_tilde_setup(void);

- (BOOL)application:(UIApplication *)application 
	didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
	pdAudioController = [[PdAudioController alloc] init];
	[pdAudioController configurePlaybackWithSampleRate:44100
		 numberChannels:2 inputEnabled:YES mixingEnabled:NO];
	lrshift_tilde_setup();
	...
}

More information about adding externals to your libpd project are available on the libpd wiki.

Maintaining a folder hierarchy for pd abstractions

Sometimes it is favorable to keep abstractions within a folder heirarchy, like [experimental/coolsynth]. In order for this the patches must live in a folder relative to your main pd patches on the device, which means within the app resources bundle. To do this, you must make sure the option "Create folder references for any added folders" is checked when copying the files into your xcode project - I do it by dragging the entire folder in (note it is blue, not yellow like the rest).

This is exemplified in the WaveTables sample: Note the folder layout for pd patches in Resources directory: helper patches for both synths are placed in the Resources/util folder in order to demonstrate how to maintain a folder heirarchy within your pd patches (as you may very well be doing for standard pd).