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

Fix waveform overview lenght. #11359

Merged
merged 5 commits into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/widget/woverview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void WOverview::onConnectedControlChanged(double dParameter, double dValue) {
// least once per second, regardless of m_iPos which depends on the length
// of the widget.
int oldPositionSeconds = m_iPosSeconds;
m_iPosSeconds = static_cast<int>(dParameter * m_trackSamplesControl->get());
m_iPosSeconds = static_cast<int>(dParameter * getTrackSamples());
if ((m_bTimeRulerActive || m_pHoveredMark != nullptr) && oldPositionSeconds != m_iPosSeconds) {
redraw = true;
}
Expand Down Expand Up @@ -320,13 +320,20 @@ void WOverview::slotLoadingTrack(TrackPointer pNewTrack, TrackPointer pOldTrack)
&Track::waveformSummaryUpdated,
this,
&WOverview::slotWaveformSummaryUpdated);
disconnect(m_pCurrentTrack.get(),
&Track::cuesUpdated,
this,
&WOverview::receiveCuesUpdated);
}

m_waveformSourceImage = QImage();
m_analyzerProgress = kAnalyzerProgressUnknown;
m_actualCompletion = 0;
m_waveformPeak = -1.0;
m_pixmapDone = false;
// Note: Here we already have the new track, but the engine and it's
// Control Objects may still have the old one until the slotTrackLoaded()
// signal has been received.
m_trackLoaded = false;
m_endOfTrack = false;

Expand Down Expand Up @@ -492,7 +499,8 @@ void WOverview::mouseReleaseEvent(QMouseEvent* e) {
void WOverview::mousePressEvent(QMouseEvent* e) {
//qDebug() << "WOverview::mousePressEvent" << e->pos();
mouseMoveEvent(e);
if (m_pCurrentTrack == nullptr) {
double trackSamples = getTrackSamples();
if (m_pCurrentTrack == nullptr || trackSamples <= 0) {
return;
}
if (e->button() == Qt::LeftButton) {
Expand All @@ -503,7 +511,7 @@ void WOverview::mousePressEvent(QMouseEvent* e) {
}

if (m_pHoveredMark != nullptr) {
double dValue = m_pHoveredMark->getSamplePosition() / m_trackSamplesControl->get();
double dValue = m_pHoveredMark->getSamplePosition() / trackSamples;
m_iPickupPos = valueToPosition(dValue);
m_iPlayPos = m_iPickupPos;
setControlParameterUp(dValue);
Expand Down Expand Up @@ -585,11 +593,11 @@ void WOverview::paintEvent(QPaintEvent* pEvent) {
drawEndOfTrackFrame(&painter);
drawAnalyzerProgress(&painter);

double trackSamples = m_trackSamplesControl->get();
if (m_trackLoaded && trackSamples > 0) {
double trackSamples = getTrackSamples();
if (trackSamples > 0) {
const float offset = 1.0f;
const auto gain = static_cast<CSAMPLE_GAIN>(length() - 2) /
static_cast<CSAMPLE_GAIN>(m_trackSamplesControl->get());
static_cast<CSAMPLE_GAIN>(trackSamples);

drawRangeMarks(&painter, offset, gain);
drawMarks(&painter, offset, gain);
Expand Down Expand Up @@ -940,7 +948,7 @@ void WOverview::drawMarks(QPainter* pPainter, const float offset, const float ga
}

double markSamples = pMark->getSamplePosition();
double trackSamples = m_trackSamplesControl->get();
double trackSamples = getTrackSamples();
double currentPositionSamples = m_playpositionControl->get() * trackSamples;
double markTime = samplePositionToSeconds(markSamples);
double markTimeRemaining = samplePositionToSeconds(trackSamples - markSamples);
Expand Down Expand Up @@ -1051,7 +1059,7 @@ void WOverview::drawTimeRuler(QPainter* pPainter) {
textPointDistance.setX(0);
widgetPositionFraction = m_timeRulerPos.y() / height();
}
qreal trackSamples = m_trackSamplesControl->get();
qreal trackSamples = getTrackSamples();
qreal timePosition = samplePositionToSeconds(
widgetPositionFraction * trackSamples);
qreal timePositionTillEnd = samplePositionToSeconds(
Expand Down
8 changes: 7 additions & 1 deletion src/widget/woverview.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ class WOverview : public WWidget, public TrackDropTarget {
}

double getTrackSamples() const {
return m_trackSamplesControl->get();
if (m_trackLoaded) {
return m_trackSamplesControl->get();
} else {
// Ignore the value, because the engine can still have the old track
// during loading
return 0.0;
}
}

QImage m_waveformSourceImage;
Expand Down
6 changes: 5 additions & 1 deletion src/widget/woverviewhsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ bool WOverviewHSV::drawNextPixmapPart() {
// by total_gain
// We keep full range waveform data to scale it on paint
m_waveformSourceImage = QImage(
static_cast<int>(trackSamples / audioVisualRatio / 2),
static_cast<int>(trackSamples / audioVisualRatio / 2) + 1,
2 * 255,
QImage::Format_ARGB32_Premultiplied);
m_waveformSourceImage.fill(QColor(0, 0, 0, 0).value());
if (dataSize / 2 != m_waveformSourceImage.width()) {
qWarning() << "Track duration has changed since last analysis"
<< m_waveformSourceImage.width() << "!=" << dataSize / 2;
}
}
DEBUG_ASSERT(!m_waveformSourceImage.isNull());

Expand Down
6 changes: 5 additions & 1 deletion src/widget/woverviewlmh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ bool WOverviewLMH::drawNextPixmapPart() {
// by total_gain
// We keep full range waveform data to scale it on paint
m_waveformSourceImage = QImage(
static_cast<int>(trackSamples / audioVisualRatio / 2),
static_cast<int>(trackSamples / audioVisualRatio / 2) + 1,
2 * 255,
QImage::Format_ARGB32_Premultiplied);
m_waveformSourceImage.fill(QColor(0, 0, 0, 0).value());
if (dataSize / 2 != m_waveformSourceImage.width()) {
qWarning() << "Track duration has changed since last analysis"
<< m_waveformSourceImage.width() << "!=" << dataSize / 2;
}
}
DEBUG_ASSERT(!m_waveformSourceImage.isNull());

Expand Down
6 changes: 5 additions & 1 deletion src/widget/woverviewrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ bool WOverviewRGB::drawNextPixmapPart() {
// by total_gain
// We keep full range waveform data to scale it on paint
m_waveformSourceImage = QImage(
static_cast<int>(trackSamples / audioVisualRatio / 2),
static_cast<int>(trackSamples / audioVisualRatio / 2) + 1,
2 * 255,
QImage::Format_ARGB32_Premultiplied);
m_waveformSourceImage.fill(QColor(0, 0, 0, 0).value());
if (dataSize / 2 != m_waveformSourceImage.width()) {
qWarning() << "Track duration has changed since last analysis"
<< m_waveformSourceImage.width() << "!=" << dataSize / 2;
}
}
DEBUG_ASSERT(!m_waveformSourceImage.isNull());

Expand Down