Skip to content

Commit

Permalink
reduce delta with qml-rendergraph-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
m0dB authored and m0dB committed Nov 2, 2024
1 parent c7a3c7a commit f409455
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 64 deletions.
56 changes: 30 additions & 26 deletions src/waveform/renderers/allshader/waveformrendererendoftrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ void WaveformRendererEndOfTrack::setup(const QDomNode& node, const SkinContext&
}

void WaveformRendererEndOfTrack::preprocess() {
if (!preprocessInner()) {
geometry().allocate(0);
markDirtyGeometry();
}
}

bool WaveformRendererEndOfTrack::preprocessInner() {
if (!m_pEndOfTrackControl->toBool()) {
return false;
}

const int elapsed = m_timer.elapsed().toIntegerMillis() % kBlinkingPeriodMillis;

const double blinkIntensity = (double)(2 * abs(elapsed - kBlinkingPeriodMillis / 2)) /
Expand All @@ -70,39 +81,32 @@ void WaveformRendererEndOfTrack::preprocess() {
const double criticalIntensity = (remainingTimeTriggerSeconds - remainingTime) /
remainingTimeTriggerSeconds;

const double alpha = criticalIntensity * blinkIntensity;
const double alpha = std::min(1.0, std::max(0.0, criticalIntensity * blinkIntensity));

if (alpha != 0.0) {
QSizeF size(m_waveformRenderer->getWidth(), m_waveformRenderer->getHeight());
float r, g, b, a;
getRgbF(m_color, &r, &g, &b, &a);
QSizeF size(m_waveformRenderer->getWidth(), m_waveformRenderer->getHeight());
float r, g, b, a;
getRgbF(m_color, &r, &g, &b, &a);

const float posx0 = 0.f;
const float posx1 = size.width() / 2.f;
const float posx2 = size.width();
const float posy1 = 0.f;
const float posy2 = size.height();
const float posx0 = 0.f;
const float posx1 = size.width() / 2.f;

Check failure on line 91 in src/waveform/renderers/allshader/waveformrendererendoftrack.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04

conversion from ‘qreal’ {aka ‘double’} to ‘float’ may change value [-Werror=float-conversion]

Check warning on line 91 in src/waveform/renderers/allshader/waveformrendererendoftrack.cpp

View workflow job for this annotation

GitHub Actions / coverage

conversion from ‘qreal’ {aka ‘double’} to ‘float’ may change value [-Wfloat-conversion]
const float posx2 = size.width();

Check failure on line 92 in src/waveform/renderers/allshader/waveformrendererendoftrack.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04

conversion from ‘qreal’ {aka ‘double’} to ‘float’ may change value [-Werror=float-conversion]

Check warning on line 92 in src/waveform/renderers/allshader/waveformrendererendoftrack.cpp

View workflow job for this annotation

GitHub Actions / coverage

conversion from ‘qreal’ {aka ‘double’} to ‘float’ may change value [-Wfloat-conversion]
const float posy1 = 0.f;
const float posy2 = size.height();

Check failure on line 94 in src/waveform/renderers/allshader/waveformrendererendoftrack.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04

conversion from ‘qreal’ {aka ‘double’} to ‘float’ may change value [-Werror=float-conversion]

Check warning on line 94 in src/waveform/renderers/allshader/waveformrendererendoftrack.cpp

View workflow job for this annotation

GitHub Actions / coverage

conversion from ‘qreal’ {aka ‘double’} to ‘float’ may change value [-Wfloat-conversion]

float minAlpha = 0.5f * static_cast<float>(alpha);
float maxAlpha = 0.83f * static_cast<float>(alpha);
float minAlpha = 0.5f * static_cast<float>(alpha);
float maxAlpha = 0.83f * static_cast<float>(alpha);

geometry().allocate(6 * 2);
RGBAVertexUpdater vertexUpdater{geometry().vertexDataAs<Geometry::RGBAColoredPoint2D>()};
vertexUpdater.addRectangleHGradient(
{posx0, posy1}, {posx1, posy2}, {r, g, b, minAlpha}, {r, g, b, minAlpha});
vertexUpdater.addRectangleHGradient(
{posx1, posy1}, {posx2, posy2}, {r, g, b, minAlpha}, {r, g, b, maxAlpha});
geometry().allocate(6 * 2);
RGBAVertexUpdater vertexUpdater{geometry().vertexDataAs<Geometry::RGBAColoredPoint2D>()};
vertexUpdater.addRectangleHGradient(
{posx0, posy1}, {posx1, posy2}, {r, g, b, minAlpha}, {r, g, b, minAlpha});
vertexUpdater.addRectangleHGradient(
{posx1, posy1}, {posx2, posy2}, {r, g, b, minAlpha}, {r, g, b, maxAlpha});

markDirtyGeometry();
} else if (geometry().vertexCount() != 0) {
geometry().allocate(0);
markDirtyGeometry();
}
markDirtyGeometry();
markDirtyMaterial();
}

bool WaveformRendererEndOfTrack::isSubtreeBlocked() const {
return !m_pEndOfTrackControl->toBool();
return true;
}

} // namespace allshader
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class allshader::WaveformRendererEndOfTrack final

// Virtual for rendergraph::Node
void preprocess() override;
bool isSubtreeBlocked() const override;

private:
std::unique_ptr<ControlProxy> m_pEndOfTrackControl;
Expand All @@ -42,5 +41,7 @@ class allshader::WaveformRendererEndOfTrack final
QColor m_color;
PerformanceTimer m_timer;

bool preprocessInner();

DISALLOW_COPY_AND_ASSIGN(WaveformRendererEndOfTrack);
};
11 changes: 1 addition & 10 deletions src/waveform/renderers/allshader/waveformrendermark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void allshader::WaveformRenderMark::draw(QPainter* painter, QPaintEvent* event)
bool allshader::WaveformRenderMark::init() {
m_pTimeRemainingControl = std::make_unique<ControlProxy>(
m_waveformRenderer->getGroup(), "time_remaining");
::WaveformRenderMarkBase::init();
return true;
}

Expand Down Expand Up @@ -150,16 +151,6 @@ bool allshader::WaveformRenderMark::isSubtreeBlocked() const {
return m_isSlipRenderer && !m_waveformRenderer->isSlipActive();
}

namespace {
template<class T>
std::unique_ptr<T> castToUniquePtr(std::unique_ptr<rendergraph::BaseNode>&& pNode) {
if (dynamic_cast<T*>(pNode.get())) {
return std::unique_ptr<T>(dynamic_cast<T*>(pNode.release()));
}
return std::unique_ptr<T>();
}
} // namespace

