Sunday 25 January 2009

Back to Noatikl!


Noatikl Logo


Now that the first release of Mixtikl has settled-down nicely (with an iPhone port hopefully pending, subject to feedback from Apple), we're starting to look again at Noatikl.

The first thing to sort-out is to make it easier to use templates, and we've just updated Noatikl to version 1.5.0.15 to deal with that. It is now really, really easy to merge Noatikl pieces and templates together.

The next thing we'll be looking at is some big stuff for Noatikl 2: mainly the generative pattern editor, which is a big chunk of work, and is something that is going to take a lot of focus from us over the coming months. We might also spend some time looking at easy-to-use interfaces for the Noatikl engine for mobile. Whatever we do, we're planning on having some real fun with our generative music engine!

Sunday 11 January 2009

iPhone and Bonjour file sharing

I've finally figured-out how to share files between my iPhone running Mixtikl, and other devices connected to the local network using Wi-Fi. Though it is a lot more work that it should be. :)

The way to do it was for Mixtikl to run as a HTTP server which broadcasts it's presence using Bonjour (see Apple's CocoaHTTPServer example to get you started!), and then you can browse for and grab files from it (e.g. saved .mixtikl or .partikl files) using Safari from any browser on your network! From Safari, select Bookmarks -> Show All Bookmarks, and click on the Bonjour tab. There is a Mixtikl entry from every Mixtikl iPhone on the local network; double-click on it to show the list of files on the iPhone, and select/save the files you want to your Mac!

The other way around, you're able to use Mixtikl on the iPhone to see files advertised by Mixtikl on the Mac (which also runs a HTTP server advertised using Bonjour); Mixtikl has a special view allowing you to select the server to use, look at the file list, and select the file(s) you want to copy-across to your iPhone.

Cool stuff; welcome to the Zeroconf revolution! :)

Monday 5 January 2009

Porting Mixtikl to iPhone

I spent most of Christmas finishing-off the bulk of the remaining port of Mixtikl to iPhone, with a view to possibly releasing it if we can resolve various issues related to Apple's SDK terms.

I had planned to work on the Symbian port, but delayed that after reminding myself again of the horrors of porting any code to Symbian. :) That will wait for a few more weeks...!

Anyways, it is interesting to reflect on the iPhone porting process.

All in all, I reckon it took me around 3 to 4 weeks to port Mixtikl; which was mainly about creating an iPhone abstraction layer, with Cocoa variants for some of the code.

Not too hard, but there is some crazy stuff out there:
- you have to abandon all use of fopen() etc., and use Cocoa NSFileManager instead. If you try fopen() in the emulator, it'll try to open files in the host Mac's file system; which isn't what you want. :) opendir() etc. all have to be replaced, too.
- Mixtikl is highly threaded. I simply couldn't get the NSTimer class working properly in such a threaded system, and resorted to using Thread-based timers instead (that wasted a few days, drove me potty!).
- despite what Objective-C/Cocoa heads tell you, I found autorelease pools difficult to get my head round, easy to leak by mistake, and inefficient on occasion. IMO, if you have to learn magic rules for when you can and should release objects returned to you within the system, then the system ain't as smart as it should be. No such problems in Java. No such problems in C++! You need to remember that not all of us spend all of our time writing Objective-C, and it isn't easy to dip-into without making mistakes in this area.
If you call [object release] when you shouldn't, the system fails at some unrelated time in the future; if you fail to call [object release] when you should, the system will leak and it ain't easy to track down! Horrible.
- On a related note, avoid using NSData to hold file read/write data; use the file descriptor and low-level file-descriptor function such as read()/write() instead. Why? Well, if you're reading loads of file data, the NSData objects (which are purged by an auto-release pool) aren't actually purged until some arbitrary point later over which you have no control. This can lead to your system running out of memory as lots of auto-release objects are accumulated but not yet purged (!); leading to memory allocations failing bizarrely even when you're convinced your software should still have access to lots of memory (the memory clearly isn't available until the system purges the autorelease pool.... at some point when it feels like it!). You can avoid this simply by using file descriptors instead (from [myfile fileDescriptor]). Oh, and another reason is that file descriptor based access is a whole lot faster, as there is no unnecessary buffer allocation/releasing going on.
- you'll be amazed at how horrible image drawing is, if you're using Core Graphics like we are. Having to use transformation matrices to account for the inverted Y coordinate was not fun at all, to say the least! :(

On a separate note, the state of play wrt demo code for Apple/iPhone/Microsoft etc. remains pretty poor. When I worked at Tao Group, I put lots of effort into creating many clear, fully-working and complete demo programs that illustrated many different specific specific uses of our Audio APIs, along the lines of "what code do I need to achieve this specific effect", including playing files, playing streams, adding effects plug-ins etc. I can but presume that the reason that most companies don't do this, is that those responsible for writing the APIs aren't actually genuinely passionate about helping the people who want to use their APIs. This always leads to me wasting lots of time fiddling with poorly written demos, trying to figure-out how to actually use the various APIs...