More clever monitor refresh / timeline preview invalidate on timeline operations

parent 265281b7
......@@ -222,7 +222,7 @@ public:
bool contains(GenTime pos) const {
if (startPos == endPos)
return true;
return (pos < endPos && pos > startPos);
return (pos <= endPos && pos >= startPos);
}
bool operator==(const ItemInfo &a)
{
......
......@@ -1935,3 +1935,8 @@ void ClipItem::updateKeyframes(QDomElement effect)
}
m_keyframeView.loadKeyframes(locale, e, cropStart().frames(m_fps), cropDuration().frames(m_fps));
}
bool ClipItem::hasVisibleVideo() const
{
return (m_clipType != Audio && m_clipState != PlaylistState::AudioOnly && m_clipState != PlaylistState::Disabled);
}
......@@ -188,12 +188,14 @@ public:
/** @brief Returns true of this clip needs a duplicate (MLT requires duplicate for clips with audio or we get clicks. */
bool needsDuplicate() const;
/** @brief Returns true of this has audio. */
/** @brief Returns true if this has audio. */
bool isSplittable() const;
/** @brief Returns some info useful for recreating this clip. */
PlaylistState::ClipState clipState() const;
PlaylistState::ClipState originalState() const;
/** @brief Returns true if this clip is currently displaying video. */
bool hasVisibleVideo() const;
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
......
This diff is collapsed.
......@@ -210,6 +210,7 @@ public:
int seekPosition() const;
/** @brief Trigger a monitor refresh. */
void monitorRefresh(QList <ItemInfo> range, bool invalidateRange = false);
void monitorRefresh(bool invalidateRange = false);
/** @brief Trigger a monitor refresh if timeline cursor is inside range. */
void monitorRefresh(ItemInfo range, bool invalidateRange = false);
......
......@@ -319,7 +319,6 @@ int Timeline::getTracks() {
}
connect(tk, &Track::newTrackDuration, this, &Timeline::checkDuration, Qt::DirectConnection);
connect(tk, SIGNAL(storeSlowMotion(QString,Mlt::Producer *)), m_doc->renderer(), SLOT(storeSlowmotionProducer(QString,Mlt::Producer *)));
connect(tk, &Track::invalidatePreview, this, &Timeline::invalidatePreview);
}
}
headers_container->setFixedWidth(headerWidth);
......
......@@ -62,7 +62,7 @@ void AddEffectCommand::redo()
m_view->deleteEffect(m_track, m_pos, m_effect);
}
AddTimelineClipCommand::AddTimelineClipCommand(CustomTrackView *view, const QString &clipId, const ItemInfo &info, const EffectsList &effects, PlaylistState::ClipState state, bool doIt, bool doRemove, QUndoCommand * parent) :
AddTimelineClipCommand::AddTimelineClipCommand(CustomTrackView *view, const QString &clipId, const ItemInfo &info, const EffectsList &effects, PlaylistState::ClipState state, bool doIt, bool doRemove, bool refreshMonitor, QUndoCommand * parent) :
QUndoCommand(parent),
m_view(view),
m_clipId(clipId),
......@@ -70,7 +70,8 @@ AddTimelineClipCommand::AddTimelineClipCommand(CustomTrackView *view, const QStr
m_effects(effects),
m_state(state),
m_doIt(doIt),
m_remove(doRemove)
m_remove(doRemove),
m_refresh(refreshMonitor)
{
if (!m_remove) setText(i18n("Add timeline clip"));
else setText(i18n("Delete timeline clip"));
......@@ -720,7 +721,7 @@ void RebuildGroupCommand::redo()
m_view->rebuildGroup(m_childTrack, m_childPos);
}
RefreshMonitorCommand::RefreshMonitorCommand(CustomTrackView *view, ItemInfo info, bool execute, bool refreshOnUndo, QUndoCommand * parent) :
RefreshMonitorCommand::RefreshMonitorCommand(CustomTrackView *view, QList <ItemInfo> info, bool execute, bool refreshOnUndo, QUndoCommand * parent) :
QUndoCommand(parent),
m_view(view),
m_info(info),
......@@ -728,20 +729,36 @@ RefreshMonitorCommand::RefreshMonitorCommand(CustomTrackView *view, ItemInfo inf
m_execOnUndo(refreshOnUndo)
{
}
RefreshMonitorCommand::RefreshMonitorCommand(CustomTrackView *view, ItemInfo info, bool execute, bool refreshOnUndo, QUndoCommand * parent) :
QUndoCommand(parent),
m_view(view),
m_info(QList <ItemInfo>() << info),
m_exec(execute),
m_execOnUndo(refreshOnUndo)
{
}
// virtual
void RefreshMonitorCommand::undo()
{
if (m_execOnUndo)
m_view->monitorRefresh(m_info);
m_view->monitorRefresh(m_info, true);
}
// virtual
void RefreshMonitorCommand::redo()
{
if (m_exec && !m_execOnUndo)
m_view->monitorRefresh(m_info);
m_view->monitorRefresh(m_info, true);
m_exec = true;
}
void RefreshMonitorCommand::updateRange(QList <ItemInfo> info)
{
m_info.clear();
m_info = info;
}
ResizeClipCommand::ResizeClipCommand(CustomTrackView *view, const ItemInfo &start, const ItemInfo &end, bool doIt, bool dontWorry, QUndoCommand * parent) :
QUndoCommand(parent),
m_view(view),
......
......@@ -49,7 +49,19 @@ private:
class AddTimelineClipCommand : public QUndoCommand
{
public:
AddTimelineClipCommand(CustomTrackView *view, const QString &clipId, const ItemInfo &info, const EffectsList &effects, PlaylistState::ClipState state, bool doIt, bool doRemove, QUndoCommand * parent = 0);
/** @brief Add clip in timeline.
* @param view The parent view
* @param clipId The Bin clip id
* @param info The position where to add clip
* @param effects the clip's effectStack
* @param state the clip's playlist state
* @param doIt whether to execute command on first run
* @param doRemove Should the clip be deleted or added on execute
* @param refreshMonitor Should the monitor be refreshed on execute (false if this command is in a group and
* refresh is executed separately
* @param parent The parent command
* */
AddTimelineClipCommand(CustomTrackView *view, const QString &clipId, const ItemInfo &info, const EffectsList &effects, PlaylistState::ClipState state, bool doIt, bool doRemove, bool refreshMonitor, QUndoCommand * parent = 0);
void undo();
void redo();
private:
......@@ -60,6 +72,7 @@ private:
PlaylistState::ClipState m_state;
bool m_doIt;
bool m_remove;
bool m_refresh;
};
class AddTrackCommand : public QUndoCommand
......@@ -385,12 +398,14 @@ private:
class RefreshMonitorCommand : public QUndoCommand
{
public:
RefreshMonitorCommand(CustomTrackView *view, QList <ItemInfo> info, bool execute, bool refreshOnUndo, QUndoCommand * parent = 0);
RefreshMonitorCommand(CustomTrackView *view, ItemInfo info, bool execute, bool refreshOnUndo, QUndoCommand * parent = 0);
void undo();
void redo();
void updateRange(QList <ItemInfo> info);
private:
CustomTrackView *m_view;
ItemInfo m_info;
QList <ItemInfo> m_info;
bool m_exec;
bool m_execOnUndo;
};
......
......@@ -116,8 +116,6 @@ bool Track::doAdd(qreal t, Mlt::Producer *cut, TimelineMode::EditMode mode)
if (m_playlist.insert_at(pos, cut, 1) == m_playlist.count() - 1) {
emit newTrackDuration(m_playlist.get_playtime());
}
if (type != AudioTrack)
emit invalidatePreview(pos, len);
return true;
}
......@@ -146,8 +144,6 @@ bool Track::move(qreal start, qreal end, TimelineMode::EditMode mode)
if (durationChanged) {
emit newTrackDuration(m_playlist.get_playtime());
}
if (type != AudioTrack)
emit invalidatePreview(pos, clipProducer->get_playtime());
return result;
}
......@@ -169,10 +165,8 @@ bool Track::del(qreal t)
if (ix == m_playlist.count() - 1) {
durationChanged = true;
}
int length = 0;
Mlt::Producer *clip = m_playlist.replace_with_blank(ix);
if (clip) {
length = clip->get_playtime();
delete clip;
}
else {
......@@ -185,8 +179,6 @@ bool Track::del(qreal t)
if (durationChanged) {
emit newTrackDuration(m_playlist.get_playtime());
}
if (type != AudioTrack)
emit invalidatePreview(pos, length);
return true;
}
......@@ -196,8 +188,6 @@ bool Track::del(qreal t, qreal dt)
m_playlist.insert_blank(m_playlist.remove_region(frame(t), frame(dt) + 1), frame(dt));
m_playlist.consolidate_blanks();
m_playlist.unlock();
if (type != AudioTrack)
emit invalidatePreview(frame(t), frame(dt));
return true;
}
......@@ -207,7 +197,6 @@ bool Track::resize(qreal t, qreal dt, bool end)
int startFrame = frame(t);
int index = m_playlist.get_clip_index_at(startFrame);
int length = frame(dt);
int updateLength = length;
QScopedPointer<Mlt::Producer> clip(m_playlist.get_clip(index));
if (clip == NULL || clip->is_blank()) {
qWarning("Can't resize clip at %f", t);
......@@ -246,12 +235,6 @@ bool Track::resize(qreal t, qreal dt, bool end)
m_playlist.unlock();
// this is the last clip in track, check tracks length to adjust black track and project duration
emit newTrackDuration(m_playlist.get_playtime());
if (type != AudioTrack) {
if (updateLength > 0)
emit invalidatePreview(startFrame, updateLength);
else
emit invalidatePreview(startFrame + updateLength, -updateLength);
}
return true;
}
length = -length;
......@@ -277,12 +260,6 @@ bool Track::resize(qreal t, qreal dt, bool end)
m_playlist.consolidate_blanks();
m_playlist.unlock();
if (type != AudioTrack) {
if (updateLength > 0)
emit invalidatePreview(startFrame, updateLength);
else
emit invalidatePreview(startFrame + updateLength, -updateLength);
}
return true;
}
......@@ -366,7 +343,6 @@ bool Track::replaceAll(const QString &id, Mlt::Producer *original, Mlt::Producer
QString service = original->parent().get("mlt_service");
QString idForTrack = original->parent().get("id");
QLocale locale;
QList <QPoint> updateList;
if (needsDuplicate(service)) {
// We have to use the track clip duplication functions, because of audio glitches in MLT's multitrack
idForAudioTrack = idForTrack + QLatin1Char('_') + m_playlist.get("id") + "_audio";
......@@ -385,9 +361,6 @@ bool Track::replaceAll(const QString &id, Mlt::Producer *original, Mlt::Producer
}
current.remove(0, 1);
Mlt::Producer *cut = NULL;
if (type != AudioTrack) {
updateList << QPoint(m_playlist.clip_start(i), m_playlist.clip_length(i));
}
if (current.startsWith("slowmotion:" + id + ":")) {
// Slowmotion producer, just update resource
Mlt::Producer *slowProd = newSlowMos.value(current.section(QStringLiteral(":"), 2));
......@@ -436,9 +409,6 @@ bool Track::replaceAll(const QString &id, Mlt::Producer *original, Mlt::Producer
delete cut;
}
}
foreach(const QPoint &pt, updateList) {
emit invalidatePreview(pt.x(), pt.y());
}
return found;
}
......@@ -468,8 +438,6 @@ bool Track::replace(qreal t, Mlt::Producer *prod, PlaylistState::ClipState state
bool ok = m_playlist.insert_at(frame(t), cut, 1) >= 0;
delete cut;
m_playlist.unlock();
if (type != AudioTrack)
emit invalidatePreview(frame(t), orig->get_playtime());
return ok;
}
......@@ -479,7 +447,6 @@ void Track::updateEffects(const QString &id, Mlt::Producer *original)
QString idForVideoTrack;
QString service = original->parent().get("mlt_service");
QString idForTrack = original->parent().get("id");
QList <QPoint> updateList;
if (needsDuplicate(service)) {
// We have to use the track clip duplication functions, because of audio glitches in MLT's multitrack
idForAudioTrack = idForTrack + QLatin1Char('_') + m_playlist.get("id") + "_audio";
......@@ -495,24 +462,16 @@ void Track::updateEffects(const QString &id, Mlt::Producer *original)
if (current.startsWith(QLatin1String("slowmotion:"))) {
if (current.section(QStringLiteral(":"), 1, 1) == id) {
Clip(origin).replaceEffects(*original);
updateList << QPoint(m_playlist.clip_start(i), m_playlist.clip_length(i));
}
}
else if (current == id) {
// we are directly using original producer, no need to update effects
updateList << QPoint(m_playlist.clip_start(i), m_playlist.clip_length(i));
continue;
}
else if (current.section(QStringLiteral("_"), 0, 0) == id) {
updateList << QPoint(m_playlist.clip_start(i), m_playlist.clip_length(i));
Clip(origin).replaceEffects(*original);
}
}
if (type != AudioTrack) {
foreach(const QPoint &pt, updateList) {
emit invalidatePreview(pt.x(), pt.y());
}
}
}
/*Mlt::Producer &Track::find(const QByteArray &name, const QByteArray &value, int startindex) {
......
......@@ -211,7 +211,6 @@ signals:
* @param duration is the new length */
void newTrackDuration(int duration);
void storeSlowMotion(const QString &url, Mlt::Producer *prod);
void invalidatePreview(int position, int length);
private:
/** Position in MLT's tractor */
......
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