aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Baptiste Mardelle <[email protected]>2016-05-17 23:28:23 +0200
committerJean-Baptiste Mardelle <[email protected]>2016-05-17 23:28:23 +0200
commit24173546d73294b3bd88f8fd4551ef7ce23970d1 (patch)
treed6aa60749fed9f6ea09549adcf39fbc508faa0ec
parent622f1bbb0214ec4e17c2d4af67ebf7a5a7897271 (diff)
Allow reordering of bin clip effects
-rw-r--r--src/bin/bin.cpp30
-rw-r--r--src/bin/bin.h2
-rw-r--r--src/bin/bincommands.cpp23
-rw-r--r--src/bin/bincommands.h13
-rw-r--r--src/effectstack/effectstackview2.cpp4
-rw-r--r--src/effectstack/effectstackview2.h2
-rw-r--r--src/mainwindow.cpp2
-rw-r--r--src/mltcontroller/clipcontroller.cpp27
-rw-r--r--src/mltcontroller/clipcontroller.h6
9 files changed, 106 insertions, 3 deletions
diff --git a/src/bin/bin.cpp b/src/bin/bin.cpp
index 7d5b184..874d05a 100644
--- a/src/bin/bin.cpp
+++ b/src/bin/bin.cpp
@@ -2216,6 +2216,36 @@ void Bin::slotDeleteEffect(const QString &id, QDomElement effect)
m_doc->commandStack()->push(command);
}
+void Bin::slotMoveEffect(const QString &id, QList <int> currentPos, int newPos)
+{
+ MoveBinEffectCommand *command = new MoveBinEffectCommand(this, id, currentPos, newPos);
+ m_doc->commandStack()->push(command);
+}
+
+void Bin::moveEffect(const QString &id, const QList <int> &oldPos, const QList <int> &newPos)
+{
+ ProjectClip *clip = m_rootFolder->clip(id);
+ if (!clip) return;
+ int new_position = newPos.at(0);
+ ClipController *ctrl = clip->controller();
+ int effectsCount = ctrl->effectsCount();
+ if (new_position > effectsCount) {
+ new_position = effectsCount;
+ }
+ int old_position = oldPos.at(0);
+ for (int i = 0; i < newPos.count(); ++i) {
+ if (old_position > new_position) {
+ // Moving up, we need to adjust index
+ old_position = oldPos.at(i);
+ new_position = newPos.at(i);
+ }
+ ctrl->moveEffect(old_position, new_position);
+ }
+ emit masterClipUpdated(ctrl, m_monitor);
+ m_monitor->refreshMonitorIfActive();
+ ctrl->reloadTrackProducers();
+}
+
void Bin::removeEffect(const QString &id, const QDomElement &effect)
{
if (effect.isNull()) {
diff --git a/src/bin/bin.h b/src/bin/bin.h
index fc09674..9d32c2e 100644
--- a/src/bin/bin.h
+++ b/src/bin/bin.h
@@ -486,6 +486,7 @@ public:
void deleteAllClipMarkers(const QString &id);
/** @brief Remove an effect from a bin clip. */
void removeEffect(const QString &id, const QDomElement &effect);
+ void moveEffect(const QString &id, const QList <int> &oldPos, const QList <int> &newPos);
/** @brief Add an effect to a bin clip. */
void addEffect(const QString &id, QDomElement &effect);
/** @brief Edit an effect settings to a bin clip. */
@@ -611,6 +612,7 @@ public slots:
void slotSaveClipMarkers(const QString &id);
void slotDuplicateClip();
void slotDeleteEffect(const QString &id, QDomElement effect);
+ void slotMoveEffect(const QString &id, QList <int> currentPos, int newPos);
/** @brief Request audio thumbnail for clip with id */
void slotCreateAudioThumb(const QString &id);
/** @brief Abort audio thumbnail for clip with id */
diff --git a/src/bin/bincommands.cpp b/src/bin/bincommands.cpp
index d91ffbb..c3f47ae 100644
--- a/src/bin/bincommands.cpp
+++ b/src/bin/bincommands.cpp
@@ -150,6 +150,29 @@ void RemoveBinEffectCommand::redo()
m_bin->removeEffect(m_clipId, m_effect);
}
+MoveBinEffectCommand::MoveBinEffectCommand(Bin *bin, const QString &clipId, QList <int> oldPos, int newPos, QUndoCommand *parent) :
+ QUndoCommand(parent),
+ m_bin(bin),
+ m_clipId(clipId),
+ m_oldindex(oldPos)
+{
+ for (int i = 0; i < m_oldindex.count(); ++i) {
+ m_newindex << newPos + i;
+ }
+ setText(i18n("Move Bin Effect"));
+}
+
+// virtual
+void MoveBinEffectCommand::undo()
+{
+ m_bin->moveEffect(m_clipId, m_newindex, m_oldindex);
+}
+// virtual
+void MoveBinEffectCommand::redo()
+{
+ m_bin->moveEffect(m_clipId, m_oldindex, m_newindex);
+}
+
RenameBinSubClipCommand::RenameBinSubClipCommand(Bin *bin, const QString &clipId, const QString &newName, const QString &oldName, int in, int out, QUndoCommand *parent) :
QUndoCommand(parent),
m_bin(bin),
diff --git a/src/bin/bincommands.h b/src/bin/bincommands.h
index 65726e8..1d3a9dd 100644
--- a/src/bin/bincommands.h
+++ b/src/bin/bincommands.h
@@ -106,6 +106,19 @@ private:
QDomElement m_effect;
};
+class MoveBinEffectCommand : public QUndoCommand
+{
+public:
+ explicit MoveBinEffectCommand(Bin *bin, const QString &clipId, QList <int> oldPos, int newPos, QUndoCommand *parent = 0);
+ void undo();
+ void redo();
+private:
+ Bin *m_bin;
+ QString m_clipId;
+ QList <int> m_oldindex;
+ QList <int> m_newindex;
+};
+
class RenameBinSubClipCommand : public QUndoCommand
{
public:
diff --git a/src/effectstack/effectstackview2.cpp b/src/effectstack/effectstackview2.cpp
index 63c0255..701b11d 100644
--- a/src/effectstack/effectstackview2.cpp
+++ b/src/effectstack/effectstackview2.cpp
@@ -840,7 +840,7 @@ void EffectStackView2::slotMoveEffectUp(const QList<int> &indexes, bool up)
if (m_status == TIMELINE_TRACK) emit changeEffectPosition(NULL, m_trackindex, indexes, endPos);
else if (m_status == TIMELINE_CLIP) emit changeEffectPosition(m_clipref, -1, indexes, endPos);
else if (m_status == MASTER_CLIP) {
- //TODO
+ emit changeEffectPosition(m_masterclipref->clipId(), indexes, endPos);
}
}
@@ -1086,7 +1086,7 @@ void EffectStackView2::slotMoveEffect(QList <int> currentIndexes, int newIndex,
} else if (m_status == TIMELINE_CLIP) {
emit updateEffect(m_clipref, -1, oldeffect, neweffect, effectToMove->effectIndex(),false);
} else if (m_status == MASTER_CLIP) {
- //TODO
+ //emit updateEffect(m_masterclipref, oldeffect, neweffect, effectToMove->effectIndex(),false);
}
}
}
diff --git a/src/effectstack/effectstackview2.h b/src/effectstack/effectstackview2.h
index e503a2b..310927a 100644
--- a/src/effectstack/effectstackview2.h
+++ b/src/effectstack/effectstackview2.h
@@ -269,6 +269,8 @@ signals:
void changeEffectState(ClipItem*, int, const QList <int>&, bool);
/** An effect in stack was moved */
void changeEffectPosition(ClipItem*, int, const QList <int>&, int);
+ /** An effect in stack was moved for a Bin clip */
+ void changeEffectPosition(const QString &, const QList <int>&, int);
/** an effect was saved, reload list */
void reloadEffects();
/** An effect with position parameter was changed, seek */
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 3c8826c..18467a7 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -298,9 +298,9 @@ MainWindow::MainWindow(const QString &MltPath, const QUrl &Url, const QString &
connect(pCore->bin(), SIGNAL(masterClipUpdated(ClipController *, Monitor *)), m_effectStack, SLOT(slotRefreshMasterClipEffects(ClipController *, Monitor *)));
connect(m_effectStack, SIGNAL(addMasterEffect(QString,QDomElement)), pCore->bin(), SLOT(slotEffectDropped(QString,QDomElement)));
connect(m_effectStack, SIGNAL(removeMasterEffect(QString,QDomElement)), pCore->bin(), SLOT(slotDeleteEffect(QString,QDomElement)));
+ connect(m_effectStack, SIGNAL(changeEffectPosition(QString,const QList <int>,int)), pCore->bin(), SLOT(slotMoveEffect(QString,const QList <int>,int)));
connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
connect(m_effectStack, SIGNAL(displayMessage(QString,int)), this, SLOT(slotGotProgressInfo(QString,int)));
-
m_effectStackDock = addDock(i18n("Properties"), QStringLiteral("effect_stack"), m_effectStack);
m_effectList = new EffectsListView();
diff --git a/src/mltcontroller/clipcontroller.cpp b/src/mltcontroller/clipcontroller.cpp
index abf8258..8083c19 100644
--- a/src/mltcontroller/clipcontroller.cpp
+++ b/src/mltcontroller/clipcontroller.cpp
@@ -656,6 +656,33 @@ EffectsList ClipController::effectList()
return xmlEffectList(m_masterProducer->profile(), m_masterProducer->parent());
}
+void ClipController::moveEffect(int oldPos, int newPos)
+{
+ QMutexLocker lock(&m_effectMutex);
+ Mlt::Service service(m_masterProducer->parent());
+ EffectManager effect(service);
+ effect.moveEffect(oldPos, newPos);
+}
+
+void ClipController::reloadTrackProducers()
+{
+ m_binController->updateTrackProducer(clipId());
+}
+
+int ClipController::effectsCount()
+{
+ int count = 0;
+ Mlt::Service service(m_masterProducer->parent());
+ for (int ix = 0; ix < service.filter_count(); ++ix) {
+ Mlt::Filter *effect = service.filter(ix);
+ QString id = effect->get("kdenlive_id");
+ if (!id.isEmpty()) {
+ count++;
+ }
+ }
+ return count;
+}
+
// static
EffectsList ClipController::xmlEffectList(Mlt::Profile *profile, Mlt::Service &service)
{
diff --git a/src/mltcontroller/clipcontroller.h b/src/mltcontroller/clipcontroller.h
index eff3439..c190ae6 100644
--- a/src/mltcontroller/clipcontroller.h
+++ b/src/mltcontroller/clipcontroller.h
@@ -187,6 +187,12 @@ public:
void disableEffects(bool disable);
/** @brief Create a Kdenlive EffectList xml data from an MLT service */
static EffectsList xmlEffectList(Mlt::Profile *profile, Mlt::Service &service);
+ /** @brief Returns the number of Kdenlive added effects for this bin clip */
+ int effectsCount();
+ /** @brief Move an effect in stack for this bin clip */
+ void moveEffect(int oldPos, int newPos);
+ /** @brief Request an update of all track producers */
+ void reloadTrackProducers();
private:
Mlt::Producer *m_masterProducer;