heronarts/LX

How to wait until mixer setup is complete? (LXMixer & LXChannels)

worldveil opened this issue · 1 comments

I've got some logic for indexing and cataloging patterns and channels that happens when a new project file (.lxp) is loaded.

Right now, this setup sometimes explodes because the channels aren't created yet.

Other than wrapping code like this in an exponential backoff:

while ( ... ) {
  try {
      lx.engine.mixer.channels.get(EFFECTS_CHANNEL_INDEX_INT_HERE);
      // ...
  } catch (IndexOutOfBoundsException e) {
     // double the wait, and try again
  }
}

are there any good hooks for putting said initialization code into?

I think initialize(LX lx) is only run on UI start, not project load, and therefore is also before the mixer is fully loaded with channels specified in the .lxp

Yep, project load happens after all the initialization hooks and setup.

If you want to monitor project load and perform actions after, do this:

lx.addProjectListener(new LX.ProjectListener() {
  public void projectChanged(File file, Change change) {
    // File will be the project file
    // Change will be one of TRY, NEW, SAVE, or OPEN
    // You probably only care about doing something on OPEN
  }
});

Closing this for now, but let me know if you have any issues getting that working and feel free to re-open if so!