Fixes for project duration

parent 9d72b089
......@@ -460,6 +460,14 @@ KdenliveDoc *Core::currentDoc()
return m_projectManager->current();
}
int Core::projectDuration() const
{
if (!m_guiConstructed) {
return 0;
}
return m_mainWindow->getCurrentTimeline()->controller()->duration();
}
void Core::profileChanged()
{
GenTime::setFps(getCurrentFps());
......
......@@ -170,6 +170,8 @@ public:
void showClipKeyframes(ObjectId id, bool enable);
Mlt::Profile *thumbProfile();
void clearSelection();
/** @brief Returns the current project duration */
int projectDuration() const;
private:
explicit Core();
......
......@@ -638,7 +638,7 @@ void GLWidget::refresh()
m_consumer->set("refresh", 1);
}
bool GLWidget::checkFrameNumber(int pos)
bool GLWidget::checkFrameNumber(int pos, int offset)
{
emit seekPosition(pos);
// TODO: cleanup and move logic to proper proxy class
......@@ -656,9 +656,9 @@ bool GLWidget::checkFrameNumber(int pos)
} else {
m_producer->set_speed(speed);
}
} else if (qFuzzyIsNull(speed)) {
} else if (!qFuzzyIsNull(speed)) {
if (m_isLoopMode) {
if (pos >= m_producer->get_int("out") - 1) {
if (pos >= m_producer->get_int("out") - offset) {
m_consumer->purge();
m_producer->seek(m_proxy->zoneIn());
m_producer->set_speed(1.0);
......@@ -666,7 +666,13 @@ bool GLWidget::checkFrameNumber(int pos)
}
return true;
} else {
return pos < m_producer->get_int("out") - 1.;
if (pos >= m_producer->get_int("out") - offset) {
m_consumer->purge();
m_producer->seek(m_producer->get_int("out") - offset);
m_producer->set_speed(0);
return false;
}
return true;
}
} else if (speed < 0. && pos <= 0) {
m_producer->set_speed(0);
......
......@@ -107,7 +107,7 @@ public:
void setAudioThumb(int channels = 0, const QVariantList &audioCache = QList<QVariant>());
int droppedFrames() const;
void resetDrops();
bool checkFrameNumber(int pos);
bool checkFrameNumber(int pos, int offset);
/** @brief Return current timeline position */
int getCurrentPos() const;
/** @brief Requests a monitor refresh */
......
......@@ -1653,11 +1653,9 @@ void Monitor::onFrameDisplayed(const SharedFrame &frame)
{
m_monitorManager->frameDisplayed(frame);
int position = frame.get_position();
if (!m_glMonitor->checkFrameNumber(position)) {
if (!m_glMonitor->checkFrameNumber(position, m_id == Kdenlive::ClipMonitor ? 1 : TimelineModel::seekDuration + 1)) {
m_playAction->setActive(false);
} /* else if (position >= m_length) {
m_playAction->setActive(false);
}*/
}
}
void Monitor::checkDrops(int dropped)
......@@ -2098,7 +2096,11 @@ void Monitor::slotEnd()
{
slotActivateMonitor();
m_glMonitor->switchPlay(false);
m_glMonitor->seek(m_glMonitor->duration());
if (m_id == Kdenlive::ClipMonitor) {
m_glMonitor->seek(m_glMonitor->duration());
} else {
m_glMonitor->seek(pCore->projectDuration());
}
}
void Monitor::addSnapPoint(int pos)
......
......@@ -79,14 +79,14 @@ import QtQuick 2.4
onExited: root.mouseOverRuler = false;
onPressed: {
if (mouse.buttons === Qt.LeftButton) {
controller.requestSeekPosition(mouseX / root.timeScale);
controller.requestSeekPosition(Math.min(mouseX / root.timeScale, root.duration));
}
}
onPositionChanged: {
if (mouse.buttons === Qt.LeftButton) {
root.mouseRulerPos = mouseX
if (pressed) {
controller.requestSeekPosition(mouseX / root.timeScale);
controller.requestSeekPosition(Math.min(mouseX / root.timeScale, root.duration));
}
}
}
......
......@@ -301,7 +301,7 @@ QVariant TimelineItemModel::data(const QModelIndex &index, int role) const
}
case DurationRole:
// qDebug() << "DATA yielding duration" << m_tractor->get_playtime();
return m_tractor->get_playtime();
return getTrackById_const(id)->trackDuration();
case IsMuteRole:
// qDebug() << "DATA yielding mute" << 0;
return getTrackById_const(id)->isMute();
......
......@@ -1507,7 +1507,7 @@ void TimelineModel::updateDuration()
int TimelineModel::duration() const
{
return m_tractor->get_playtime();
return m_tractor->get_playtime() - TimelineModel::seekDuration;
}
std::unordered_set<int> TimelineModel::getGroupElements(int clipId)
......
......@@ -47,7 +47,7 @@ Rectangle {
if (wheel.modifiers & Qt.ControlModifier) {
timeline.setScaleFactor(timeline.scaleFactor + 0.2 * wheel.angleDelta.y / 120);
} else {
var newScroll = Math.min(scrollView.flickableItem.contentX - wheel.angleDelta.y, timeline.duration * root.timeScale - (scrollView.width - scrollView.__verticalScrollBar.width) + root.projectMargin)
var newScroll = Math.min(scrollView.flickableItem.contentX - wheel.angleDelta.y, timeline.fullDuration * root.timeScale - (scrollView.width - scrollView.__verticalScrollBar.width) + root.projectMargin)
scrollView.flickableItem.contentX = Math.max(newScroll, 0)
}
}
......@@ -562,7 +562,7 @@ Rectangle {
acceptedButtons: Qt.RightButton | Qt.LeftButton
cursorShape: tracksArea.mouseY < ruler.height || root.activeTool === 0 ? Qt.ArrowCursor : root.activeTool === 1 ? Qt.IBeamCursor : Qt.SplitHCursor
onWheel: {
timeline.seekPosition = Math.min(timeline.position + (wheel.angleDelta.y > 0 ? 1 : -1), timeline.duration - 1)
timeline.seekPosition = Math.min(timeline.position + (wheel.angleDelta.y > 0 ? 1 : -1), timeline.fullDuration - 1)
timeline.position = timeline.seekPosition
}
onPressed: {
......@@ -593,7 +593,7 @@ Rectangle {
if (mouse.y > ruler.height) {
timeline.selection = []
}
timeline.seekPosition = Math.min((scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor, timeline.duration - 1)
timeline.seekPosition = Math.min((scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor, timeline.fullDuration - 1)
timeline.position = timeline.seekPosition
} else if (root.activeTool === 1) {
// razor tool
......@@ -644,7 +644,7 @@ Rectangle {
}
} else if (mouse.buttons === Qt.LeftButton) {
if (root.activeTool === 0 || mouse.y < ruler.height) {
timeline.seekPosition = Math.min((scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor, timeline.duration - 1)
timeline.seekPosition = Math.min((scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor, timeline.fullDuration - 1)
timeline.position = timeline.seekPosition
} else if (root.activeTool === 2 && spacerGroup > -1) {
// Move group
......@@ -678,7 +678,7 @@ Rectangle {
}
} else if (mouse.modifiers & Qt.ShiftModifier) {
// Shift click, process seek
timeline.seekPosition = Math.min((scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor, timeline.duration - 1)
timeline.seekPosition = Math.min((scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor, timeline.fullDuration - 1)
timeline.position = timeline.seekPosition
}
if (spacerGroup > -1) {
......@@ -701,7 +701,7 @@ Rectangle {
if (parent.mouseX < 50)
timeline.seekPosition = Math.max(0, timeline.position - 10)
else
timeline.seekPosition = Math.min(timeline.position + 10, timeline.duration - 1)
timeline.seekPosition = Math.min(timeline.position + 10, timeline.fullDuration - 1)
}
}
......@@ -717,7 +717,7 @@ Rectangle {
id: ruler
y: 0
x: 0
width: Math.max(root.width - headerWidth, timeline.duration * timeScale + root.projectMargin)
width: Math.max(root.width - headerWidth, timeline.fullDuration * timeScale + root.projectMargin)
Rectangle {
id: seekCursor
visible: timeline.seekPosition > -1
......@@ -746,7 +746,7 @@ Rectangle {
flickableItem.interactive: false
clip: true
Rectangle {
width: Math.max(root.width - headerWidth - scrollView.__verticalScrollBar.width, timeline.duration * timeScale + root.projectMargin)
width: Math.max(root.width - headerWidth - scrollView.__verticalScrollBar.width, timeline.fullDuration * timeScale + root.projectMargin)
height: trackHeaders.height
color: activePalette.window
id: tracksContainerArea
......
......@@ -212,7 +212,7 @@ void TimelineController::setScaleFactorOnMouse(double scale, bool zoomOnMouse)
// Don't allow scaling less than full project's width
scale = (width() - 160.0) / m_duration;
}*/
m_root->setProperty("zoomOnMouse", zoomOnMouse ? qMin(getMousePos(), m_duration - TimelineModel::seekDuration) : -1);
m_root->setProperty("zoomOnMouse", zoomOnMouse ? qMin(getMousePos(), duration()) : -1);
m_scale = scale;
emit scaleFactorChanged();
}
......@@ -232,6 +232,11 @@ int TimelineController::duration() const
return m_duration;
}
int TimelineController::fullDuration() const
{
return m_duration + TimelineModel::seekDuration;
}
void TimelineController::checkDuration()
{
int currentLength = m_model->duration();
......
......@@ -42,6 +42,7 @@ class TimelineController : public QObject
/* @brief holds the current project duration
*/
Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
Q_PROPERTY(int fullDuration READ fullDuration NOTIFY durationChanged)
Q_PROPERTY(bool audioThumbFormat READ audioThumbFormat NOTIFY audioThumbFormatChanged)
/* @brief holds the current timeline position
*/
......@@ -88,6 +89,7 @@ public:
/* @brief Returns the project's duration (tractor)
*/
Q_INVOKABLE int duration() const;
Q_INVOKABLE int fullDuration() const;
/* @brief Returns the current cursor position (frame currently displayed by MLT)
*/
Q_INVOKABLE int position() const { return m_position; }
......
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