Skip to content

Add a draft param-units extension - #524

Draft
linuxnow wants to merge 1 commit into
free-audio:nextfrom
linuxnow:draft-param-units
Draft

linuxnow wants to merge 1 commit into
free-audio:nextfrom
linuxnow:draft-param-units

Conversation

@linuxnow

@linuxnow linuxnow commented Nov 3, 2026 •

Copy link
Copy Markdown

Following up on #522. Thanks for the encouragement there, here's the extension as we actually use it.

Some background: I work on OpenMixer, a Linux mixing console. It hosts CLAP and LV2 plugins, but it never opens their GUIs. It draws its own knobs and meters, and it saves and recalls everything by name. That's where we kept running into the same gap.

value_to_text() is perfect when a person reads the value. It isn't enough when the host has to work with the value itself: drawing a frequency scale, building OSC addresses, a script, or a mapping saved to a file. Parsing "2.3 kHz" back into a unit is fragile, and a clap_id can change when a plugin is rebuilt, so there's nothing stable to store.

So this adds clap.param-units/1. For a parameter id, the plugin returns two things:

  • a unit, taken from LV2's unit list one to one and in the same order, plus a small block from 0x100 for four units LV2 doesn't have (dBFS, dBu, ratio, LUFS);
  • an optional symbol: [A-Za-z_][A-Za-z0-9_]*, at most 63 bytes, unique in the plugin, and kept the same across versions.

The host gets a changed() callback to read the units again.

Using LV2's list on purpose means a plugin ported from LV2, or an LV2 plugin wrapped as CLAP, keeps its units:unit and port symbol without any translation.

We already ship the same data in omx-clap-core, under our own vendor id:

I left a few things out. Our own version also carries a display scale, a step size, and a fingerprint of the parameter list. Range is already in clap_param_info, and the rest is about how our console vets plugins, so it didn't seem to belong here.

The compile tests (src/main.c, src/main.cc) pass as C11, C17 and C++11 to C++20 with -Wall -Wextra -pedantic -Werror.

A few things I'm unsure about and would love your view on:

  • Unit and symbol in one call, or two extensions? They come from the same place in LV2, so I kept them together, but the symbol isn't really about units.
  • Should get() return false when there's neither a unit nor a symbol, or always succeed with CLAP_PARAM_UNIT_NONE and an empty symbol?
  • Is it worth reserving a range for private units, or should new ones only ever be added here?
  • And the name: is param-units right when it also carries the symbol?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant