Skip to content

Commit

Permalink
Synchronize filter view when filters are manipulated by the timeline.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatherly committed Nov 23, 2014
1 parent c9e24ce commit 61c3942
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/controllers/filtercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ FilterController::FilterController(QObject* parent) : QObject(parent),
m_future = QtConcurrent::run(this, &FilterController::loadFilterMetadata);

connect(&m_attachedModel, SIGNAL(changed()), this, SLOT(handleAttachedModelChange()));
connect(&m_attachedModel, SIGNAL(modelAboutToBeReset()), this, SLOT(handleAttachedModelAboutToReset()));
connect(&m_attachedModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), this, SLOT(handleAttachedRowsRemoved(const QModelIndex&,int,int)));
connect(&m_attachedModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(handleAttachedRowsInserted(const QModelIndex&,int,int)));
connect(&m_attachedModel, SIGNAL(duplicateAddFailed(int)), this, SLOT(handleAttachDuplicateFailed(int)));
Expand Down Expand Up @@ -107,9 +108,7 @@ AttachedFiltersModel* FilterController::attachedModel()

void FilterController::setProducer(Mlt::Producer *producer)
{
m_currentFilter.reset(NULL);
m_attachedModel.reset(producer);
setCurrentFilter(-1);
m_attachedModel.setProducer(producer);
}

void FilterController::setCurrentFilter(int attachedIndex)
Expand All @@ -135,6 +134,11 @@ void FilterController::handleAttachedModelChange()
MLT.refreshConsumer();
}

void FilterController::handleAttachedModelAboutToReset()
{
setCurrentFilter(-1);
}

