Add peak indicators to the mixer strips. They show the maximum peak value
that was observed and can be reset by clicking on them.
## Implementation details
The implementation works via a signal/slot mechanism. The `Fader` class
has a new signal `peakChanged` which reports peak values as
amplifications. A new class `PeakIndicator` is added which has a slot
`updatePeak` which is connected to the new signal in `Fader`.
The `PeakIndicator` inherits from `QLabel` and mainly deals with updating
the label text from the current peak value.
Add a `PeakIndicator` instance to `MixerChannelView`. Add a `reset`
method to `MixerChannelView` so that the mixer channel can be reset on
the loading of new projects, etc. The current implementation resets the
peak indicator back to -inf dbFS. The `reset` method is called in
`MixerView::clear`.
Remove the clamping in `Fader::setPeak` so that all peaks are reported.
Emit the new signal if the peak changes.
* Render fader levels in code with a gradient
Render the fader level in code using a gradient instead of using pixmaps. The problem with the pixmaps is that they don't "know" how a fader instance is configured with regards to the minimum and maximum value. This means that the display can give quite a wrong impression.
The rendering of levels has been unified in the method `paintLevels`. It can render using dbFS and linear scale. The method `paintLinearLevels` has been removed completely, i.e. there's no more code that renders using pixmaps.
Much of the previous code relied on the size of the background image `fader_background.png`, e.g. the initialization of the size. For now the `Fader` widget is initially resized to the size of that background image as it is present in the default and classic theme (see `Fader::init`). All rendering uses the size of the widget itself to determine where to draw what. This means that the widget is prepared to be resizable.
The method `paintLevels` first renders the background of the level indicators and uses these as clipping paths for all other rendering operations, e.g. for the rendering of the levels themselves. Levels are rendered using a gradient which is defined with the following stops:
* Two stops for the ok levels.
* One stop for warning levels.
* One stop for clipping levels.
Peak indicators do not use the three distinct colors anymore but instead use the color of the gradient at that position of the peak. This makes everything look "smooth".
The code now also renders a marker at unity position, i.e. at position 1.0 in linear levels and 0 dbFS in dbFS scale.
The painting code makes lots of use of the class `PaintHelper`. This class is configured with a minimum and maximum value and can then return linear factors for given values. There are two supported modes:
* Map min to 0 and max to 1
* Map min to 1 and max to 0
It can also compute rectangles that correspond to a given value. These methods can be given rectangles that are supposed to represent the span from min to max. The returned result is then a rectangle that fills the lower part of the source rectangle according to the given value with regards to min and max (`getMeterRect`). Another method returns a rectangle of height 1 which lies inside the given source rectangle at the corresponding level (`getPersistentPeakRect`).
The method `paintLevels` uses a mapping function to map the amplitude values (current peak value, persistent peak, etc.) to the display values. There's one mapper that keeps the original value and it is used to display everything in a linear scale. Another mapper maps everything to dbFS and uses these values as display everything in a dbFS scale. The following values must be mapped for the left and right channel to make this work:
* Min and max display values (min and max peak values)
* The current peak value
* The persistent peak value
* The value for unity, i.e. 1.0 in linear levels and 0 dbFS in dbFS scale.
Remove the method `calculateDisplayPeak` which was used in the old method to render linear levels.
`Fader::setPeak` now uses `std::clamp` instead of doing "manual" comparisons.
The LMMS plugins Compressor, EQ and Delay are still configured to use linear displays. It should be considered to switch them to dbFS/logarithmic displays as well and to remove the code that renders linearly.
* Remove unused pixmaps from `Fader`
Remove the now unused pixmaps for the background and the LEDs from the `Fader` class and remove the files from the default and classic theme directories.
* Rename peak properties and use them to render levels
Rename the peak properties as follows:
* peakGreen -> peakOk
* peakRed -> peakClip
* peakYellow -> peakWarn
The reasoning is that a style might for example use a different color than green to indicate levels that are ok.
Use the properties to initialize the gradient that is used to render the levels.
Initialize the properties to the colors of the current default theme so that it's not mandatory to set them in a style sheet. Up until now they have all been initialized as black.
* Always render the knob in the middle of the fader
Render the knob in the middle of the fader regardless of the width. The previous implementation was dependent on the fader pixmap having a matching width because it always rendered at x=0.
* Set size policy of fader to minimum expanding
Set the size policy of the fader to minimum expanding in both directions. This will make the fader grow in layouts if there is space.
* Default dbFS levels and better peak values
Default to dbFS levels for all faders and set some better minimum and maximum peak values.
* Fix faders of Crossover EQ
Fix the faders of the Crossover EQ which were initialized and rendered much too wide and with a line at unity. The large width also resulted in the knobs being rendered outside of view.
Resize the fader to the minimum size so that it is constructed at a sane default.
Introduce a property that allows to control if the unity line is rendered. The property is available in style sheets and defaults to the unity lines being rendered. Adjust the paint code to evaluate the property.
Initialize the faders of the Crossover EQ such that the unity line is not drawn.
* Remove EqFader constructor with pixmaps
Remove the constructor of `EqFader` that takes the pixmaps to the fader background, leds and knob. The background and leds pixmaps are not used by the base class `Fader` for rendering anymore to make the `Fader` resizable. A pixmap is still used to render the knob but the constructor that takes the knob as an argument does not do anything meaningful with it, i.e. all faders are rendered with the default knob anyway.
Remove the resources for the fader background, leds and knob as they are not used and the knob was the same image as the default knob anyway.
Remove the static pixmaps from the constructor of `EqControlsDialog`. Switch the instantiations of the EQ's faders to use the remaining constructor of `EqFader`. This constructor sets a different fixed size of (23, 116) compared to the removed constructor which set a size of (23, 80). Therefore all faders that used the removed constructor are now set explicitly to a fixed size of (23, 80).
The constructor that's now used also calls a different base constructor than the removed one. The difference between the two base constructors of `Fader` is that one of them sets the member `m_conversionFactor` to 100.0 whereas the other one keeps the default of 1.0. The adjusted faders in `EqControlsDialog` are thus now constructed with the conversion factor set to 100. However, all of them already call `setDisplayConversion` with `false` after construction which results in the conversion factor being reset to 1.0. So the result should be the same as before the changes.
* Remove background and LEDs pixmap from Fader constructor
Remove the parameters for the background and LEDs pixmap from the second `Fader` constructor. Make the knob pixmap parameter in the constructor a const reference. Assign the reference to the knob pixmap of the `Fader` itself. This enables clients to use their own fader knobs as is the case with the Crossover EQ. The EQ now renders using it's own knobs again.
Make the second constructor delegate to the first one. This will additionally set the conversion factor to 100 but this is not a problem with the current code because the only user of the second constructor, the Crossover EQ, already calls `setDisplayConversion` with the parameter set to `false`, hence reinstating a conversion factor of 1.
Remove the resources for the background and LEDs from the Crossover EQ as they are not used anymore. Remove the three QPixmap members from `CrossoverEQControlDialog` as they are not needed. The background and LEDs are not used anyway and the knob is passed in as a constant reference which is copied. Hence we can use a local variable in the constructor of `CrossoverEQControlDialog`.
* Remove the init method from Fader
Remove the `init` method from `Fader` as it is not needed anymore due to the constructor delegation. Tidy up the parameter lists and use of spaces in the constructor.
* Introduce range with solid warn color
Introduce a second point in the gradient for the warn colors so that we get a certain range with the full/solid warn color.
The colors are distributed as follows now. The solid ok range goes from -inf dbFS to -12 dbFS. The warn range goes from -6 dbFS to 0 dbFS. In between the colors are interpolated. Values above 0 dbFS interpolate from the warn color to the clip color.
This is now quite similar to the previous implementation.
# Analysis of the previous pixmap implementation
The pixmap implementation used pixmaps with a height of 116 pixels to map 51 dbFS (-42 dbFS to 9 dbFS) across the whole height. The pixels of the LED pixmap were distributed as follows along the Y-axis:
* Margin: 4
* Red: 18
* Yellow: 14
* Green: 76
* Margin: 4
Due to the margins the actual red, yellow and green areas only represent a range of (1 - (4+4) / 116) * 51 ~ 47,48 dbFS. This range is distributed as follows across the colors:
Red: 7.91 dbFS
Yellow: 6.16 dbFS
Green: 33.41 dbFS
The borders between the colors are located along the following dbFS values:
* Red/yellow: 9 - (4 + 18) / 116 * 51 dbFS ~ -0.67 dbFS
* Yellow/green: 9 - (4 + 18 + 14) / 116 * 51 dbFS ~ -6.83 dbFS
* The green marker is rendered for values above -40.24 dbFS.
* Remove unused method Fader::clips
* Fader: Correctly render arbitrary ranges
Adjust the `Fader` so that it can correctly render arbitrary ranges of min and max peak values, e.g. that it would render a display range of [-12 dbFS, -42 dbFS] correctly.
Until now the gradient was defined to start at the top of the levels rectangle and end at the bottom. As a result the top was always rendered in the "clip" color and the bottom in the "ok" color. However, this is wrong, e.g. if we configure the `Fader` with a max value of -12 dbFS and a min value of -42 dbFS. In that case the whole range of the fader should be rendered with the "ok" color.
The fix is to compute the correct window coordinates of the start and end point of gradient using from the "window" of values that the `Fader` displays and then to map the in-between colors accordingly. See the added comments in the code for more details.
Add the templated helper class `LinearMap` to `lmms_math.h`. The class defines a linear function/map which is initialized using two points. With the `map` function it is then possible to evaluate arbitrary X-coordinates.
* Remove unused methods in PaintHelper
Remove the now unused mapping methods from `PaintHelper`. Their functionality has been replaced with the usage of `LinearMap` in the code.
* Fix some builds
Include `cassert` for some builds that otherwise fail.
* Opaque unity marker with styling option
Make the unity marker opaque by default and enable to style it with the style sheets. None of the two style sheets uses this option though.
* Darker default color for the unity line
* Move code
Move the computation of most mapped values at the top right after the definition of the mapper so that it is readily available in all phases of the painting code.
* Render unity lines in background
Render the unity lines before rendering the levels so that they get overdrawn and do not stick out when they are crossed.
* Don't draw transparent white lines anymore
Don't draw the transparent white lines anymore as they were mostly clipped anyway and only create "smudge".
* Full on clip color at unity
Adjust the gradient so that the full on clip color shows starting at unity. There is only a very short transition from the end of warning to clipping making it look like a solid color "standing" on top of a gradient.
* Fix discrepancy between levels and unity markers
This commit removes the helper class `PaintHelper` and now uses two lambdas to compute the rectangles for the peak indicators and levels. It uses the linear map which maps the peak values (in dbFS or linear) to window coordinates of the widget.
The change fixes a discrepancy in the following implementation for which the full on clip rectangle rendered slightly below the unity marker.
* Fix fader display for Equalizer shelves and peaks
The peak values for the shelves and peaks of the Equalizer plugin are computed in `EqEffect::peakBand`. The previous implementation evaluated the bins of the corresponding frequency spectrum and determined the "loudest" one. The value of this bin was then converted to dbFS and mapped to the interval [0, inf[ where all values less or equal to -60 dbFS were mapped to 0 and a value of 40 dbFS was mapped to 1. So effectively everything was mapped somewhere into [0, 1] yet in a quite "distorted" way because a signal of 40 dbFS resulted in being displayed as unity in the fader.
This commit directly returns the value of the maximum bin, i.e. it does not map first to dbFS and then linearize the result anymore. This should work because the `Fader` class assumes a "linear" input signal and if the value of the bin was previously mapped to dbFS it should have some "linear" character. Please note that this is still somewhat of a "proxy" value because ideally the summed amplitude of all relevant bins in the frequency range would be shown and not just the "loudest" one.
## Other changes
Rename `peakBand` to `linearPeakBand` to make more clear that a linear value is returned.
Handle a potential division by zero by checking the value of `fft->getEnergy()` before using it.
Index into `fft->m_bands` so that no parallel incrementing of the pointer is needed. This also enables the removal of the local variable `b`.
* Improve the rendering of the levels
The levels rendering now more explicitly distinguished between the rendering of the level outline/border and the level meters. The level rectangles are "inset" with regards to the borders so that there is a margin between the level borders and the meter readings. This margin is now also applied to the top and bottom of the levels. Levels are now also rendered as rounded rectangles similar to the level borders.
Only render the levels and peaks if their values are greater than the minimum level.
Make the radius of the rounded rectangles more pronounced by increasing its value from 1 to 2.
Decrease the margins so that the level readings become wider, i.e. so that they are rendered with more pixels.
Add the lambda `computeLevelMarkerRect` so that the rendering of the level markers is more decoupled from the rendering of the peak markers.
* Reduce code repetition
Reduce code repetition in `EqEffect::setBandPeaks` by introducing a lambda. Adjust code formatting.
* Code review changes
Code review changes in `Fader.cpp`. Mostly whitespace adjustments.
Split up the calculation of the meter width to make it more understandable. This also reduces the number of parentheses.
* Use MEMBER instead of READ/WRITE
Use `MEMBER` instead of `READ`/`WRITE` for some properties that are not called explicitly from outside of the class.
* Use default member initializers for Fader
Use default member initializers for the members in `Fader` that have previously been initialized in the constructor list.
* Make code clearer
Make code clearer in `Fader::FadermouseDoubleClickEvent`. Only divide if the dialog was accepted with OK.
* Replace knobFModel with std::vector
* Create QPixmap's on the stack
* Assign parent for QGraphicsScene
A call to QGraphicsView::setScene does not make
the view take ownership of the scene.
* Do not allocate QList on the heap
* Use static QPixmap's
The QPixmap's need to be created within the constructor, and not outside
where they are defined, since it can't find them otherwise.
I'm not too sure why.
* Clear m_vi2->knobFModel in destructor
* Use local static QPixmap's
* Do not allocate QPixmap with new in AudioFileProcessor
* Do not allocate QPixmap with new in Nes
* Do not allocate QPixmap with new in Organic
* Do not allocate QPixmap with new in SaControlsDialog
* Do not allocate QPixmap with new in Vestige
* Do not allocate QPixmap with new for FileBrowser
* Do not allocate QPixmap with new in MixerLine
* Do not allocate QPixmap with new in SendButtonIndicator
* Do not allocate QPixmap with new in AutomationClipView
* Do not allocate QPixmap with new in MidiClipView
* Do not allocate QPixmap with new in AutomationEditor
* Do not allocate QPixmap with new in PianoRoll
* Do not allocate QPixmap with new in TimeLineWidget
* Do not allocate QPixmap with new in EnvelopeAndLfoView
* Do not allocate QPixmap with new in PianoView
* Do not allocate QPixmap with new in ComboBox
* Do not allocate QPixmap with new in Fader
* Do not allocate QPixmap with new for LcdWidget
* Do not allocate QPixmap with new for LedCheckbox
* Use m_ as prefix for members
* Use uniform initialization
I already started using uniform initialization for the QPixmap changes
for some reason, so I'm finishing that up.
* Uniform initiaization
* And then he realized he was making copies...
* Do not call QPixmap copy constructor
* Do not call QPixmap copy constructor in SaControlsDialog
* Do not make pixmap's static for Lcd's and Led's
* Initialize pixmaps in-class
* Fix few mistakes and formatting
Introduce the new class SimpleTextFloat which simply shows a text and
that works like a pseudo tool tip with a narrow margin. It was extracted
from TextFloat to adhere to the single responsibility principle.
The new class is used by:
* Fader: display the current volume when moving the fader
* Knob: display the current value when the knob is moved
* PianoRoll: display the current value when setting the note volume and
panning
Add stylings for the new widget in style.css.
This PR places all LMMS symbols into namespaces to eliminate any potential future name collisions between LMMS and third-party modules.
Also, this PR changes back `LmmsCore` to `Engine`, reverting c519921306 .
Co-authored-by: allejok96 <allejok96@gmail.com>
Add m_conversionFactor to the AutomatableModelView. This factor will be applied to the model->value when displaying
it in the contextmenu of the control for the reset and copy actions. The factor will be applied when copying the value to
the clipboard. When pasting from the clipboard, the value will be divided by the factor.
Remove the model->displayValue() calls when updating the reset/copy/paste action text labels as this gives e.g. in the
Equalizer the wrong action text for the Frequency knobs.
In the Fader class, remove the m_displayConversion variable but rather use the new m_conversionFactor variable.
Rewire the setDisplayConversion() function to set the m_conversionFactor to 1.0 or 100.0.
Faders in FxMixer show now the correct context menu. Copying and pasting values between faders or even volume knobs
in tracks shows consistent behavior. Other faders (like in Eq) show the old behavior.
Moving empty destructors out of the .cpp files and into headers
allows them to be devirtualized in certain cases.
(When the compiler can't "see" a function in a header, it must largely
assume it's some black box that the linker will resolve.)
While we're at it, use C++11's `= default` to define empty virtual
desturctors for us.
For some classes (e.g., Piano), nothing is derived from it, so we can
mark the class as final and remove any explicit virtual dtor.
There are many other places where this can be done, but this is a large
enough patch as-is.
* Render the mixer levels in a dB FS scale
Adds the option to render the mixer levels in dB FS. By default this
option is disabled so that classes which inherit from Fader are not
affected by this change. However, in the code of the FxMixerView this
feature is enabled so that the mixer shows the levels in dB FS.
The ability to render in dB FS is exported as a property so that it can
also be set in a style sheet (not used as of now). The new property is
called "levelsDisplayedInDBFS".
There are now setters and getters for the min and max level.
Showing the levels in dB FS (which is a logarithmic scale) gives a less
"fidgety" impression when the levels are moving.
* Introduction of an init method in Fader
An init method was added to unify the initialization of the two Fader
constructors.
This commit addresses a lot of issues, namely:
1. When the "Move left/right" action was selected on a mixer channel
menu sometimes it would segfault due to the fxline object being
deleted before it returned to a method inside itself
2. The Fader was declaring a new variable for the model whereas it
should used the inherited model from FloatModelView < AutomatableModelView
3. Some methods were doing more things than they should be and
performing unnecessary actions. A little cleanup/refactor was made
Please notice that a bug of the same class as the one referred at point 1
still exists: clicking on "Remove channel". This commit does not
addresses this issue.
Fixes#1584