Wednesday, February 24, 2010

Compiling CyberLink UPNP into iPhone SDK

Recently I was asked about a post to a forum I made back in 2008 when I first started hacking around with UPNP applications on the iPhone. At the time I was working on an application to control my Sonos devices using my iPhone as remote. Although I was successful, shortly after I got my first stable prototype running the "official" version was released and was plenty good enough for what I wanted so I abandoned the project. I did not however abandon UPNP on the iPhone as it remains a large missing link in the iPhone SDK.

UPNP is used by many connected home devices to notify other like minded devices of their presence, capability and services. Responding to UDP broadcasts a device and service description is made available in XML  for digestion by client programs. Most media servers and streamers speak UPNP along with some wireless photo frames.

UPNP is missing along with all the other XML based web services provision in iPhone SDK for... er reasons best known to Apple I guess but there exists a well used and stable open source UPNP library for C, C++ and Obj-C that compiles into the iPhone SDK with a bit of hacking.

CyberLink UPNP is an open source C framework for UPNP written and maintained by Satoshi Konno. The C source files and Objective C wrappers are available from the sourceforge project which you can get to from the CyberGarage site. However all the example code and the framework project are linked against the MacOSX Cocoa framework not the iPhone Foundation framework. This means that in order to compile it for use on iPhone you need to repackage the whole thing into a Cocoa Touch static library.

It has been a while since I repackaged it for my needs so it would take me a deal of time to recreate a detailed step by step but the main tasks are:

  1. Locate and download all the source code from sourceforge.
  2. Create a new Cocoa Touch static library project.
  3. Copy all the source files into your new project.
  4. Get rid of all the #import cocoa cocoa.h lines and replace with #import foundation foundation.h (easiest to do this in the prefix headers)
  5. Change the use of imports to "CGUpnpDevice.h" for the classes used. Or create a UPnP.h combined header.
  6. Compile, track down and squash the errors, rinse repeat.
The most elegant way to then use the static library in your projects is to use a shared build folder and implement the modular shared library scheme discussed in Clint Harris' excellent tutorial. Good luck and happy hacking!

Sunday, February 14, 2010

Multi-band Dynamic Gating

I have a new compositional obsession at the moment, dynamic multi-band gating. It pretty much looks like this...

 With a rich timbre sound source input the source is split up into different frequency bands that are then gated using different patterns. Add on some FX to the chain for extra sauce and away we go. Making the patterns have different periods makes for some interesting cyclic interactions. I am working on a method to modulate the gate patterns in realtime as a way of playing live and improvising compositions.

Here is a session I did this weekend with a prototype.

Impulse (manifold) by Dionysiac

Tuesday, February 09, 2010

iPhone Dev tip - Note To Self

This is pretty much a note to self but might help some other poor shmuck out there who fails to notice, as I did, a seemingly unimportant bit of a reference page.

Here is the problem - You create and initialise a UIAlertView or UIActionSheet object and your application crashes with EXC_BAD_ACCESS. "How can this be?" you wonder, it's a brand new object, how the hell is it accessing bad memory?

Well the error is misleading, in fact you have probably not read the reference page right. If you fail to terminate the otherButtonTitles parameter with a nil like this:

UIAlertView *myAlertView = [[UIAlertView alloc] 
                           initWithTitle:@"some title" 
                                 message:@"a message"
                       otherButtonTitles:@"foo", nil]

Then you get the EXC_BAD_ACCESS error, not, as you might reasonably expect an error telling you that the parameters were wrong.

I lost a lot of hours learning that so you don't have to.

Wednesday, February 03, 2010

A Max4Live device control

A little gift from my Live 8 studio control template. Control the parameters of the currently selected device on a track in Ableton Live 8.
A Lemur module and max device. with eight knobs and labels that synchronises to the selected device without the need for MIDI mapping. It is designed to work on device racks so will have strange behaviour if pointed at a device preset that is not contained in a rack with macros.

The patch relies on the CNMAT OSC Max objects. You need to get the "Everything for Mac" or "Everything for Windows" pack from here: and install that somewhere in your Max path.
  1. Download from the JazzMutant user area.
  2. Unpack and copy the "Live Device" subfolder to your Live library (I suggest under Max Audio Effect)
  3. Add the "Live Device Control" to your master track.
  4. Fill in the IP address and port for your Lemur's OSC setup.
  5. Load the module onto your Lemur.
  6. Select a device on any track and hit the green 'sync' button on the Lemur module.
  7. Play with the knobs!
The interface will follow as you select different devices on the same track but will need synchronising again if you move to a different track (although it will continue to control the last selected device).