Commit 0f53fb82 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix audio thumbs of reversed clips.

Related to #1354
parent 06f62538
Pipeline #145050 passed with stage
in 8 minutes and 44 seconds
......@@ -97,8 +97,8 @@ Row {
format: timeline.audioThumbFormat
normalize: timeline.audioThumbNormalize
speed: clipRoot.speed
waveInPoint: clipRoot.speed < 0 ? (Math.round((clipRoot.maxDuration - 1 - clipRoot.inPoint) * Math.abs(clipRoot.speed) - ((index + waveform.offset) * waveform.maxWidth / waveform.timeScale) * Math.abs(clipRoot.speed)) * clipRoot.audioChannels) : (Math.round((clipRoot.inPoint + ((index + waveform.offset) * waveform.maxWidth / waveform.timeScale)) * clipRoot.speed) * clipRoot.audioChannels)
waveOutPoint: clipRoot.speed < 0 ? (waveInPoint - Math.ceil(width / waveform.timeScale * Math.abs(clipRoot.speed)) * clipRoot.audioChannels) : (waveInPoint + Math.round(width / waveform.timeScale * clipRoot.speed) * clipRoot.audioChannels)
waveInPoint: clipRoot.speed < 0 ? (Math.ceil((clipRoot.maxDuration - 1 - clipRoot.inPoint) * Math.abs(clipRoot.speed) - ((index + waveform.offset) * waveform.maxWidth / waveform.timeScale) * Math.abs(clipRoot.speed)) * clipRoot.audioChannels) : (Math.round((clipRoot.inPoint + ((index + waveform.offset) * waveform.maxWidth / waveform.timeScale)) * clipRoot.speed) * clipRoot.audioChannels)
waveOutPoint: clipRoot.speed < 0 ? Math.max(0, (waveInPoint - Math.round(width / waveform.timeScale * Math.abs(clipRoot.speed)) * clipRoot.audioChannels)) : (waveInPoint + Math.round(width / waveform.timeScale * clipRoot.speed) * clipRoot.audioChannels)
fillColor0: clipRoot.color
fillColor1: root.thumbColor1
fillColor2: root.thumbColor2
......
......@@ -163,11 +163,17 @@ public:
if (m_audioMax > 1) {
scaleFactor = m_audioMax;
}
bool reverse = m_speed < 0;
int maxLength = m_audioLevels.length();
if (reverse) {
m_inPoint = qMin(m_inPoint, maxLength - m_channels);
}
int startPos = int(m_inPoint / indicesPrPixel);
if (!KdenliveSettings::displayallchannels()) {
// Draw merged channels
double i = 0;
int j = 0;
int idx = 0;
QPainterPath path;
if (pathDraw) {
path.moveTo(j - 1, height());
......@@ -175,10 +181,15 @@ public:
for (; i <= width(); j++) {
double level;
i = j * increment;
int idx = qCeil((startPos + i) * indicesPrPixel);
idx += idx % m_channels;
if (reverse) {
idx = qCeil((startPos - i) * indicesPrPixel);
idx -= idx % m_channels;
} else {
idx = qCeil((startPos + i) * indicesPrPixel);
idx += idx % m_channels;
}
i -= offset;
if (idx + m_channels >= m_audioLevels.length() || idx < 0) {
if (idx + m_channels >= maxLength || idx < 0) {
break;
}
level = m_audioLevels.at(idx) / scaleFactor;
......@@ -228,13 +239,19 @@ public:
painter->setOpacity(1);
double i = 0;
int j = 0;
int idx = 0;
for (; i <= width(); j++) {
i = j * increment;
int idx = int(ceil((startPos + i) * indicesPrPixel));
idx += idx % m_channels;
if (reverse) {
idx = qCeil((startPos - i) * indicesPrPixel);
idx -= idx % m_channels;
} else {
idx = qCeil((startPos + i) * indicesPrPixel);
idx += idx % m_channels;
}
i -= offset;
idx += channel;
if (idx >= m_audioLevels.length() || idx < 0) break;
if (idx >= maxLength || idx < 0) break;
if (pathDraw) {
level = m_audioLevels.at(idx) * scaleFactor;
path.lineTo(i, y - level);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment