Skip to content

Commit

Permalink
fixup! feat: add scrolling waveform in QML using scenegraph
Browse files Browse the repository at this point in the history
  • Loading branch information
acolombier committed Dec 1, 2024
1 parent a59fe88 commit ad11a74
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 62 deletions.
19 changes: 12 additions & 7 deletions src/qml/qmlwaveformrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,36 @@ QmlWaveformRendererMark::QmlWaveformRendererMark()

QmlWaveformRendererFactory::Renderer QmlWaveformRendererEndOfTrack::create(
WaveformWidgetRenderer* waveformWidget) const {
auto* renderer = new WaveformRendererEndOfTrack(waveformWidget, m_color);
auto* renderer = new WaveformRendererEndOfTrack(waveformWidget);
renderer->setup(m_color);
return QmlWaveformRendererFactory::Renderer{renderer, renderer};
}

QmlWaveformRendererFactory::Renderer QmlWaveformRendererPreroll::create(
WaveformWidgetRenderer* waveformWidget) const {
auto* renderer = new WaveformRendererPreroll(
waveformWidget, WaveformRendererAbstract::Play, m_color);
waveformWidget, WaveformRendererAbstract::Play);
renderer->setup(m_color);
return QmlWaveformRendererFactory::Renderer{renderer, renderer};
}

QmlWaveformRendererFactory::Renderer QmlWaveformRendererRGB::create(
WaveformWidgetRenderer* waveformWidget) const {
auto* renderer = new WaveformRendererRGB(waveformWidget,
::WaveformRendererAbstract::Play);
renderer->setup(
m_axesColor,
m_lowColor,
m_midColor,
m_highColor,
::WaveformRendererAbstract::Play);
m_highColor);
return QmlWaveformRendererFactory::Renderer{renderer, renderer};
}

QmlWaveformRendererFactory::Renderer QmlWaveformRendererBeat::create(
WaveformWidgetRenderer* waveformWidget) const {
auto* renderer = new WaveformRenderBeat(
waveformWidget, ::WaveformRendererAbstract::Play, m_color);
waveformWidget, ::WaveformRendererAbstract::Play);
renderer->setup(m_color);
return QmlWaveformRendererFactory::Renderer{renderer, renderer};
}