void allshader::WaveformRenderMark::update() {
if (isSubtreeBlocked()) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/allshader/waveformrendermark.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class allshader::WaveformMarkNodeGraphics : public ::WaveformMark::Graphics {

private:
WaveformMarkNode* waveformMarkNode() const {
DEBUG_ASSERT(!m_pNode);
DEBUG_ASSERT(m_pNode);
return static_cast<WaveformMarkNode*>(m_pNode.get());
}

Expand Down
11 changes: 5 additions & 6 deletions src/waveform/renderers/allshader/waveformrendermarkrange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ void WaveformRenderMarkRange::setup(const QDomNode& node, const SkinContext& ski
QDomNode child = node.firstChild();
while (!child.isNull()) {
if (child.nodeName() == "MarkRange") {
m_markRanges.push_back(
WaveformMarkRange(
m_waveformRenderer->getGroup(),
child,
skinContext,
*m_waveformRenderer->getWaveformSignalColors()));
addRange(WaveformMarkRange(
m_waveformRenderer->getGroup(),
child,
skinContext,
*m_waveformRenderer->getWaveformSignalColors()));
}
child = child.nextSibling();
}
Expand Down
9 changes: 6 additions & 3 deletions src/waveform/renderers/allshader/waveformrendermarkrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <QColor>
#include <QVector2D>
#include <memory>

#include "rendergraph/node.h"
#include "util/class.h"
Expand All @@ -14,17 +13,21 @@ class SkinContext;

namespace rendergraph {
class GeometryNode;
}
} // namespace rendergraph

namespace allshader {
class WaveformRenderMarkRange;
}
} // namespace allshader

class allshader::WaveformRenderMarkRange final : public ::WaveformRendererAbstract,
public rendergraph::Node {
public:
explicit WaveformRenderMarkRange(WaveformWidgetRenderer* waveformWidget);

void addRange(WaveformMarkRange&& range) {
m_markRanges.push_back(std::move(range));
}

// Pure virtual from WaveformRendererAbstract, not used
void draw(QPainter* painter, QPaintEvent* event) override final;

Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/waveformmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

#include "control/controlproxy.h"
#include "track/cue.h"
#include "waveform/renderers/waveformsignalcolors.h"
#include "waveform/waveformmarklabel.h"

class SkinContext;
class WaveformSignalColors;
class QOpenGLTexture;

namespace allshader {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/waveformmarkrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class WaveformMarkRange {
WaveformMarkLabel m_durationLabel;

private:
void generateImage(int weidth, int height);
void generateImage(int width, int height);

std::unique_ptr<ControlProxy> m_markStartPointControl;
std::unique_ptr<ControlProxy> m_markEndPointControl;
Expand Down
4 changes: 4 additions & 0 deletions src/waveform/renderers/waveformrendermarkbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ WaveformRenderMarkBase::WaveformRenderMarkBase(
void WaveformRenderMarkBase::setup(const QDomNode& node, const SkinContext& context) {
WaveformSignalColors signalColors = *m_waveformRenderer->getWaveformSignalColors();
m_marks.setup(m_waveformRenderer->getGroup(), node, context, signalColors);
}

bool WaveformRenderMarkBase::init() {
m_marks.connectSamplePositionChanged(this, &WaveformRenderMarkBase::onMarkChanged);
m_marks.connectSampleEndPositionChanged(this, &WaveformRenderMarkBase::onMarkChanged);
m_marks.connectVisibleChanged(this, &WaveformRenderMarkBase::onMarkChanged);
return true;
}

void WaveformRenderMarkBase::onSetTrack() {
Expand Down
2 changes: 2 additions & 0 deletions src/waveform/renderers/waveformrendermarkbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class WaveformRenderMarkBase : public QObject, public WaveformRendererAbstract {

void setup(const QDomNode& node, const SkinContext& context) override;

bool init() override;

// Called when a new track is loaded.
void onSetTrack() override;

Expand Down
18 changes: 6 additions & 12 deletions src/waveform/renderers/waveformwidgetrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ WaveformWidgetRenderer::WaveformWidgetRenderer(const QString& group)
// Really create some to manage those;
m_visualPlayPosition(nullptr),
m_totalVSamples(0),
m_pRateRatioCO(nullptr),
m_pGainControlObject(nullptr),
m_gain(1.0),
m_pTrackSamplesControlObject(nullptr),
m_trackSamples(0),
m_trackSamples(0.0),
m_scaleFactor(1.0),
m_playMarkerPosition(s_defaultPlayMarkerPosition),
m_pContext(nullptr),
m_passthroughEnabled(false) {
//qDebug() << "WaveformWidgetRenderer";
for (int type = ::WaveformRendererAbstract::Play;
Expand Down Expand Up @@ -76,10 +74,6 @@ WaveformWidgetRenderer::~WaveformWidgetRenderer() {
delete m_rendererStack[i];
}

delete m_pRateRatioCO;
delete m_pGainControlObject;
delete m_pTrackSamplesControlObject;

#ifdef WAVEFORMWIDGETRENDERER_DEBUG
delete m_timer;
#endif
Expand All @@ -90,11 +84,11 @@ bool WaveformWidgetRenderer::init() {

m_visualPlayPosition = VisualPlayPosition::getVisualPlayPosition(m_group);

m_pRateRatioCO = new ControlProxy(
m_pRateRatioCO = std::make_unique<ControlProxy>(
m_group, "rate_ratio");
m_pGainControlObject = new ControlProxy(
m_pGainControlObject = std::make_unique<ControlProxy>(
m_group, "total_gain");
m_pTrackSamplesControlObject = new ControlProxy(
m_pTrackSamplesControlObject = std::make_unique<ControlProxy>(
m_group, "track_samples");

for (int i = 0; i < m_rendererStack.size(); ++i) {
Expand Down Expand Up @@ -419,7 +413,7 @@ void WaveformWidgetRenderer::setDisplayBeatGridAlpha(int alpha) {
void WaveformWidgetRenderer::setTrack(TrackPointer track) {
m_pTrack = track;
//used to postpone first display until track sample is actually available
m_trackSamples = -1;
m_trackSamples = -1.0;

for (int i = 0; i < m_rendererStack.size(); ++i) {
m_rendererStack[i]->onSetTrack();
Expand Down
6 changes: 3 additions & 3 deletions src/waveform/renderers/waveformwidgetrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ class WaveformWidgetRenderer {
QSharedPointer<VisualPlayPosition> m_visualPlayPosition;
int m_posVSample[2];
int m_totalVSamples;
ControlProxy* m_pRateRatioCO;
ControlProxy* m_pGainControlObject;
std::unique_ptr<ControlProxy> m_pRateRatioCO;
std::unique_ptr<ControlProxy> m_pGainControlObject;
std::unique_ptr<ControlProxy> m_pTrackSamplesControlObject;
double m_gain;
ControlProxy* m_pTrackSamplesControlObject;
double m_trackSamples;
double m_scaleFactor;
double m_playMarkerPosition; // 0.0 - left, 0.5 - center, 1.0 - right
Expand Down

0 comments on commit f409455

Please sign in to comment.