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

Use the real track length to scale waveforms #11162

Merged
merged 11 commits into from
Feb 20, 2023
Merged
15 changes: 13 additions & 2 deletions src/waveform/renderers/glslwaveformrenderersignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ void GLSLWaveformRendererSignal::draw(QPainter* painter, QPaintEvent* /*event*/)
return;
}

const double audioVisualRatio = pWaveform->getAudioVisualRatio();
if (audioVisualRatio <= 0) {
return;
}

int dataSize = pWaveform->getDataSize();
if (dataSize <= 1) {
return;
Expand All @@ -276,6 +281,11 @@ void GLSLWaveformRendererSignal::draw(QPainter* painter, QPaintEvent* /*event*/)
return;
}

const int trackSamples = m_waveformRenderer->getTrackSamples();
if (trackSamples <= 0) {
return;
}

maybeInitializeGL();

// save the GL state set for QPainter
Expand All @@ -294,9 +304,10 @@ void GLSLWaveformRendererSignal::draw(QPainter* painter, QPaintEvent* /*event*/)
getGains(&allGain, &lowGain, &midGain, &highGain);

const auto firstVisualIndex = static_cast<GLfloat>(
m_waveformRenderer->getFirstDisplayedPosition() * dataSize / 2.0);
m_waveformRenderer->getFirstDisplayedPosition() * trackSamples /
audioVisualRatio / 2.0);
const auto lastVisualIndex = static_cast<GLfloat>(
m_waveformRenderer->getLastDisplayedPosition() * dataSize / 2.0);
m_waveformRenderer->getLastDisplayedPosition() * trackSamples / audioVisualRatio / 2.0);

// const int firstIndex = int(firstVisualIndex+0.5);
// firstVisualIndex = firstIndex - firstIndex%2;
Copy link
Member

Choose a reason for hiding this comment

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

There is a check above, that the integer datasize can't be <=1. Therefore dataSize / 2.0 can't be smaller than 1.0. I wonder if a similar check for trackSamples / audioVisualRatio / 2.0 is needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

trackSamples and audioVisualRatio are also checked individual.

Expand Down
16 changes: 14 additions & 2 deletions src/waveform/renderers/glvsynctestrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void GLVSyncTestRenderer::draw(QPainter* painter, QPaintEvent* /*event*/) {
return;
}

const double audioVisualRatio = pWaveform->getAudioVisualRatio();
if (audioVisualRatio <= 0) {
return;
}

const int dataSize = pWaveform->getDataSize();
if (dataSize <= 1) {
return;
Expand All @@ -54,8 +59,15 @@ void GLVSyncTestRenderer::draw(QPainter* painter, QPaintEvent* /*event*/) {
return;
}

double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize;
double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize;
const int trackSamples = m_waveformRenderer->getTrackSamples();
if (trackSamples <= 0) {
return;
}

double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() *
trackSamples / audioVisualRatio;
double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() *
trackSamples / audioVisualRatio;

const int firstIndex = int(firstVisualIndex + 0.5);
firstVisualIndex = firstIndex - firstIndex % 2;
Expand Down
14 changes: 12 additions & 2 deletions src/waveform/renderers/glwaveformrendererfilteredsignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ void GLWaveformRendererFilteredSignal::draw(QPainter* painter, QPaintEvent* /*ev
return;
}

const double audioVisualRatio = pWaveform->getAudioVisualRatio();
if (audioVisualRatio <= 0) {
return;
}

const int dataSize = pWaveform->getDataSize();
if (dataSize <= 1) {
return;
Expand All @@ -45,10 +50,15 @@ void GLWaveformRendererFilteredSignal::draw(QPainter* painter, QPaintEvent* /*ev
return;
}

const int trackSamples = m_waveformRenderer->getTrackSamples();
if (trackSamples <= 0) {
return;
}

auto firstVisualIndex = static_cast<GLfloat>(
m_waveformRenderer->getFirstDisplayedPosition() * dataSize);
m_waveformRenderer->getFirstDisplayedPosition() * trackSamples / audioVisualRatio);
auto lastVisualIndex = static_cast<GLfloat>(
m_waveformRenderer->getLastDisplayedPosition() * dataSize);
m_waveformRenderer->getLastDisplayedPosition() * trackSamples / audioVisualRatio);
const auto lineWidth = static_cast<GLfloat>(
1.0 / m_waveformRenderer->getVisualSamplePerPixel() + 1);

Expand Down
14 changes: 12 additions & 2 deletions src/waveform/renderers/glwaveformrendererrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void GLWaveformRendererRGB::draw(QPainter* painter, QPaintEvent* /*event*/) {
return;
}

const double audioVisualRatio = pWaveform->getAudioVisualRatio();
if (audioVisualRatio <= 0) {
return;
}

const int dataSize = pWaveform->getDataSize();
if (dataSize <= 1) {
return;
Expand All @@ -47,10 +52,15 @@ void GLWaveformRendererRGB::draw(QPainter* painter, QPaintEvent* /*event*/) {
return;
}

const int trackSamples = m_waveformRenderer->getTrackSamples();
if (trackSamples <= 0) {
return;
}

auto firstVisualIndex = static_cast<GLfloat>(
m_waveformRenderer->getFirstDisplayedPosition() * dataSize);
m_waveformRenderer->getFirstDisplayedPosition() * trackSamples / audioVisualRatio);
auto lastVisualIndex = static_cast<GLfloat>(
m_waveformRenderer->getLastDisplayedPosition() * dataSize);
m_waveformRenderer->getLastDisplayedPosition() * trackSamples / audioVisualRatio);
const auto lineWidth = static_cast<GLfloat>(
(1.0 / m_waveformRenderer->getVisualSamplePerPixel()) + 1.5);

