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

Improve audio thumbnail offset on clip cut or longer clips.

Related to #973
CCBUG: 423337
parent abc1984d
......@@ -279,6 +279,7 @@ Item {
showItem: audioThumb.visible
format: controller.audioThumbFormat
normalize: controller.audioThumbNormalize
scaleFactor: audioThumb.width / (root.duration - 1) / root.zoomFactor
drawInPoint: 0
drawOutPoint: audioThumb.width
waveInPoint: (root.duration - 1) * root.zoomStart * channels
......
......@@ -7,7 +7,7 @@ import com.enums 1.0
Row {
id: waveform
opacity: clipState == ClipState.Disabled ? 0.2 : 1
property int maxWidth: 500 + 100 * timeline.scaleFactor
property int maxWidth: 500 - (500 % timeline.scaleFactor) + 100 * timeline.scaleFactor
anchors.fill: parent
Timer {
......@@ -47,6 +47,7 @@ Row {
binId: clipRoot.binId
audioStream: clipRoot.audioStream
isFirstChunk: index == 0
scaleFactor: timeline.scaleFactor
showItem: waveform.visible && (index * waveform.maxWidth < (clipRoot.scrollStart + scrollView.width)) && ((index * waveform.maxWidth + width) > clipRoot.scrollStart)
format: timeline.audioThumbFormat
normalize: timeline.audioThumbNormalize
......
......@@ -1078,23 +1078,8 @@ Rectangle {
acceptedButtons: Qt.AllButtons
cursorShape: root.activeTool === 0 ? Qt.ArrowCursor : root.activeTool === 1 ? Qt.IBeamCursor : Qt.SplitHCursor
onWheel: {
if (wheel.modifiers & Qt.AltModifier) {
// Alt + wheel = seek to next snap point
if (wheel.angleDelta.x > 0) {
timeline.triggerAction('monitor_seek_snap_backward')
} else {
timeline.triggerAction('monitor_seek_snap_forward')
}
} else if (wheel.modifiers & Qt.ControlModifier) {
root.wheelAccumulatedDelta += wheel.angleDelta.y;
// Zoom
if (root.wheelAccumulatedDelta >= defaultDeltasPerStep) {
root.zoomIn(true);
root.wheelAccumulatedDelta = 0;
} else if (root.wheelAccumulatedDelta <= -defaultDeltasPerStep) {
root.zoomOut(true);
root.wheelAccumulatedDelta = 0;
}
if (wheel.modifiers & Qt.AltModifier || wheel.modifiers & Qt.ControlModifier || mouseY > trackHeaders.height) {
zoomByWheel(wheel)
} else {
var delta = wheel.modifiers & Qt.ShiftModifier ? timeline.fps() : 1
proxy.position = wheel.angleDelta.y > 0 ? Math.max(root.consumerPosition - delta, 0) : Math.min(root.consumerPosition + delta, timeline.fullDuration - 1)
......@@ -1356,7 +1341,7 @@ Rectangle {
width: root.baseUnit * 1.2
fillColor: activePalette.windowText
anchors.bottom: parent.bottom
x: root.consumerPosition * timeline.scaleFactor - (width / 2)
x: cursor.x - (width / 2)
}
MouseArea {
anchors.fill: parent
......@@ -1665,10 +1650,19 @@ Rectangle {
id: cursor
visible: root.consumerPosition > -1
color: root.textColor
width: Math.max(1, 1 * timeline.scaleFactor)
opacity: (width > 2) ? 0.5 : 1
width: 1
opacity: 1
height: tracksContainerArea.height + subtitleTrack.height
x: root.consumerPosition * timeline.scaleFactor
Rectangle {
color: root.textColor
width: Math.max(0, 1 * timeline.scaleFactor - 1)
visible: width > 1
opacity: 0.2
anchors.left:parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
}
}
}
}
......@@ -1677,12 +1671,21 @@ Rectangle {
id: cutLine
visible: root.activeTool == 1 && tracksArea.mouseY > ruler.height
color: 'red'
width: Math.max(1, 1 * timeline.scaleFactor)
opacity: (width > 2) ? 0.5 : 1
width: 1
opacity: 1
height: tracksContainerArea.height
x: 0
//x: root.consumerPosition * timeline.scaleFactor - scrollView.contentX
y: ruler.height
Rectangle {
color: 'red'
width: Math.max(0, 1 * timeline.scaleFactor - 1)
visible: width > 1
opacity: 0.2
anchors.left:parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
}
}
}
}
......
......@@ -90,6 +90,7 @@ class TimelineWaveform : public QQuickPaintedItem
Q_PROPERTY(int waveOutPoint MEMBER m_outPoint)
Q_PROPERTY(int waveOutPointWithUpdate MEMBER m_outPoint NOTIFY propertyChanged)
Q_PROPERTY(int audioStream MEMBER m_stream)
Q_PROPERTY(double scaleFactor MEMBER m_scale)
Q_PROPERTY(bool format MEMBER m_format NOTIFY propertyChanged)
Q_PROPERTY(bool normalize MEMBER m_normalize NOTIFY propertyChanged)
Q_PROPERTY(bool showItem READ showItem WRITE setShowItem NOTIFY showItemChanged)
......@@ -149,7 +150,7 @@ public:
return;
}
}
qreal indicesPrPixel = qreal(m_outPoint - m_inPoint) / width() * m_precisionFactor;
if (m_outPoint == m_inPoint) {
return;
}
......@@ -157,7 +158,8 @@ public:
pen.setColor(m_color);
painter->setBrush(m_color);
pen.setCapStyle(Qt::FlatCap);
double increment = qMax(1., 1. / qAbs(indicesPrPixel));
double increment = m_scale / 2; //qMax(1., 1. / qAbs(indicesPrPixel));
qreal indicesPrPixel = 2. / m_scale; //qreal(m_outPoint - m_inPoint) / width() * m_precisionFactor;
int h = height();
double offset = 0;
bool pathDraw = increment > 1.2;
......@@ -187,7 +189,7 @@ public:
}
for (; i <= width() && i < m_drawOutPoint; j++) {
i = j * increment;
int idx = ceil((startPos + i) * indicesPrPixel);
int idx = qCeil((startPos + i) * indicesPrPixel);
idx += idx % m_channels;
i -= offset;
if (idx + m_channels >= m_audioLevels.length() || idx < 0) {
......@@ -296,6 +298,7 @@ private:
int m_channels;
int m_precisionFactor;
int m_stream;
double m_scale;
double m_audioMax;
bool m_firstChunk;
};
......
Markdown is supported
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