Program in a Program?

There isn’t a one-size-fits-all approach because the logic of many sketches does not logically coexist – for example, sketches that are using a video camera feed, or setting up peasycam, or catching MIDI events, etc. For some things, you could extend this through routing – for example, have the master sketch set up MIDI and multiple sub-sketches listen for MIDI events, or have the master sketch grab the latest data from serial and then have multiple sub-sketches react. For other things, it is trickier – like instantiating a different cam object for each peasycam. (Almost) all these things can be worked around, but they are several different work-arounds. Some libraries are strongly designed around a single-sketch paradigm. You also can’t have multiple top-level interaction functions like keyPressed() – they need to be merged, and then the order in which different client sketches intercept events could matter. A meta-input handler can register and unregister event listeners in some order, but that isn’t the simple, out-of-the-box Processing setup.

That said, many people are unaware that you can layer sketch-like objects as PGraphics into a single layout, and that they don’t have to all be the same renderer – so long as the top-level canvas is P2D or P3D, you can mix as many JAVA2D, P2D, or P3D layers in under it and treat each one like a separate sketch at the level of rendering – although not at the level of code. If you want a quick way to assemble visual sketches like legos, start by pointing each at a dedicated PGraphics with drawing the PGraphics as the last step.

If you are trying to create a dynamic gallery of sketches there are several ways to tackle that outside Processing – depending on if you want it to be run-time dynamic or compiled. You can have sketches launch other sketches. You can also format stand-alone sketches ahead of time so that a script can mash them up into one multi-object.

However, this all requires advanced planning. If you want simultaneous sketches embedded in a surface that are largely stand-alone, I would suggest using p5.js in a web browser with iframes or namespacing.


Also: If you want a framework that lets you use Processing sketches like patches or plugins then I recommend checking out the latest release of PraxisLive.

See also using Syphon to pipe Processing into VDMX: https://vdmx.vidvox.net/tutorials/vdmx-processing-syphon-osc-intro

4 Likes