Skip to content

Commit

Permalink
Merge pull request #13648 from acolombier/fix/overview-minute-marker-…
Browse files Browse the repository at this point in the history
…div-by-zero

fix: prevent div by zero and use correct config key
  • Loading branch information
Swiftb0y authored Sep 15, 2024
2 parents 1296cdf + 0693553 commit cfa0e16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/preferences/dialog/dlgprefwaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ DlgPrefWaveform::DlgPrefWaveform(

m_pOverviewMinuteMarkersControl = std::make_unique<ControlObject>(
ConfigKey(QStringLiteral("[Waveform]"),
QStringLiteral("DrawOverviewMinuteMarkers")));
QStringLiteral("draw_overview_minute_markers")));
m_pOverviewMinuteMarkersControl->setReadOnly();

// Populate untilMark options
Expand Down Expand Up @@ -304,7 +304,7 @@ void DlgPrefWaveform::slotUpdate() {
}

bool drawOverviewMinuteMarkers = m_pConfig->getValue(
ConfigKey("[Waveform]", "DrawOverviewMinuteMarkers"), true);
ConfigKey("[Waveform]", "draw_overview_minute_markers"), true);
overviewMinuteMarkersCheckBox->setChecked(drawOverviewMinuteMarkers);
m_pOverviewMinuteMarkersControl->forceSet(drawOverviewMinuteMarkers);

Expand Down Expand Up @@ -575,7 +575,7 @@ void DlgPrefWaveform::slotSetNormalizeOverview(bool normalize) {
}

void DlgPrefWaveform::slotSetOverviewMinuteMarkers(bool draw) {
m_pConfig->setValue(ConfigKey("[Waveform]", "DrawOverviewMinuteMarkers"), draw);
m_pConfig->setValue(ConfigKey("[Waveform]", "draw_overview_minute_markers"), draw);
m_pOverviewMinuteMarkersControl->forceSet(draw);
}

Expand Down
13 changes: 11 additions & 2 deletions src/widget/woverview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ WOverview::WOverview(

m_pMinuteMarkersControl = make_parented<ControlProxy>(
QStringLiteral("[Waveform]"),
QStringLiteral("DrawOverviewMinuteMarkers"),
QStringLiteral("draw_overview_minute_markers"),
this);
m_pMinuteMarkersControl->connectValueChanged(this, &WOverview::slotMinuteMarkersChanged);
slotMinuteMarkersChanged(static_cast<bool>(m_pMinuteMarkersControl->get()));
Expand Down Expand Up @@ -741,6 +741,10 @@ void WOverview::drawMinuteMarkers(QPainter* pPainter) {
return;
}

if (m_pRateRatioControl->get() == 0) {
return;
}

// Faster than track->getDuration() and already has playback speed ratio compensated for
const double trackSeconds = samplePositionToSeconds(getTrackSamples());

Expand Down Expand Up @@ -1615,9 +1619,14 @@ void WOverview::paintText(const QString& text, QPainter* pPainter) {
}

double WOverview::samplePositionToSeconds(double sample) {
double rate = m_pRateRatioControl->get();
VERIFY_OR_DEBUG_ASSERT(rate != 0.0) {
return 1;
}

double trackTime = sample /
(m_trackSampleRateControl.get() * mixxx::kEngineChannelOutputCount);
return trackTime / m_pRateRatioControl->get();
return trackTime / rate;
}

void WOverview::resizeEvent(QResizeEvent* pEvent) {
Expand Down

0 comments on commit cfa0e16

Please sign in to comment.