Multiple simultaneous visualizations
Now that we have a collection of visualizations, we can enhance the app to run more than one at a time and switch between them.
To support multiple concurrent visualizations, replace the activeViz
variable in VisualizerBox
with a list of visualizations
:
public List<Visualization> visualizations = new ArrayList<Visualization|();
Then, cycle through the list in each of the VisualizerBox
method that use it. We always want to set up all of them, but then only draw (preDraw
, postDraw
) the active ones:
public void setup() { audioTexture = genTexture(); fftTexture = genTexture(); for (Visualization viz : visualizations) { viz.setup(); } } public void preDraw() { for (Visualization viz : visualizations) { viz.preDraw(); } } public void postDraw() { for (Visualization viz : visualizations) { viz.postDraw(); } }
We can control the scene...