Skip to content

Commit

Permalink
Vectorscope render fix (LMMS#7652)
Browse files Browse the repository at this point in the history
* Fix rendering for Vectorscope

The rendering of the Vectorscope is broken on Wayland if the size of the
Vectorscope is increased. This is caused by using a `QImage` to render
the scope traces which is then scaled up.

Introduce a new way to paint the vector scope (goniometer) which simply
paints lines or points that progressively get dimmer and which does not
make use of a QImage anymore.

It supports the following features:
* Log mode
* Zooming
* Rendering the drawing performance
* Selecting a different color for the traces

It does not support:
* HQ Mode: The new implementation provides a performance that's
  equivalent to Non-HQ mode and look similar or better than the HQ mode.
* Blurring of old data
* Persistence: Might be implemented by using a factor for the dimming

Rendering of the samples/trances uses the composition mode "Plus" so
that overlapping elements will appear like adding brightness. Painting
the grid and lines is done using the normal composition mode "Source
Over" so that it simply replaces existing pixels.

Painting of the lines/points and the grids and lines is done in a
"signal space", i.e. a transform where elements in the interval of
[-1, 1] feel "natural". The text is painted in "widget space".

* Remove old implementation

Remove HQ mode and persistence. Also remove the legacy option again.
This removes the models, loading, saving and the GUI controls.

Remove all unnecessary members from `VectorView`, adjust the
constructor. Move the implementation of `paintLinesMode` into
`paintEvent`. Remove methods `paintLegacyMode` and `paintLinesMode`.

* Move colors into VectorView

Move the colors out of `VecControls` into `VectorView` as they are
related to presentation.

* Remove friend relationship to VectorView

Remove a friend relationship to `VectorView` from `VecControls` by
introducing  const getters for the models.

* Remove VectorView::m_visible

Remove the unnecessary member `m_visible` from `VectorView`. It was not
initialized and only written to but never read.

* Make Vectorscope themeable

Make the Vectorscope themeable by introducing Qt properties for the
relevant colors.

The default theme gets the values from the code whereas the classic
theme gets a trace with amber color.

* Rename m_colorFG

Rename `m_colorFG` to `m_colorTrace`. Adjust the Qt property
accordingly.

Remove local variable `traceColor` from paint method and use member
`m_colorTrace` directly.

* Remove m_colorOutline

Remove unused member `m_colorOutline`.

* Fix horizontal lines on silence

Fix the horizontal lines that are rendered on silence. They seem to be
produced when rendering lines that start and end at the same point.

Therefore we only draw a point if the current and last point are the
same.

* Add some margin to the VectorView

Add some margin to the rendering of the `VectorView` so that the circle
does not touch the bounary of the widget.

* Clean up the layout of the Vectorscope

Clean up the layout of the Vectorscope. The checkboxes are not put on
top of the vector view anymore but are organized in a horizontal layout
beneath it. This gives a much tidier look.
  • Loading branch information
michaelgregorius authored Jan 22, 2025
1 parent 80a46d3 commit 501011e
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 268 deletions.
6 changes: 6 additions & 0 deletions data/themes/classic/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,12 @@ lmms--gui--CompressorControlDialog lmms--gui--Knob {
qproperty-lineWidth: 2;
}

lmms--gui--VectorView {
qproperty-colorTrace: rgba(255, 170, 33, 255);
qproperty-colorGrid: rgba(76, 80, 84, 128);
qproperty-colorLabels: rgba(76, 80, 84, 255);
}

lmms--gui--BarModelEditor {
qproperty-backgroundBrush: rgba(28, 73, 51, 255);
qproperty-barBrush: rgba(17, 136, 71, 255);
Expand Down
6 changes: 6 additions & 0 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,12 @@ lmms--gui--CompressorControlDialog lmms--gui--Knob {
qproperty-lineWidth: 2;
}

lmms--gui--VectorView {
qproperty-colorTrace: rgba(60, 255, 130, 255);
qproperty-colorGrid: rgba(76, 80, 84, 128);
qproperty-colorLabels: rgba(76, 80, 84, 255);
}

lmms--gui--BarModelEditor {
qproperty-backgroundBrush: rgba(28, 73, 51, 255);
qproperty-barBrush: rgba(17, 136, 71, 255);
Expand Down
14 changes: 3 additions & 11 deletions plugins/Vectorscope/VecControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,9 @@ VecControls::VecControls(Vectorscope *effect) :
m_effect(effect),

// initialize models and set default values
m_persistenceModel(0.5f, 0.0f, 1.0f, 0.05f, this, tr("Display persistence amount")),
m_logarithmicModel(false, this, tr("Logarithmic scale")),
m_highQualityModel(false, this, tr("High quality"))
m_linesModeModel(true, this, tr("Lines rendering"))
{
// Colors (percentages include sRGB gamma correction)
m_colorFG = QColor(60, 255, 130, 255); // ~LMMS green
m_colorGrid = QColor(76, 80, 84, 128); // ~60 % gray (slightly cold / blue), 50 % transparent
m_colorLabels = QColor(76, 80, 84, 255); // ~60 % gray (slightly cold / blue)
m_colorOutline = QColor(30, 34, 38, 255); // ~40 % gray (slightly cold / blue)
}


Expand All @@ -59,17 +53,15 @@ gui::EffectControlDialog* VecControls::createView()

void VecControls::loadSettings(const QDomElement &element)
{
m_persistenceModel.loadSettings(element, "Persistence");
m_logarithmicModel.loadSettings(element, "Logarithmic");
m_highQualityModel.loadSettings(element, "HighQuality");
m_linesModeModel.loadSettings(element, "LinesMode");
}


void VecControls::saveSettings(QDomDocument &document, QDomElement &element)
{
m_persistenceModel.saveSettings(document, element, "Persistence");
m_logarithmicModel.saveSettings(document, element, "Logarithmic");
m_highQualityModel.saveSettings(document, element, "HighQuality");
m_linesModeModel.saveSettings(document, element, "LinesMode");
}


Expand Down
12 changes: 4 additions & 8 deletions plugins/Vectorscope/VecControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,16 @@ class VecControls : public EffectControls
QString nodeName() const override {return "Vectorscope";}
int controlCount() override {return 3;}

const BoolModel& getLogarithmicModel() const { return m_logarithmicModel; }
const BoolModel& getLinesModel() const { return m_linesModeModel; }

private:
Vectorscope *m_effect;

FloatModel m_persistenceModel;
BoolModel m_logarithmicModel;
BoolModel m_highQualityModel;

QColor m_colorFG;
QColor m_colorGrid;
QColor m_colorLabels;
QColor m_colorOutline;
BoolModel m_linesModeModel;

friend class gui::VecControlsDialog;
friend class gui::VectorView;
};


Expand Down
39 changes: 12 additions & 27 deletions plugins/Vectorscope/VecControlsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,45 +44,31 @@ VecControlsDialog::VecControlsDialog(VecControls *controls) :
m_controls(controls)
{
auto master_layout = new QVBoxLayout;
master_layout->setContentsMargins(0, 2, 0, 0);
master_layout->setContentsMargins(0, 0, 0, 0);
setLayout(master_layout);

// Visualizer widget
// The size of 768 pixels seems to offer a good balance of speed, accuracy and trace thickness.
auto display = new VectorView(controls, m_controls->m_effect->getBuffer(), 768, this);
auto display = new VectorView(controls, m_controls->m_effect->getBuffer(), this);
master_layout->addWidget(display);

// Config area located inside visualizer
auto internal_layout = new QVBoxLayout(display);
auto config_layout = new QHBoxLayout();
auto switch_layout = new QVBoxLayout();
internal_layout->addStretch();
internal_layout->addLayout(config_layout);
config_layout->addLayout(switch_layout);

// High-quality switch
auto highQualityButton = new LedCheckBox(tr("HQ"), this);
highQualityButton->setToolTip(tr("Double the resolution and simulate continuous analog-like trace."));
highQualityButton->setCheckable(true);
highQualityButton->setModel(&controls->m_highQualityModel);
switch_layout->addWidget(highQualityButton);
auto controlLayout = new QHBoxLayout();
master_layout->addLayout(controlLayout);

// Log. scale switch
auto logarithmicButton = new LedCheckBox(tr("Log. scale"), this);
logarithmicButton->setToolTip(tr("Display amplitude on logarithmic scale to better see small values."));
logarithmicButton->setCheckable(true);
logarithmicButton->setModel(&controls->m_logarithmicModel);
switch_layout->addWidget(logarithmicButton);
controlLayout->addWidget(logarithmicButton);

config_layout->addStretch();
controlLayout->addStretch();

// Persistence knob
auto persistenceKnob = new Knob(KnobType::Small17, this);
persistenceKnob->setModel(&controls->m_persistenceModel);
persistenceKnob->setLabel(tr("Persist."));
persistenceKnob->setToolTip(tr("Trace persistence: higher amount means the trace will stay bright for longer time."));
persistenceKnob->setHintText(tr("Trace persistence"), "");
config_layout->addWidget(persistenceKnob);
// Switch between lines mode and point mode
auto linesMode = new LedCheckBox(tr("Lines"), this);
linesMode->setToolTip(tr("Render with lines."));
linesMode->setCheckable(true);
linesMode->setModel(&controls->m_linesModeModel);
controlLayout->addWidget(linesMode);
}


Expand All @@ -92,5 +78,4 @@ QSize VecControlsDialog::sizeHint() const
return QSize(275, 300);
}


} // namespace lmms::gui
Loading

0 comments on commit 501011e

Please sign in to comment.