Expand Down
14 changes: 12 additions & 2 deletions src/waveform/renderers/glwaveformrenderersimplesignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void GLWaveformRendererSimpleSignal::draw(QPainter* painter, QPaintEvent* /*even
return;
}

const double audioVisualRatio = pWaveform->getAudioVisualRatio();
if (audioVisualRatio <= 0) {
return;
}

const int dataSize = pWaveform->getDataSize();
if (dataSize <= 1) {
return;
Expand All @@ -47,10 +52,15 @@ void GLWaveformRendererSimpleSignal::draw(QPainter* painter, QPaintEvent* /*even
return;
}

const int trackSamples = m_waveformRenderer->getTrackSamples();
if (trackSamples <= 0) {
return;
}

auto firstVisualIndex = static_cast<GLfloat>(
m_waveformRenderer->getFirstDisplayedPosition() * dataSize);
m_waveformRenderer->getFirstDisplayedPosition() * trackSamples / audioVisualRatio);
auto lastVisualIndex = static_cast<GLfloat>(
m_waveformRenderer->getLastDisplayedPosition() * dataSize);
m_waveformRenderer->getLastDisplayedPosition() * trackSamples / audioVisualRatio);
const auto lineWidth = static_cast<GLfloat>(
1.0 / m_waveformRenderer->getVisualSamplePerPixel() + 1);

Expand Down
18 changes: 16 additions & 2 deletions src/waveform/renderers/qtwaveformrendererfilteredsignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ int QtWaveformRendererFilteredSignal::buildPolygon() {
return 0;
}

const double audioVisualRatio = pWaveform->getAudioVisualRatio();
if (audioVisualRatio <= 0) {
return 0;
}

const int dataSize = pWaveform->getDataSize();
if (dataSize <= 1) {
return 0;
Expand All @@ -117,8 +122,17 @@ int QtWaveformRendererFilteredSignal::buildPolygon() {
return 0;
}

const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize;
const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize;
const int trackSamples = m_waveformRenderer->getTrackSamples();
if (trackSamples <= 0) {
return 0;
}

const double firstVisualIndex =
m_waveformRenderer->getFirstDisplayedPosition() * trackSamples /
audioVisualRatio;
const double lastVisualIndex =
m_waveformRenderer->getLastDisplayedPosition() * trackSamples /
audioVisualRatio;

m_polygon[0].clear();
m_polygon[1].clear();
Expand Down
18 changes: 16 additions & 2 deletions src/waveform/renderers/qtwaveformrenderersimplesignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ void QtWaveformRendererSimpleSignal::draw(QPainter* painter, QPaintEvent* /*even
return;
}

const double audioVisualRatio = pWaveform->getAudioVisualRatio();
if (audioVisualRatio <= 0) {
return;
}

const int dataSize = pWaveform->getDataSize();
if (dataSize <= 1) {
return;
Expand All @@ -59,6 +64,11 @@ void QtWaveformRendererSimpleSignal::draw(QPainter* painter, QPaintEvent* /*even
return;
}

const int trackSamples = m_waveformRenderer->getTrackSamples();
if (trackSamples <= 0) {
return;
}

PainterScope PainterScope(painter);

painter->setRenderHint(QPainter::Antialiasing);
Expand Down Expand Up @@ -90,8 +100,12 @@ void QtWaveformRendererSimpleSignal::draw(QPainter* painter, QPaintEvent* /*even
painter->drawLine(0,0,m_waveformRenderer->getLength(),0);
}

const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize;
const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize;
const double firstVisualIndex =
m_waveformRenderer->getFirstDisplayedPosition() * trackSamples /
audioVisualRatio;
const double lastVisualIndex =
m_waveformRenderer->getLastDisplayedPosition() * trackSamples /
audioVisualRatio;
m_polygon.clear();
m_polygon.reserve(2 * m_waveformRenderer->getLength() + 2);
m_polygon.append(QPointF(0.0, 0.0));
Expand Down
18 changes: 16 additions & 2 deletions src/waveform/renderers/waveformrendererfilteredsignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ void WaveformRendererFilteredSignal::draw(QPainter* painter,
return;
}

const double audioVisualRatio = pWaveform->getAudioVisualRatio();
if (audioVisualRatio <= 0) {
return;
}

const int dataSize = pWaveform->getDataSize();
if (dataSize <= 1) {
return;
Expand All @@ -50,6 +55,11 @@ void WaveformRendererFilteredSignal::draw(QPainter* painter,
return;
}

const int trackSamples = m_waveformRenderer->getTrackSamples();
if (trackSamples <= 0) {
return;
}

PainterScope PainterScope(painter);

painter->setRenderHints(QPainter::Antialiasing, false);
Expand All @@ -62,8 +72,12 @@ void WaveformRendererFilteredSignal::draw(QPainter* painter,
painter->setTransform(QTransform(0, 1, 1, 0, 0, 0));
}

const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize;
const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize;
const double firstVisualIndex =
m_waveformRenderer->getFirstDisplayedPosition() * trackSamples /
audioVisualRatio;
const double lastVisualIndex =
m_waveformRenderer->getLastDisplayedPosition() * trackSamples /
audioVisualRatio;

// Represents the # of waveform data points per horizontal pixel.
const double gain = (lastVisualIndex - firstVisualIndex) /
Expand Down
18 changes: 16 additions & 2 deletions src/waveform/renderers/waveformrendererhsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ void WaveformRendererHSV::draw(QPainter* painter,
return;
}

const double audioVisualRatio = pWaveform->getAudioVisualRatio();
if (audioVisualRatio <= 0) {
return;
}

const int dataSize = pWaveform->getDataSize();
if (dataSize <= 1) {
return;
Expand All @@ -43,6 +48,11 @@ void WaveformRendererHSV::draw(QPainter* painter,
return;
}

const int trackSamples = m_waveformRenderer->getTrackSamples();
if (trackSamples <= 0) {
return;
}

PainterScope PainterScope(painter);

painter->setRenderHints(QPainter::Antialiasing, false);
Expand All @@ -55,8 +65,12 @@ void WaveformRendererHSV::draw(QPainter* painter,
painter->setTransform(QTransform(0, 1, 1, 0, 0, 0));
}

const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize;
const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize;
const double firstVisualIndex =
m_waveformRenderer->getFirstDisplayedPosition() * trackSamples /
audioVisualRatio;
const double lastVisualIndex =
m_waveformRenderer->getLastDisplayedPosition() * trackSamples /
audioVisualRatio;

const double offset = firstVisualIndex;

Expand Down
18 changes: 16 additions & 2 deletions src/waveform/renderers/waveformrendererrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ void WaveformRendererRGB::draw(QPainter* painter,
return;
}

const double audioVisualRatio = pWaveform->getAudioVisualRatio();
if (audioVisualRatio <= 0) {
return;
}

const int dataSize = pWaveform->getDataSize();
if (dataSize <= 1) {
return;
Expand All @@ -42,6 +47,11 @@ void WaveformRendererRGB::draw(QPainter* painter,
return;
}

const int trackSamples = m_waveformRenderer->getTrackSamples();
if (trackSamples <= 0) {
return;
}

PainterScope PainterScope(painter);

painter->setRenderHints(QPainter::Antialiasing, false);
Expand All @@ -54,8 +64,12 @@ void WaveformRendererRGB::draw(QPainter* painter,
painter->setTransform(QTransform(0, 1, 1, 0, 0, 0));
}

const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize;
const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize;
const double firstVisualIndex =
m_waveformRenderer->getFirstDisplayedPosition() * trackSamples /
audioVisualRatio;
const double lastVisualIndex =
m_waveformRenderer->getLastDisplayedPosition() * trackSamples /
audioVisualRatio;

const double offset = firstVisualIndex;

Expand Down