Modular Compositions

Markus Kroll's picture

Hello!

I am quite new to Quartz Composer although I already gained some experience with. Now I would like to get some feedback on the following problem:

I want to create a composition, which can "dynamically" load other compositions at render-time:

A kind of framework composition reads a XML-file and decides upon that, which other compositions to load - it also has to pass parameters to these compositions (such as list of assets, effect-properties ...) - these parameters are taken from the XML as well.

These (to be loaded) compositions are basically either simple "effects" (such as a reflection) to be applied to an image or text for instance or more complex ones (lets call them "objects") such as an image-slider/moving text etc. So basically "effects" don't have a real storyboard and "objects" are graphical representations of assets (images/text/...) with a storyboard underneath.

My idea is to keep the "framework composition" as simple as possible (it just includes the xml-parser, state-machine ...) and to realize effects/objects are individual compositions. That modular approach would keep the complexitiy manageable and would also make debugging easier.

So is that something which can be done? And if so, what would be the best way to do it?

Thanks already! Markus

usefuldesign.au's picture
Re: Modular Compositions

I've done the XML parsing side of just that scenario and it works fine. I'm not loading different QC files as determined by XML data.

Obviously auto-configuration for the inputs (not to mention noodling them) is not possible in an automated set-up. Just have a composition loader for each consumer and switch them on and off as appropriate.

cradle's picture
Re: Modular Compositions

I haven't done what you're attempting, but I'm going to be trying to do it in the not too distant future.

Here's some pointers that I'll probably follow through.

The 'qtz' files are themselves XML files (technically plist), albeit compressed into binary format, there is an option in the advanced settings of the editor (option+menu item) that allows you to enable editing (opening/saving) of (non binary) xml compositions.

There are tools available for converting to and from plist to binary plist and back again. But that's if you even care for them to be binary at all (they are smaller, but not much smaller if you transfer the text files compressed anyhow).

If you weren't concerned with doing the whole thing 'in memory' you could very easily download files using QC into the directory you are working in (or other known directory) and load them from there, as you would know the path and could just use composition importer.

The advantage of using the XML approach is that you could directly manipulate the compositions, if you wanted to .

Another trick I've been using is loading javascript direct from URL's over the intertubes, and then having them "eval" at runtime, giving me almost complete control over the entire app. Using this method, you could even not have to know ahead of time the format of your XML you want to download, and have it download the latest version of your Javascript to interpret the XML.

Anyway, that's my awesome idea. You can't copyright ideas though. So I may as well give it away and see if anyone else can use it to good effect :)

I plan on monetising eventually... that's what the all say right? ;)

My fall back, in fact, is to create a new plugin (in objective C) that would allow for exactly the type of framework you are describing to exist 'plug and play'. But I won't go into the details of that... cos it makes me too excited, and talking too much about your goals ends up in none of them ever being acheived.

Good luck anyway :D

Markus Kroll's picture
Re: Modular Compositions

As far as the XML parsing is concerned, that seems to be pretty straight forward - at least what I can tell from my testing.

So if I understand you correctly, you are saying, that I should have a composition loader specifically for each of the effect/object-compositions (to be loaded) within my "XML-parser composition" - right?

So whenever I add a new "module", I just have to add another composition loader to the logic of that XML parser for that "module".

As effects work basically on images, the to be loaded effect must take (input) and output an image plus a structure, which will parameterize the effect. If I realize via "published output", can I include the same effect multiple times without having conflicts?

Objects are similiar, they just take a structure (assets, parameter...) and they will also output an image, that can be placed by the XML-parser-comp. to a sprite or billboard...

Does that makes sense at all? Or did I understand something completely wrong :-) ?

Thanks a lot!

usefuldesign.au's picture
Re: Modular Compositions

Nothing wrong, that sounds fine. If your compositions conform to a QC template (eg. Image Filter or Graphic Transition) you can have a changing path to the .qtz file (ie a modular file system that can load comps at will).

You can also declare your own Input and Output keys inn the settings panel for each loader and as long as they match to published ports on the loaded compositions it should work. So yes a fully modular system is possible. Just make your own protocol for inputs and outputs and conform to it.

Make a chain of loaders with multiplexers and directory scanners to generate the file paths (URLs) and inputs from the XML structure.

Also read the patch description for better explanation.

gtoledo3's picture
Re: Modular Compositions

(If you manipulate a QC file's XML in realtime, it won't "change" until it is saved and reloaded, so it doesn't present a practical solution to changing parameters via something that is loaded with an importer, but it does allow some kind of extra function I guess.)

I guess at this point it's worth noting that a composition importer will import a qtz file if it's a qtz file, regardless of extension name, because it can be somewhat handy in making resources non-obvious, or for doing serial authorization.

It might also be fruitful to look at 10.5 developer example apps. Parameter View and ImageFX might be useful for showing how to setup an app so that you're presented with different published parameters depending on the composition you load.