Skip to content

Tutorial: Global Parameters

Mark Slee edited this page Feb 9, 2022 · 2 revisions

The best place to add parameters to your project are as parameters on the custom patterns and effects that you write. However, in some cases it is desirable to have a separate container for project state that is not particular to a given animation component. In this case, you can register your own global component with the LX engine and add custom UI to control it. By registering your component with the engine, its parameter values will be saved and loaded with the project file, and it may be mapped for OSC/MIDI control just like anything else in the LX hierarchy.

Defining a Component Class

Define a class which extends from LXComponent and register its parameters. You may optionally add the LXOscComponent interface if you want your component to be able to receive OSC control via the normal LX engine.

public class MyComponent extends LXComponent implements LXOscComponent {

  public final BoundedParameter param1 =
    new BoundedParameter("p1", 0)
    .setDescription("A global parameter that does something");

  public final BoundedParameter param2 =
    new BoundedParameter("p2", 0)
    .setDescription("A global parameter that does something else");

  public MyComponent(LX lx) {
    super(lx);
    addParameter("param1", this.param1);     addParameter("param2", this.param2);
  }
}

Initialize the Component

  public MyComponent myComponent;

  @Override
  public void initialize(LX lx) {
    // Create an instance of your global component and register it with the LX engine
    // so that it can be saved and loaded in project files
    this.myComponent = new MyComponent(lx);
    lx.engine.registerComponent("myComponent", this.myComponent);
  }

Define a UI class

public class UIMyComponent extends UICollapsibleSection {
  public UIMyComponent(LXStudio.UI ui, MyComponent myComponent) {
    super(ui, 0, 0, ui.leftPane.global.getContentWidth(), 80);
    setTitle("MY COMPONENT");

    new UIKnob(0, 0, myComponent.param1).addToContainer(this);
    new UIKnob(40, 0, myComponent.param2).addToContainer(this);
  }
}

Instantiate the UI class

  public void onUIReady(LXStudio lx, LXStudio.UI ui) {
    // Instantiate the UI object and add it to the global section
    new UIMyComponent(ui, this.myComponent).addToContainer(ui.leftPane.global);
  }