Skip to content

Tutorial: Custom OSC

Mark Slee edited this page Feb 9, 2022 · 1 revision

The easiest way to work with OSC in LX is to hover over any control visible in the LX Studio UI and see the default OSC path that is generated for that parameter. However, in some situations you may wish to work with incoming OSC data in another format, or which does not neatly map to parameters.

In this case, you may put code in the initialize callback of your project to set up a custom OSC listener. Just specify the port and add a listener which will receive calls passing an OscMessage object whenever OSC is received on the given port.

  @Override
  public void initialize(LX lx) {
    final int customOscPort = 3535;
    try {
      lx.engine.osc.receiver(customOscPort).addListener((message) -> {
        String address = message.getAddressPattern().toString();
        if (address.equals("/my/custom/path")) {
          // process your custom messages...
        }
      });
    } catch (SocketException sx) {
      sx.printStackTrace();
    }
  }