Expand Down Expand Up @@ -110,13 +114,14 @@ QmlWaveformRendererFactory::Renderer QmlWaveformRendererMark::create(
return QmlWaveformRendererFactory::Renderer{};
}
auto* renderer = new WaveformRenderMark(waveformWidget,
::WaveformRendererAbstract::Play);
renderer->setup(
m_playMarkerColor,
m_playMarkerBackground,
m_untilMark->showTime(),
m_untilMark->showBeats(),
static_cast<Qt::Alignment>(m_untilMark->align()),
m_untilMark->textSize(),
::WaveformRendererAbstract::Play);
m_untilMark->textSize());
int priority = 0;
for (auto* pMark : m_marks) {
renderer->addMark(WaveformMarkPointer(new WaveformMark(
Expand Down
6 changes: 2 additions & 4 deletions src/waveform/renderers/allshader/waveformrenderbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ using namespace rendergraph;
namespace allshader {

WaveformRenderBeat::WaveformRenderBeat(WaveformWidgetRenderer* waveformWidget,
::WaveformRendererAbstract::PositionSource type,
QColor color)
::WaveformRendererAbstract::PositionSource type)
: ::WaveformRendererAbstract(waveformWidget),
m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip),
m_color(color) {
m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip) {
initForRectangles<UniColorMaterial>(0);
setUsePreprocess(true);
}
Expand Down
7 changes: 5 additions & 2 deletions src/waveform/renderers/allshader/waveformrenderbeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ class allshader::WaveformRenderBeat final
public:
explicit WaveformRenderBeat(WaveformWidgetRenderer* waveformWidget,
::WaveformRendererAbstract::PositionSource type =
::WaveformRendererAbstract::Play,
QColor color = QColor());
::WaveformRendererAbstract::Play);

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

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

void setup(const QColor& color) {
m_color = color;
}

// Virtuals for rendergraph::Node
void preprocess() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ using namespace rendergraph;
namespace allshader {

WaveformRendererEndOfTrack::WaveformRendererEndOfTrack(
WaveformWidgetRenderer* waveformWidget, QColor color)
WaveformWidgetRenderer* waveformWidget)
: ::WaveformRendererAbstract(waveformWidget),
m_pEndOfTrackControl(nullptr),
m_pTimeRemainingControl(nullptr),
m_color(color) {
m_pTimeRemainingControl(nullptr) {
initForRectangles<RGBAMaterial>(0);
setUsePreprocess(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ class allshader::WaveformRendererEndOfTrack final
public rendergraph::GeometryNode {
public:
explicit WaveformRendererEndOfTrack(
WaveformWidgetRenderer* waveformWidget, QColor color = QColor());
WaveformWidgetRenderer* waveformWidge);

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

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

void setup(const QColor& color) {
m_color = color;
}

bool init() override;

// Virtual for rendergraph::Node
Expand Down
4 changes: 1 addition & 3 deletions src/waveform/renderers/allshader/waveformrendererpreroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ namespace allshader {

WaveformRendererPreroll::WaveformRendererPreroll(
WaveformWidgetRenderer* waveformWidget,
::WaveformRendererAbstract::PositionSource type,
QColor color)
::WaveformRendererAbstract::PositionSource type)
: ::WaveformRendererAbstract(waveformWidget),
m_color(color),
m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip) {
setGeometry(std::make_unique<Geometry>(PatternMaterial::attributes(), 0));
setMaterial(std::make_unique<PatternMaterial>());
Expand Down
7 changes: 5 additions & 2 deletions src/waveform/renderers/allshader/waveformrendererpreroll.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ class allshader::WaveformRendererPreroll final
explicit WaveformRendererPreroll(
WaveformWidgetRenderer* waveformWidget,
::WaveformRendererAbstract::PositionSource type =
::WaveformRendererAbstract::Play,
QColor color = QColor(200, 25, 20));
::WaveformRendererAbstract::Play);
~WaveformRendererPreroll() override;

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

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

void setup(const QColor& color) {
m_color = color;
}

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

Expand Down
18 changes: 8 additions & 10 deletions src/waveform/renderers/allshader/waveformrendererrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,24 @@ inline float math_pow2(float x) {
} // namespace

WaveformRendererRGB::WaveformRendererRGB(WaveformWidgetRenderer* waveformWidget,
#ifdef __RENDERGRAPH_IS_SCENEGRAPH
QColor axesColor,
QColor lowColor,
QColor midColor,
QColor highColor,
#endif
::WaveformRendererAbstract::PositionSource type,
WaveformRendererSignalBase::Options options)
: WaveformRendererSignalBase(waveformWidget),
m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip),
m_options(options) {
#ifdef __RENDERGRAPH_IS_SCENEGRAPH
initForRectangles<RGBMaterial>(0);
setUsePreprocess(true);
}

void WaveformRendererRGB::setup(const QColor& axesColor,
const QColor& lowColor,
const QColor& midColor,
const QColor& highColor) {
getRgbF(axesColor, &m_axesColor_r, &m_axesColor_g, &m_axesColor_b, &m_axesColor_a);

getRgbF(lowColor, &m_rgbLowColor_r, &m_rgbLowColor_g, &m_rgbLowColor_b);
getRgbF(midColor, &m_rgbMidColor_r, &m_rgbMidColor_g, &m_rgbMidColor_b);
getRgbF(highColor, &m_rgbHighColor_r, &m_rgbHighColor_g, &m_rgbHighColor_b);
#endif
initForRectangles<RGBMaterial>(0);
setUsePreprocess(true);
}

void WaveformRendererRGB::onSetup(const QDomNode& node) {
Expand Down
11 changes: 5 additions & 6 deletions src/waveform/renderers/allshader/waveformrendererrgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ class allshader::WaveformRendererRGB final
public rendergraph::GeometryNode {
public:
explicit WaveformRendererRGB(WaveformWidgetRenderer* waveformWidget,
#ifdef __RENDERGRAPH_IS_SCENEGRAPH
QColor axesColor,
QColor lowColor,
QColor midColor,
QColor highColor,
#endif
::WaveformRendererAbstract::PositionSource type =
::WaveformRendererAbstract::Play,
WaveformRendererSignalBase::Options options = WaveformRendererSignalBase::Option::None);

// Pure virtual from WaveformRendererSignalBase, not used
void onSetup(const QDomNode& node) override;

void setup(const QColor& axesColor,

Check failure on line 24 in src/waveform/renderers/allshader/waveformrendererrgb.h

View workflow job for this annotation

GitHub Actions / clazy

'allshader_gl::WaveformRendererRGB::setup' hides overloaded virtual function [-Werror,-Woverloaded-virtual]

Check failure on line 24 in src/waveform/renderers/allshader/waveformrendererrgb.h

View workflow job for this annotation

GitHub Actions / macOS 12 x64

'allshader_gl::WaveformRendererRGB::setup' hides overloaded virtual function [-Werror,-Woverloaded-virtual]

Check failure on line 24 in src/waveform/renderers/allshader/waveformrendererrgb.h

View workflow job for this annotation

GitHub Actions / macOS 12 arm64

'allshader_gl::WaveformRendererRGB::setup' hides overloaded virtual function [-Werror,-Woverloaded-virtual]
const QColor& lowColor,
const QColor& midColor,
const QColor& highColor);

bool supportsSlip() const override {
return true;
}
Expand Down
29 changes: 13 additions & 16 deletions src/waveform/renderers/allshader/waveformrendermark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,11 @@ QString timeSecToString(double timeSec) {

allshader::WaveformRenderMark::WaveformRenderMark(
WaveformWidgetRenderer* waveformWidget,
#ifdef __RENDERGRAPH_IS_SCENEGRAPH
QColor fgPlayColor,
QColor bgPlayColor,
bool untilMarkShowBeats,
bool untilMarkShowTime,
Qt::Alignment untilMarkAlign,
int untilMarkTextSize,
#endif
::WaveformRendererAbstract::PositionSource type)
: ::WaveformRenderMarkBase(waveformWidget, false),
m_beatsUntilMark(0),
m_timeUntilMark(0.0),
m_pTimeRemainingControl(nullptr),
#ifdef __RENDERGRAPH_IS_SCENEGRAPH
m_fgPlayColor(fgPlayColor),
m_bgPlayColor(bgPlayColor),
m_untilMarkShowBeats(untilMarkShowBeats),
m_untilMarkShowTime(untilMarkShowTime),
m_untilMarkAlign(untilMarkAlign),
m_untilMarkTextSize(untilMarkTextSize),
#endif
m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip),
m_playPosHeight(0.f),
m_playPosDevicePixelRatio(0.f) {
Expand Down Expand Up @@ -195,6 +179,19 @@ allshader::WaveformRenderMark::WaveformRenderMark(
}
}

void allshader::WaveformRenderMark::setup(const QColor& fgPlayColor,
const QColor& bgPlayColor,
bool untilMarkShowBeats,
bool untilMarkShowTime,
Qt::Alignment untilMarkAlign,
int untilMarkTextSize) {
m_fgPlayColor = fgPlayColor;

Check failure on line 188 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'm_fgPlayColor': undeclared identifier

Check failure on line 188 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / coverage

‘m_fgPlayColor’ was not declared in this scope; did you mean ‘fgPlayColor’?

Check failure on line 188 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / clazy

use of undeclared identifier 'm_fgPlayColor'; did you mean 'fgPlayColor'?
m_bgPlayColor = bgPlayColor;

Check failure on line 189 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'm_bgPlayColor': undeclared identifier

Check failure on line 189 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / coverage

‘m_bgPlayColor’ was not declared in this scope; did you mean ‘bgPlayColor’?
m_untilMarkShowBeats = untilMarkShowBeats;

Check failure on line 190 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'm_untilMarkShowBeats': undeclared identifier

Check failure on line 190 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / coverage

‘m_untilMarkShowBeats’ was not declared in this scope; did you mean ‘untilMarkShowBeats’?
m_untilMarkShowTime = untilMarkShowTime;

Check failure on line 191 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'm_untilMarkShowTime': undeclared identifier

Check failure on line 191 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / coverage

‘m_untilMarkShowTime’ was not declared in this scope; did you mean ‘untilMarkShowTime’?
m_untilMarkAlign = untilMarkAlign;

Check failure on line 192 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'm_untilMarkAlign': undeclared identifier

Check failure on line 192 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / coverage

‘m_untilMarkAlign’ was not declared in this scope; did you mean ‘untilMarkAlign’?
m_untilMarkTextSize = untilMarkTextSize;

Check failure on line 193 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'm_untilMarkTextSize': undeclared identifier

Check failure on line 193 in src/waveform/renderers/allshader/waveformrendermark.cpp

View workflow job for this annotation

GitHub Actions / coverage

‘m_untilMarkTextSize’ was not declared in this scope; did you mean ‘untilMarkTextSize’?
}
void allshader::WaveformRenderMark::draw(QPainter* painter, QPaintEvent* event) {
Q_UNUSED(painter);
Q_UNUSED(event);
Expand Down
15 changes: 7 additions & 8 deletions src/waveform/renderers/allshader/waveformrendermark.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase,
public rendergraph::Node {
public:
explicit WaveformRenderMark(WaveformWidgetRenderer* waveformWidget,
#ifdef __RENDERGRAPH_IS_SCENEGRAPH
QColor fgPlayColor,
QColor bgPlayColor,
bool untilMarkShowBeats,
bool untilMarkShowTime,
Qt::Alignment untilMarkAlign,
int untilMarkTextSize,
#endif
::WaveformRendererAbstract::PositionSource type =
::WaveformRendererAbstract::Play);

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

void setup(const QColor& fgPlayColor,

Check failure on line 31 in src/waveform/renderers/allshader/waveformrendermark.h

View workflow job for this annotation

GitHub Actions / clazy

'allshader_gl::WaveformRenderMark::setup' hides overloaded virtual function [-Werror,-Woverloaded-virtual]
const QColor& bgPlayColor,
bool untilMarkShowBeats,
bool untilMarkShowTime,
Qt::Alignment untilMarkAlign,
int untilMarkTextSize);

bool init() override;

void update();
Expand Down

0 comments on commit ad11a74

Please sign in to comment.