Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show effect parameter units in parameter name label #11041

Merged
merged 10 commits into from
Jan 9, 2023

Conversation

ronso0
Copy link
Member

@ronso0 ronso0 commented Nov 5, 2022

Follow-up for #11032

  • adopt LV2 units http://lv2plug.in/ns/extensions/units
  • get parameter units from LV2 plugins and translate them to enum EffectManifestParameter::UnitsHint
    Note: custom unit constructors are ignored.
  • blacklist known, undesired custom LV2 units, log unknown units (to either include or ignore them)
  • translate EffectManifestParameter::UnitsHint to display strings
  • show units in parameter name label
  • trim parameter value decimals to avoid unnecessary widget expansion
  • add UnitsHint to built-in effects

Nice to have:

  • scale / convert units depending on range, for example convert Hz > 10.000 to kHz?

image

@ronso0 ronso0 marked this pull request as draft November 5, 2022 14:44
@ronso0 ronso0 force-pushed the effect-parameter-units branch 3 times, most recently from 1d806e8 to 0d9a4fc Compare November 5, 2022 23:02
@ronso0
Copy link
Member Author

ronso0 commented Nov 5, 2022

(rebasing & rebasing while testing QStringLiteral vs. QLatin1String in unitsHintToString until clazy is happy (and other builders, too))))

@ronso0
Copy link
Member Author

ronso0 commented Nov 5, 2022

  • reload unit after swapping parameters

@ronso0 ronso0 force-pushed the effect-parameter-units branch 2 times, most recently from e30b12a to 99df207 Compare November 7, 2022 18:41
@ronso0
Copy link
Member Author

ronso0 commented Nov 7, 2022

Unofficial LV2 units are now logged if lv2ParamDebug is true.
Anyone following this: please test this branch and report any custom units you consier helpful.
I only came across G for all sorts of gains / levels, and st for "Frequency shift" with LSP plugins 🤷

@JoergAtGithub
Copy link
Member

JoergAtGithub commented Nov 7, 2022

I tried this, but couldn't find any parameter with unit other than Hz. I'm not sure if other units doesn't work, or if the effects have no unit specified.
I tried with built in effects and effects from https://github.com/DISTRHO/PawPaw/releases/tag/v1.1

@ronso0
Copy link
Member Author

ronso0 commented Nov 7, 2022

Yeah, built-in effects have Hz, dB and ms IIRC.
The debug output only shows non-standard LV2 units.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works already nice. I have left some comments.

There is a minor issue with the layouts.
The unit is jumping when crossing a trailing 0 that is omitted.
All knobs are jumping in case a long label is replaced by a shorter value text.

Not sure if this is worth to fix.

The filter knobs can make use of a more complex logic for showing the significant numbers and a conditional kilo k. But that is also quite advanced, just an idea.

src/effects/backends/effectmanifestparameter.h Outdated Show resolved Hide resolved
// EffectManifestParameter::unitsHintToString
unitsHint = EffectManifestParameter::lv2UnitToUnitsHint(
lilv_node_as_string(customUnit));
if (lv2ParamDebug &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one should be always enabled. If it happens on a user machine it will go to the mixxx.log and we can request this during bug hunting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, yes, but in my case with the LSP suite it prints hundreds of lines with G

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can leave it enabled until the release so we can easily look for missing units?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we know of the G case and have decided to use no unit for it. How about skip the message in this case. This also gives a chance to drop a comment about to our decision.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, for G it's a simple check. if the blacklist grows we need to rework this though.

src/widget/weffectparameternamebase.cpp Outdated Show resolved Hide resolved
src/widget/weffectparameternamebase.cpp Outdated Show resolved Hide resolved
src/widget/weffectparameternamebase.cpp Outdated Show resolved Hide resolved
@ronso0
Copy link
Member Author

ronso0 commented Nov 7, 2022

The unit is jumping when crossing a trailing 0 that is omitted.

not sure how to fix that. Using a fixed number of decimals wouldn't fix the position since the integer part of the value cn change, too, for example a Center1/2 of the param. EQ

All knobs are jumping in case a long label is replaced by a shorter value text.

Not sure if this is worth to fix.

nope, see above.
figuring out how to fix the pixel postion of either . or the unit is a PITA and not worth the effort IMO.
guessing the width from the range etc.
IMO the benefit of showing the value is to get the "final" value after stopping the adjustment for a second.

@ronso0
Copy link
Member Author

ronso0 commented Nov 8, 2022

With the current unit blacklist I get notified only about

plugin "MaBitcrush" has custom unit "bits" for parameter "resolution"
plugin "LFO" has custom unit "(coef)" for parameter "Speed"
plugin "LFO" has custom unit "(coef)" for parameter "Multiplier"
plugin "LSP Delay Compensator Mono" has custom unit "°C" for parameter "Temperature"
plugin "LSP Delay Compensator Stereo" has custom unit "°C" for parameter "Temperature"
plugin "LSP Delay Compensator x2 Stereo" has custom unit "°C" for parameter "Temperature L"
plugin "LSP Delay Compensator x2 Stereo" has custom unit "°C" for parameter "Temperature R"
plugin "LSP Slapback Delay Mono" has custom unit "°C" for parameter "Tem"
plugin "LSP Slapback Delay Stereo" has custom unit "°C" for parameter "Tem"

@ronso0
Copy link
Member Author

ronso0 commented Nov 8, 2022

A question about performance vs. easy maintenance:
are there other performant solutions to have all parameter unit enums & strings in effectmanifest.h, besides the if/else getter?
or something fast like a QHash?

@ronso0
Copy link
Member Author

ronso0 commented Nov 8, 2022

@daschuer As soon the fixup look good to you I'll squash them.

@ronso0 ronso0 linked an issue Nov 9, 2022 that may be closed by this pull request
@daschuer
Copy link
Member

A QHash would be faster.

This topic has made me rethink the whole custom units topic:
For my understanding implementing it is just a few lines away and it will release us from some maintenance. Instead of storing an enum along with the pure unit, we can use always custom units by replacing it with the printf format string, the LV2 renderer.
Using QString::asprintf()

What do you think?

@ronso0
Copy link
Member Author

ronso0 commented Nov 10, 2022

I'm not sure I understand. Where exactly you want to use the LV2 render method?
Besides, that would reintroduce mins instead of min http://lv2plug.in/ns/extensions/units#min
and that's just the 'official' units. How should we filter out undesired units?

@daschuer
Copy link
Member

In case we decide to extend this for custom units, most of the current code and replacements can remain working. I will comment the places inline.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the comments.
Just as suggestion. This PR is also good without.

}
}