void FilterController::handleAttachedRowsRemoved(const QModelIndex&, int first, int)
{
int newFilterIndex = first;
Expand Down
1 change: 1 addition & 0 deletions src/controllers/filtercontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public slots:

private slots:
void handleAttachedModelChange();
void handleAttachedModelAboutToReset();
void addMetadata(QmlMetadata*);
void handleAttachedRowsRemoved(const QModelIndex & parent, int first, int last);
void handleAttachedRowsInserted(const QModelIndex & parent, int first, int last);
Expand Down
34 changes: 29 additions & 5 deletions src/models/attachedfiltersmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,30 @@ bool AttachedFiltersModel::isReady()
Mlt::Filter* AttachedFiltersModel::getFilter(int row) const
{
Mlt::Filter* result = 0;
if (m_producer && m_producer->is_valid() && row < m_mltIndexMap.count()) {
if (m_producer && m_producer->is_valid() && row < m_mltIndexMap.count() && row >= 0) {
result = m_producer->filter(m_mltIndexMap[row]);
}
return result;
}

QmlMetadata* AttachedFiltersModel::getMetadata(int row) const
{
if (row < m_metaList.count()) {
if (row < m_metaList.count() && row >= 0) {
return m_metaList[row];
}
return NULL;
}

void AttachedFiltersModel::setProducer(Mlt::Producer* producer)
{
if ((!producer && m_producer.isNull()) ||
(producer && !m_producer.isNull() && producer->get_parent() == m_producer->get_parent())) {
// No change
return;
}
reset(producer);
}

int AttachedFiltersModel::rowCount(const QModelIndex &parent) const
{
if (m_producer && m_producer->is_valid())
Expand Down Expand Up @@ -204,7 +214,9 @@ bool AttachedFiltersModel::moveRows(const QModelIndex & sourceParent, int source
}
int mltSrcIndex = m_mltIndexMap[sourceRow];
int mltDstIndex = m_mltIndexMap[destinationRow];
m_event->block();
m_producer->move_filter(mltSrcIndex, mltDstIndex);
m_event->unblock();
// Adjust MLT index map for indices that just changed.
m_mltIndexMap.removeAt(sourceRow);
for (int i = 0; i < m_mltIndexMap.count(); i++) {
Expand Down Expand Up @@ -264,8 +276,10 @@ void AttachedFiltersModel::add(QmlMetadata* meta)

beginInsertRows(QModelIndex(), insertIndex, insertIndex);
MLT.pause();
m_event->block();
m_producer->attach(*filter);
m_producer->move_filter(m_producer->filter_count() - 1, mltIndex);
m_event->unblock();
// Adjust MLT index map for indices that just changed.
for (int i = 0; i < m_mltIndexMap.count(); i++) {
if (m_mltIndexMap[i] >= mltIndex) {
Expand All @@ -291,7 +305,9 @@ void AttachedFiltersModel::remove(int row)
beginRemoveRows(QModelIndex(), row, row);
int mltIndex = m_mltIndexMap[row];
Mlt::Filter* filter = m_producer->filter(mltIndex);
m_event->block();
m_producer->detach(*filter);
m_event->unblock();
// Adjust MLT index map for indices that just changed.
m_mltIndexMap.removeAt(row);
for (int i = 0; i < m_mltIndexMap.count(); i++) {
Expand Down Expand Up @@ -323,14 +339,17 @@ bool AttachedFiltersModel::move(int fromRow, int toRow)

void AttachedFiltersModel::reset(Mlt::Producer* producer)
{
beginResetModel();
if (MLT.isPlaylist()) return;

beginResetModel();
m_event.reset();
m_producer.reset(new Mlt::Producer(producer ? producer : MLT.producer()));
m_metaList.clear();
m_mltIndexMap.clear();

if (MLT.isPlaylist()) return;
if (m_producer && m_producer->is_valid()) {
if (!m_producer.isNull() && m_producer->is_valid()) {
Mlt::Event* event = m_producer->listen("service-changed", this, (mlt_listener)AttachedFiltersModel::producerChanged);
m_event.reset(event);
int count = m_producer->filter_count();
for (int i = 0; i < count; i++) {
Mlt::Filter* filter = m_producer->filter(i);
Expand All @@ -355,3 +374,8 @@ void AttachedFiltersModel::reset(Mlt::Producer* producer)
endResetModel();
emit readyChanged();
}

void AttachedFiltersModel::producerChanged(mlt_properties, AttachedFiltersModel* model)
{
model->reset(model->m_producer.data());
}
7 changes: 6 additions & 1 deletion src/models/attachedfiltersmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QAbstractListModel>
#include <MltFilter.h>
#include <MltProducer.h>
#include <MltEvent.h>

class QmlMetadata;

Expand All @@ -39,6 +40,7 @@ class AttachedFiltersModel : public QAbstractListModel
bool isReady();
Mlt::Filter* getFilter(int row) const;
QmlMetadata* getMetadata(int row) const;
void setProducer(Mlt::Producer* producer = 0);

// QAbstractListModel Implementation
int rowCount(const QModelIndex &parent = QModelIndex()) const;
Expand All @@ -60,12 +62,15 @@ public slots:
void add(QmlMetadata* meta);
void remove(int row);
bool move(int fromRow, int toRow);
void reset(Mlt::Producer *producer = 0);

private:
static void producerChanged(mlt_properties owner, AttachedFiltersModel* model);
void reset(Mlt::Producer *producer = 0);

int m_dropRow;
int m_removeRow;
QScopedPointer<Mlt::Producer> m_producer;
QScopedPointer<Mlt::Event> m_event;
typedef QList<QmlMetadata*> MetadataList;
MetadataList m_metaList;
typedef QList<int> IndexMap;
Expand Down
1 change: 1 addition & 0 deletions src/qml/timeline/Clip.qml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ Rectangle {
parent.anchors.left = undefined
parent.anchors.horizontalCenter = undefined
parent.opacity = 1
trackRoot.clipSelected(clipRoot, trackRoot)
}
onReleased: {
root.stopScrolling = false
Expand Down

0 comments on commit 61c3942

Please sign in to comment.