in short: Is there any way to have two separate classes that reference one another in their definitions? I want objects of type A to encapsulate a collection of objects of type B, but for objects of type B to also be able to hold a reference to their containing object.
Alternatively, I could use an event system where the child objects (class B) raise an event that the containing object (class A) listens to. I'm not entirely familiar with ChucK's event model yet, though.
Here's the full story of the problem:
I'm currently working on an instrument for the Novation Launchpad using ChucK. The rest of my explanation assumes you have a basic familiarity of the layout and functionality of the Novation Launchpad.
The way it's structured, I have one class called Launchpad that is responsible for all data and functionality common to an individual device. It contains a collection of 8 LPIs (Launchpad Instruments). At any given time, one LPI on the device is in focus; interaction with the main grid and rightmost column controls that LPI. The topmost row selects between the 8 LPIs. The Launchpad object's main jobs are to allow the user to switch focus between LPIs, and to observe MidiIn messages from the physical device. So the Launchpad class handles and routes incoming data. The LPIs are the actual synthesizers; they manage (most) outgoing data. The problem I'm faced with is that the individual LPIs don't have a reference to the Launchpad itself, so I'm having trouble tracking the state of the MIDI lights in ChucK. This is needed to reduce the number of MIDI messages that I send to the device; ultimately I want to prevent any MIDI message that would tell the device to turn off a light that's already off. These messages have been creating a bottleneck, and under certain circumstances introduce unacceptable delay.
-Jordan
(this is my first Github project, so please let me know if I have it configured wrong and you can't actually checkout the project; it's intended to be public)