Leopard’s Quartz Composer and Network events

Carefully crafted in 25 Nov 2007

Back in the Tiger days, Quartz Composer had few support for network sources. The RSS feed patch was pretty much the only way we had to read data from the net, but it was way too limited (no streaming, not event based, not extendable, no input or output triggers).

I needed a way to get data from the Network in the form of events that I could reuse in a quartz composition. So our resident mac programmer coded this custom made patch based on sparse non official documentation found on the internet. And it worked great. We have about 5 plasma screens with mac minis over at work running it for months, no problems whatsoever.

Now Leopard comes along and QC had a major upgrade and I’m drooling, but ironically 1. Apple publishes an API to develop custom patches (which is good news) but 2. Our patch for Tiger doesn’t work anymore and needs a rewrite.

Then I found 2 patches in the new “Network” category: Network Broadcaster and Network Receiver. They are meant to connect several qtz compositions across the network and exchange messages between them. But maybe I can use them for something else…

I wrote a quartz composition to broadcast messages using UDP and multicast and started debugging and I discovered that the packets are really simple non-crippled text messages, four bytes per character iso-latin encoded chunks. So if you want to broadcast the message “Apple”, you’ll send this over UDP “\0\0\0A\0\0\0p\0\0\0p\0\0\0l\0\0\0e”

So I wrote a small php script (download) to broadcast messages:

#!/usr/bin/php -q
$socket = stream_socket_client('udp://');
for($i=0;$i<strlen($argv[1]);$i++) $b.="\0\0\0".$argv[1][$i];

And a sample composition to test the concept. Download here and run it on Quartz Composer. After which just type:

$ ./broadcast.php "message number 1"
$ ./broadcast.php "message number 2"

And happily see them scroll up your screen.

This is just a proof of concept. I rewrote all my most complex compositions to use the Network Receiver patch and they all work fine. Using UDP over TCP is also an advantage because you don’t have to worry about the producer as the connection is stateless, and using a multicast group is great for broadcast scenarios (ie: multiple compositions on multiple computers consuming the same data).

Now imagine the possibilities and have loads of fun.


comments powered by Disqus