Skip to content

Commit

Permalink
avoid rare marker position rounding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
m0dB committed Feb 20, 2023
1 parent aba1759 commit c993a20
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/waveform/renderers/qopengl/waveformrendermark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ void qopengl::WaveformRenderMark::renderGL() {
}
m_waveformRenderer->setMarkPositions(marksOnScreen);

// TODO orientation
double currentMarkPoint = m_waveformRenderer->getPlayMarkerPosition() *
m_waveformRenderer->getWidth();
currentMarkPoint = std::floor(currentMarkPoint);
Expand Down
8 changes: 5 additions & 3 deletions src/waveform/renderers/waveformwidgetrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ WaveformWidgetRenderer::WaveformWidgetRenderer(const QString& group)
m_scaleFactor(1.0),
m_playMarkerPosition(s_defaultPlayMarkerPosition),
m_passthroughEnabled(false),
m_playPos(-1) {
m_playPos(-1.0),
m_truePosSample(-1.0) {
//qDebug() << "WaveformWidgetRenderer";

#ifdef WAVEFORMWIDGETRENDERER_DEBUG
Expand Down Expand Up @@ -152,7 +153,7 @@ void WaveformWidgetRenderer::onPreRender(VSyncThread* vsyncThread) {
m_playPos = round(truePlayPos * m_trackPixelCount) / m_trackPixelCount;
m_totalVSamples = static_cast<int>(m_trackPixelCount * m_visualSamplePerPixel);
m_playPosVSample = static_cast<int>(m_playPos * m_totalVSamples);

m_truePosSample = truePlayPos * static_cast<double>(m_trackSamples);
double leftOffset = m_playMarkerPosition;
double rightOffset = 1.0 - m_playMarkerPosition;

Expand All @@ -169,7 +170,8 @@ void WaveformWidgetRenderer::onPreRender(VSyncThread* vsyncThread) {
m_firstDisplayedPosition = m_playPos - displayedLengthLeft;
m_lastDisplayedPosition = m_playPos + displayedLengthRight;
} else {
m_playPos = -1; // disable renderers
m_playPos = -1.0; // disable renderers
m_truePosSample = -1.0;
}

//qDebug() << "WaveformWidgetRenderer::onPreRender" <<
Expand Down
8 changes: 8 additions & 0 deletions src/waveform/renderers/waveformwidgetrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class WaveformWidgetRenderer {
// stable and deterministic
// Transform sample index to pixel in track.
inline double transformSamplePositionInRendererWorld(double samplePosition) const {
if (std::abs(samplePosition - m_truePosSample) < 1.f) {
// When asked for the sample position that corresponds with the play
// marker, return the play market pixel position. This avoids a rare
// rounding issue where a marker at that sample position would be
// 1 pixel off.
return m_playMarkerPosition * getLength();
}
const double relativePosition = samplePosition / m_trackSamples;
return transformPositionInRendererWorld(relativePosition);
}
Expand Down Expand Up @@ -219,4 +226,5 @@ class WaveformWidgetRenderer {

bool m_passthroughEnabled;
double m_playPos;
double m_truePosSample;
};

0 comments on commit c993a20

Please sign in to comment.