Commit d622fd72 authored by Eric Jiang's avatar Eric Jiang Committed by Jean-Baptiste Mardelle
Browse files

Make monitor zone out be last frame number

This should fix a mismatch in behavior between the monitor and the rest
of Kdenlive. The out frame number should be the last shown frame of a
clip. E.g. in=100, out=200 has 101 frames. Previously, the monitor
treated the out point as the frame number *after* the last shown frame,
causing an off-by-1 bug when taking in/out points from the monitor and
using them in the rest of the program.

Changing the definitions to be consistent across Kdenlive will reduce
the number of places in the code that need a +1 or -1 to adjust the
frame numbers. Note that duration calculations will still need to offset
by 1, e.g. duration = out - in + 1.
parent 28a919ac
Pipeline #205625 passed with stage
in 10 minutes and 7 seconds
......@@ -3730,9 +3730,7 @@ void MainWindow::slotInsertZoneToTree()
}
QPoint info = m_clipMonitor->getZoneInfo();
QString id;
// clip monitor counts the frame after the out point as the zone out, so we
// need to subtract 1 to get the actual last frame
pCore->projectItemModel()->requestAddBinSubClip(id, info.x(), info.y()-1, {}, m_clipMonitor->activeClipId());
pCore->projectItemModel()->requestAddBinSubClip(id, info.x(), info.y(), {}, m_clipMonitor->activeClipId());
}
void MainWindow::slotMonitorRequestRenderFrame(bool request)
......
......@@ -695,7 +695,9 @@ bool GLWidget::checkFrameNumber(int pos, bool isPlaying)
const double speed = m_producer->get_speed();
m_proxy->positionFromConsumer(pos, isPlaying);
if (m_isLoopMode || m_isZoneMode) {
if (isPlaying && pos >= m_loopOut) {
// not sure why we need to check against pos + 1 but otherwise the
// playback shows one frame after the intended out frame
if (isPlaying && pos + 1 >= m_loopOut) {
m_consumer->purge();
if (!m_isLoopMode) {
// end play zone mode
......
......@@ -804,7 +804,7 @@ void Monitor::slotSetZoneStart()
void Monitor::slotSetZoneEnd()
{
QPoint oldZone = m_glMonitor->getControllerProxy()->zone();
int currentOut = m_glMonitor->getCurrentPos() + 1;
int currentOut = m_glMonitor->getCurrentPos();
int updatedZoneIn = -1;
if (currentOut < oldZone.x()) {
updatedZoneIn = qMax(0, currentOut - (oldZone.y() - oldZone.x()));
......@@ -1015,7 +1015,7 @@ void Monitor::slotStartDrag()
QStringList list;
list.append(m_controller->AbstractProjectItem::clipId());
list.append(QString::number(p.x()));
list.append(QString::number(p.y() - 1));
list.append(QString::number(p.y()));
prodData.append(list.join(QLatin1Char('/')).toUtf8());
}
mimeData->setData(QStringLiteral("kdenlive/producerslist"), prodData);
......@@ -1333,7 +1333,7 @@ void Monitor::slotZoneEnd()
if (!slotActivateMonitor()) {
return;
}
m_glMonitor->getControllerProxy()->setPosition(m_glMonitor->getControllerProxy()->zoneOut() - 1);
m_glMonitor->getControllerProxy()->setPosition(m_glMonitor->getControllerProxy()->zoneOut());
}
void Monitor::slotRewind(double speed)
......@@ -1739,7 +1739,7 @@ void Monitor::slotOpenClip(const std::shared_ptr<ProjectClip> &controller, int i
if (out == -1) {
m_glMonitor->getControllerProxy()->setZone(m_controller->zone(), false);
} else {
m_glMonitor->getControllerProxy()->setZone(in, out + 1, false);
m_glMonitor->getControllerProxy()->setZone(in, out, false);
}
m_snaps->addPoint(int(m_controller->frameDuration() - 1));
// Loading new clip / zone, stop if playing
......
......@@ -747,7 +747,7 @@ void MonitorManager::slotSetOutPoint()
} else if (m_activeMonitor == m_projectMonitor) {
QPoint sourceZone = m_projectMonitor->getZoneInfo();
QPoint destZone = sourceZone;
destZone.setY(m_projectMonitor->position() + 1);
destZone.setY(m_projectMonitor->position());
if (destZone.y() < destZone.x()) {
destZone.setX(qMax(0, destZone.y() - (sourceZone.y() - sourceZone.x())));
}
......
......@@ -151,11 +151,11 @@ void MonitorProxy::setZoneIn(int pos)
void MonitorProxy::setZoneOut(int pos)
{
if (m_zoneOut > 0) {
emit removeSnap(m_zoneOut - 1);
emit removeSnap(m_zoneOut);
}
m_zoneOut = pos;
if (pos > 0) {
emit addSnap(m_zoneOut - 1);
emit addSnap(m_zoneOut);
}
emit zoneChanged();
emit saveZone(QPoint(m_zoneIn, m_zoneOut));
......@@ -177,7 +177,7 @@ void MonitorProxy::setZone(int in, int out, bool sendUpdate)
emit removeSnap(m_zoneIn);
}
if (m_zoneOut > 0) {
emit removeSnap(m_zoneOut - 1);
emit removeSnap(m_zoneOut);
}
m_zoneIn = in;
m_zoneOut = out;
......@@ -185,7 +185,7 @@ void MonitorProxy::setZone(int in, int out, bool sendUpdate)
emit addSnap(m_zoneIn);
}
if (m_zoneOut > 0) {
emit addSnap(m_zoneOut - 1);
emit addSnap(m_zoneOut);
}
emit zoneChanged();
if (sendUpdate) {
......
......@@ -506,7 +506,7 @@ Item {
bottom: parent.bottom
bottomMargin: overlayMargin
}
visible: root.showMarkers && controller.position + 1 == controller.zoneOut
visible: root.showMarkers && controller.position == controller.zoneOut
text: i18n("Out Point")
color: "white"
background: Rectangle {
......
......@@ -237,7 +237,7 @@ Item {
bottom: parent.bottom
bottomMargin: root.zoomOffset
}
visible: root.showMarkers && controller.position + 1 == controller.zoneOut
visible: root.showMarkers && controller.position == controller.zoneOut
text: i18n("Out Point")
color: "white"
background: Rectangle {
......
......@@ -1568,13 +1568,13 @@ void TimelineController::setZone(const QPoint &zone, bool withUndo)
m_model->removeSnap(m_zone.x());
}
if (m_zone.y() > 0) {
m_model->removeSnap(m_zone.y() - 1);
m_model->removeSnap(m_zone.y());
}
if (zone.x() > 0) {
m_model->addSnap(zone.x());
}
if (zone.y() > 0) {
m_model->addSnap(zone.y() - 1);
m_model->addSnap(zone.y());
}
updateZone(m_zone, zone, withUndo);
}
......@@ -1623,10 +1623,10 @@ void TimelineController::setZoneIn(int inPoint)
void TimelineController::setZoneOut(int outPoint)
{
if (m_zone.y() > 0) {
m_model->removeSnap(m_zone.y() - 1);
m_model->removeSnap(m_zone.y());
}
if (outPoint > 0) {
m_model->addSnap(outPoint - 1);
m_model->addSnap(outPoint);
}
m_zone.setY(outPoint);
emit zoneChanged();
......@@ -1824,7 +1824,9 @@ void TimelineController::seekToClip(int cid, bool seekToEnd)
{
int start = m_model->getItemPosition(cid);
if (seekToEnd) {
start += m_model->getItemPlaytime(cid);
// -1 because to go to the end of a 10-frame clip,
// need to go from frame 0 to frame 9 (10th frame)
start += m_model->getItemPlaytime(cid) - 1;
}
setPosition(start);
}
......
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