static QString unitsHintToString(const UnitsHint unitsHint) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This table can be changed to return the format string (or LB2 renderer).
Like "%f ms"

if (m_unitString.isEmpty()) {
setText(QString::number(dispVal));
} else {
setText(QString::number(dispVal) + QChar(' ') + m_unitString);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setText(QString::number(dispVal) + QChar(' ') + m_unitString);
setText(QString::asprintf(m_unitString, dispVal));

src/effects/backends/lv2/lv2manifest.cpp Show resolved Hide resolved
@ronso0
Copy link
Member Author

ronso0 commented Nov 10, 2022

ok, I understand your proposal and why you think it could be an improvement.

1 get rid of the lv2UnitToUnitsHint() conversion and store the format string set by the LV2 param manifest:
I'd agree if we could rely on that, though we can't: there's the min/mins exception and handling such cases requires more complexity IIUC

Using the lilv methods to get the LV2 format strings also from UnitsHint of built-in effects would work, too, of course, but IMO that's much more code (and runtime effort?) than simply returning a pre-set string. Regarding maintenance: the units list won't change very often. Tbh I don't expect anyone to ask for adding a custom unit since no one really cared much about the LV2 UI (looking at the forums requests and filed bugs). And if someone does, it's rather easy (if we annotate the methods well).
So IMO it makes more sense to keep the current implementation but improve the performance of the lv2UnitToUnitsHint() and unitsHintToString()

2 store the param unit (format) string as soon as an effect is registered, not in the widget when it's loaded to the parameter slot (load effect, or move or show parameter)
I agree, that makes sense. Even if it only accumulates the many potential singular (potentially repetetive) UnitsHint > string conversions happening during performance in the startup procedure. So it's more efficient, but the conversion is done for all available effects than just for those being actually loaded.
Probably notable only --if at all-- with many LV2 plugins
with many LV2 plugins

Re asprintf()
so instead of trimming/rounding the display value depending on its int part we'd need to adjust %f to %.nf with n is 0, 1 or 2

@daschuer
Copy link
Member

Hey, it was just an idea for improvement. If you do not get hooked on it, we can keep the original mode of this. I don't even think that there is a performance bottle neck to solve.

Using "%.nf" will unfortunately introduce an compatibility issue with the LV2 units, because they do not have this. So It is probably better to adjust the value before formatting.

I do not see an issue with "mins" and "min", because we can use for all non custom units our internal format string.

@ronso0
Copy link
Member Author

ronso0 commented Nov 10, 2022

hehe, I did get hooked on it, but you were referring only to custom units, while I assumed you want to use the LV2 units lib for built-in effects. Anyway...

Using "%.nf" will unfortunately introduce an compatibility issue with the LV2 units, because they do not have this. So It is probably better to adjust the value before formatting.

Yes, that's what I meant: adjust %f to %.0f, %.1f or %.2f as required by the value (and don't adjust the value). Because just %f will not work with adjusted values, for example double 6000.0 would be 6000.0000..(and probably a 1 somewhere down the line) , compared to 6000 Hz with QString::Number

requires checking for 'lv2' package if LILV cmake option is enabled
@ronso0 ronso0 force-pushed the effect-parameter-units branch 2 times, most recently from 5280012 to dbcffab Compare November 17, 2022 21:07
@ronso0 ronso0 marked this pull request as ready for review November 22, 2022 20:42
@ronso0 ronso0 added this to the 2.4.0 milestone Dec 4, 2022
Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and works good. Thank you.

@daschuer daschuer merged commit a7f2901 into mixxxdj:main Jan 9, 2023
@ronso0
Copy link
Member Author

ronso0 commented Jan 9, 2023

🎉 thanks for your review and ideas!

@ronso0 ronso0 deleted the effect-parameter-units branch January 9, 2023 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show units of effect parameter knobs
3 participants