Fix various error corrupting project when changing profile's framerate

CCBUG: 354940
parent 9fe0c652
......@@ -1552,6 +1552,7 @@ void KdenliveDoc::updateProjectProfile()
m_timecode.setFormat(fps);
KdenliveSettings::setCurrent_profile(m_profile.path);
pCore->monitorManager()->resetProfiles(m_profile, m_timecode);
emit updateFps();
}
void KdenliveDoc::resetProfile()
......
......@@ -238,6 +238,8 @@ signals:
void startAutoSave();
/** @brief Current doc created effects, reload list */
void reloadEffects();
/** @brief Fps was changed, update timeline */
void updateFps();
};
#endif
......
......@@ -1662,6 +1662,7 @@ void MainWindow::connectDocument()
connect(m_effectStack->transitionConfig(), SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(seekCursorPos(int)));
connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(slotActivateMonitor()));
connect(project, &KdenliveDoc::updateFps, trackView, &Timeline::updateProjectFps);
connect(trackView, SIGNAL(zoneMoved(int,int)), this, SLOT(slotZoneMoved(int,int)));
trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup, static_cast<QMenu*>(factory()->container(QStringLiteral("marker_menu"), this)));
if (m_renderWidget) {
......
......@@ -1337,7 +1337,7 @@ void Monitor::setCustomProfile(const QString &profile, const Timecode &tc)
m_timePos->updateTimeCode(tc);
if (render == NULL) return;
slotActivateMonitor();
render->prepareProfileReset();
render->prepareProfileReset(tc.fps());
m_glMonitor->resetProfile(ProfilesDialog::getVideoProfile(profile));
}
......@@ -1346,7 +1346,7 @@ void Monitor::resetProfile(MltVideoProfile profile)
m_timePos->updateTimeCode(m_monitorManager->timecode());
if (render == NULL) return;
render->prepareProfileReset();
render->prepareProfileReset(m_monitorManager->timecode().fps());
m_glMonitor->resetProfile(profile);
if (m_rootItem && m_rootItem->objectName() == QLatin1String("rooteffectscene")) {
......
......@@ -153,7 +153,7 @@ Mlt::Producer *Render::invalidProducer(const QString &id)
return clip;
}
void Render::prepareProfileReset()
void Render::prepareProfileReset(double fps)
{
m_refreshTimer.stop();
if (m_isSplitView)
......@@ -162,9 +162,9 @@ void Render::prepareProfileReset()
m_requestList.clear();
m_infoMutex.unlock();
m_infoThread.waitForFinished();
m_fps = fps;
}
void Render::seek(const GenTime &time)
{
if (!m_mltProducer || !m_isActive)
......
......@@ -301,7 +301,7 @@ class Render: public AbstractRender
const QString getBinProperty(const QString &name);
void setVolume(double volume);
/** @brief Stop all activities in preparation for a change in profile */
void prepareProfileReset();
void prepareProfileReset(double fps);
void updateSlowMotionProducers(const QString &id, QMap <QString, QString> passProperties);
static QMap<QString, QString> mltGetTransitionParamsFromXml(const QDomElement &xml);
/** @brief Make sure to close running threads before closing document */
......
......@@ -100,6 +100,7 @@ void CustomRuler::updateProjectFps(const Timecode &t)
m_timecode = t;
mediumMarkDistance = FRAME_SIZE * m_timecode.fps();
bigMarkDistance = FRAME_SIZE * m_timecode.fps() * 60;
setPixelPerMark(m_rate);
update();
}
......
......@@ -255,7 +255,7 @@ int Timeline::getTracks() {
frame->setFrameStyle(QFrame::HLine);
frame->setFixedHeight(1);
headerLayout->insertWidget(0, frame);
Track *tk = new Track(i, m_trackActions, playlist, audio == 1 ? AudioTrack : VideoTrack, m_doc->fps(), this);
Track *tk = new Track(i, m_trackActions, playlist, audio == 1 ? AudioTrack : VideoTrack, this);
m_tracks.append(tk);
if (audio == 0 && !isBackgroundBlackTrack) {
// Check if we have a composite transition for this track
......@@ -1121,8 +1121,11 @@ void Timeline::slotVerticalZoomUp()
void Timeline::updateProjectFps()
{
qDebug()<<"Requesting FPS UPDATE: "<<m_doc->timecode().fps();
m_ruler->updateFrameSize();
m_ruler->updateProjectFps(m_doc->timecode());
m_trackview->updateProjectFps();
slotChangeZoom(m_doc->zoom().x(), m_doc->zoom().y());
}
void Timeline::slotRenameTrack(int ix, const QString &name)
......
......@@ -64,7 +64,6 @@ public:
int duration() const;
KdenliveDoc *document();
void refresh() ;
void updateProjectFps();
int outPoint() const;
int inPoint() const;
int fitZoom() const;
......@@ -157,6 +156,7 @@ public slots:
void slotSaveTimelinePreview(const QString &path);
void checkDuration(int duration);
void slotShowTrackEffects(int);
void updateProjectFps();
private:
Mlt::Tractor *m_tractor;
......
......@@ -28,13 +28,12 @@
#include <QDebug>
#include <math.h>
Track::Track(int index, const QList<QAction *> &actions, Mlt::Playlist &playlist, TrackType type, qreal fps, QWidget *parent) :
Track::Track(int index, const QList<QAction *> &actions, Mlt::Playlist &playlist, TrackType type, QWidget *parent) :
effectsList(EffectsList(true)),
type(type),
trackHeader(NULL),
m_index(index),
m_playlist(playlist),
m_fps(fps)
m_playlist(playlist)
{
QString playlist_name = playlist.get("id");
if (playlist_name != "black_track") {
......@@ -62,21 +61,16 @@ void Track::setPlaylist(Mlt::Playlist &playlist)
qreal Track::fps()
{
return m_fps;
return m_playlist.get_fps();
}
int Track::frame(qreal t)
{
return round(t * m_fps);
return round(t * fps());
}
qreal Track::length() {
return m_playlist.get_playtime() / m_fps;
}
void Track::setFps(qreal fps)
{
m_fps = fps;
return m_playlist.get_playtime() / fps();
}
// basic clip operations
......@@ -602,7 +596,7 @@ void Track::updateClipProperties(const QString &id, QMap <QString, QString> prop
int Track::changeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, PlaylistState::ClipState state, double speed, int strobe, Mlt::Producer *prod, Mlt::Properties passProps, bool removeEffect)
{
int newLength = 0;
int startPos = info.startPos.frames(m_fps);
int startPos = info.startPos.frames(fps());
int clipIndex = m_playlist.get_clip_index_at(startPos);
int clipLength = m_playlist.clip_length(clipIndex);
......@@ -680,9 +674,9 @@ int Track::changeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, Playlis
int blankEnd = m_playlist.clip_start(clipIndex) + m_playlist.clip_length(clipIndex);
Mlt::Producer *cut;
if (clipIndex + 1 < m_playlist.count() && (startPos + clipLength / speed > blankEnd)) {
GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
cut = prod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
} else cut = prod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
GenTime maxLength = GenTime(blankEnd, fps()) - info.startPos;
cut = prod->cut((int)(info.cropStart.frames(fps()) / speed), (int)(info.cropStart.frames(fps()) / speed + maxLength.frames(fps()) - 1));
} else cut = prod->cut((int)(info.cropStart.frames(fps()) / speed), (int)((info.cropStart.frames(fps()) + clipLength) / speed - 1));
// move all effects to the correct producer
Clip(*cut).addEffects(*clip);
......@@ -718,12 +712,12 @@ int Track::changeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, Playlis
emit storeSlowMotion(url, prod);
}
int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
if (clipIndex + 1 < m_playlist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
int originalStart = (int)(speedIndependantInfo.cropStart.frames(fps()));
if (clipIndex + 1 < m_playlist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(fps()) > blankEnd) {
GenTime maxLength = GenTime(blankEnd, fps()) - info.startPos;
cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(fps()) - 1));
} else {
cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(fps())) - 1);
}
// move all effects to the correct producer
......@@ -760,21 +754,21 @@ int Track::changeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, Playlis
int duration;
int originalStart;
if (speed == 1.0) {
duration = speedIndependantInfo.cropDuration.frames(m_fps);
originalStart = speedIndependantInfo.cropStart.frames(m_fps);
duration = speedIndependantInfo.cropDuration.frames(fps());
originalStart = speedIndependantInfo.cropStart.frames(fps());
} else {
duration = (int) (speedIndependantInfo.cropDuration.frames(m_fps) / speed + 0.5);
originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed + 0.5);
duration = (int) (speedIndependantInfo.cropDuration.frames(fps()) / speed + 0.5);
originalStart = (int)(speedIndependantInfo.cropStart.frames(fps()) / speed + 0.5);
}
qDebug()<<"/ / /UPDATE SPEED: "<<speed<<", "<<speedIndependantInfo.cropStart.frames(m_fps)<<":"<<originalStart;
qDebug()<<"/ / /UPDATE SPEED: "<<speed<<", "<<speedIndependantInfo.cropStart.frames(fps())<<":"<<originalStart;
// Check that the blank space is long enough for our new duration
clipIndex = m_playlist.get_clip_index_at(startPos);
int blankEnd = m_playlist.clip_start(clipIndex) + m_playlist.clip_length(clipIndex);
Mlt::Producer *cut;
if (clipIndex + 1 < m_playlist.count() && (startPos + duration > blankEnd)) {
GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
GenTime maxLength = GenTime(blankEnd, fps()) - info.startPos;
cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(fps()) - 1));
} else {
cut = prod->cut(originalStart, originalStart + duration - 1);
}
......
......@@ -47,13 +47,12 @@ class Track : public QObject
{
Q_OBJECT
Q_PROPERTY(Mlt::Playlist playlist READ playlist WRITE setPlaylist)
Q_PROPERTY(qreal fps READ fps WRITE setFps)
public:
/** @brief Track constructor
* @param playlist is the MLT object used for monitor/render
* @param fps is the read speed (frames per seconds) */
explicit Track(int index, const QList<QAction *> &actions, Mlt::Playlist &playlist, TrackType type, qreal fps, QWidget *parent = 0);
explicit Track(int index, const QList<QAction *> &actions, Mlt::Playlist &playlist, TrackType type, QWidget *parent = 0);
~Track();
/// Property access function
......@@ -177,7 +176,6 @@ public:
public Q_SLOTS:
void setPlaylist(Mlt::Playlist &playlist);
void setFps(qreal fps);
signals:
/** @brief notify track length change to update background
......
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