25 November 2007 ~ 11 Comments

Leopard’s Quartz Composer and Network events

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

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.

  • http://www.videonorma.tv ullrich

    This works pretty nice!

  • http://kaemu.com ben kaemu

    That’s really cool

  • Anonymous

    “four bytes per character iso-latin encoded chunk”

    If you need to send characters not in latin-1 you can just encode the string to utf-32be (big endian) and write the encoded bytes to the socket.

    I haven’t tried this extensively but it worked for the €uro sign.

  • http://www.gomaya.com/glyph NYDave

    Many thanks for this – I’ll be looking at it to support multiple Mac minis on a network of information screens. Plus just playing with it. Great work!

  • http://wouwlabs.com/blogs/jeraman jeraman

    valeu pelo post, cara! ajudou bastante!

  • Zno

    cant change the address or ports in the receiver plugin.
    can't feed dynamic data to the php script on another address and port

  • http://pulse.yahoo.com/_GNN3AXO3ZLAHHOCPCLTWMRADB4

    You want to own the healthy shoes as MBT Shoes? choose you love in mbtstore.org.MBT Shoes clearance make you more beautiful and health.our mbtstore.org provide all kinds of mbt shoes,such as MBT Sandals,MBT Habari,MBT Fora
    .Life is movement,because movement is good for health,how to exercise.MBT can effectively exercise the small muscles around the joints,increase muscle strength.
    Also,The Moncler come in different designs and features.The Moncler Jackets come with hoods as well which reflect a casual wear line. In addition, the simple line of the Moncler down jackets is also available that is suitable for a casual day.Moncler 2010 hot in sale,enter http://www.monclersale.us now.

  • Pingback: Retrocast | Celso Martinho

  • http://www.best-hostings.in/ Best hosting

    I will appreciate for creating this interesting blog, because its having the useful information, so most of them get benefits from your blog.

  • http://donatstudios.com Jesse Donat

    Is there any way to transmit unicode?

    I have tried UTF-32 which *looked* like it worked, as well as UTF-8 breaking the string apart by rune and left padding each character with so they were all 4 in length, neither has given me good results. I’m curious if you know a solution.

  • Rob

    brilliant – such an old post but still useful. i was trying to send UDP messages from Perl, Node.js, etc and needed this info. it sucks that QC just ignores messages that come in without the null-padding that you figured out. thanks!