Skip to content

Commit

Permalink
Some filters are limited to a single instance per producer.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatherly committed Nov 18, 2014
1 parent 9d63be6 commit 7f6ebaa
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/controllers/filtercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,24 @@ void FilterController::attachFilter(int metadataIndex)
{
QmlMetadata* meta = m_metadataModel.get(metadataIndex);
QmlFilter* filter = NULL;
if (meta) {
m_currentFilterIndex = m_attachedModel.add(meta);
Mlt::Filter* mltFilter = m_attachedModel.getFilter(m_currentFilterIndex);
filter = new QmlFilter(mltFilter, meta);
filter->setIsNew(true);
} else {
m_currentFilterIndex = -1;

if (!meta) return;

if (meta->allowMultiple() == false) {
for (int i = 0; i < m_attachedModel.rowCount(); i++) {
const QmlMetadata* attachedMeta = m_attachedModel.getMetadata(i);
if (attachedMeta && meta->uniqueId() == attachedMeta->uniqueId()) {
emit errorOccurred(tr("Only one %1 filter is allowed.").arg(meta->name()));
setCurrentFilter(i);
return;
}
}
}

m_currentFilterIndex = m_attachedModel.add(meta);
Mlt::Filter* mltFilter = m_attachedModel.getFilter(m_currentFilterIndex);
filter = new QmlFilter(mltFilter, meta);
filter->setIsNew(true);
emit currentFilterChanged(filter, meta, m_currentFilterIndex);
m_currentFilter.reset(filter);
}
Expand Down
1 change: 1 addition & 0 deletions src/controllers/filtercontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class FilterController : public QObject
signals:
void currentFilterChanged(QmlFilter* filter, QmlMetadata* meta, int index);
void newMetadataFound(QmlMetadata* meta);
void errorOccurred(QString);

public slots:
void setProducer(Mlt::Producer *producer = 0);
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ MainWindow::MainWindow()
connect(this, SIGNAL(producerOpened()), m_filterController, SLOT(setProducer()));
connect(m_filterController->attachedModel(), SIGNAL(changed(bool)), SLOT(setWindowModified(bool)));
connect(m_filterController->attachedModel(), SIGNAL(changed()), SLOT(updateAutoSave()));
connect(m_filterController, SIGNAL(errorOccurred(QString)), this, SLOT(showStatusMessage(QString)));
connect(m_timelineDock, SIGNAL(fadeInChanged(int)), m_filtersDock, SLOT(setFadeInDuration(int)));
connect(m_timelineDock, SIGNAL(fadeOutChanged(int)), m_filtersDock, SLOT(setFadeOutDuration(int)));
connect(m_timelineDock, SIGNAL(trackSelected(Mlt::Producer*)), m_filterController, SLOT(setProducer(Mlt::Producer*)));
Expand Down
8 changes: 8 additions & 0 deletions src/models/attachedfiltersmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ Mlt::Filter* AttachedFiltersModel::getFilter(int row) const
return result;
}

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

int AttachedFiltersModel::rowCount(const QModelIndex &parent) const
{
if (m_producer && m_producer->is_valid())
Expand Down
1 change: 1 addition & 0 deletions src/models/attachedfiltersmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class AttachedFiltersModel : public QAbstractListModel

bool isReady();
Mlt::Filter* getFilter(int row) const;
const QmlMetadata* getMetadata(int row) const;

// QAbstractListModel Implementation
int rowCount(const QModelIndex &parent = QModelIndex()) const;
Expand Down
1 change: 1 addition & 0 deletions src/qml/filters/audio_fadein/meta.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Metadata {
mlt_service: "volume"
qml: "ui.qml"
isFavorite: true
allowMultiple: false
}
1 change: 1 addition & 0 deletions src/qml/filters/audio_fadeout/meta.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Metadata {
mlt_service: "volume"
qml: "ui.qml"
isFavorite: true
allowMultiple: false
}
1 change: 1 addition & 0 deletions src/qml/filters/crop/meta.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Metadata {
mlt_service: "crop"
qml: "ui.qml"
gpuAlt: "crop"
allowMultiple: false
}
1 change: 1 addition & 0 deletions src/qml/filters/crop/meta_movit.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Metadata {
mlt_service: "crop"
needsGPU: true
qml: "ui.qml"
allowMultiple: false
}
1 change: 1 addition & 0 deletions src/qml/filters/fadein_brightness/meta.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Metadata {
qml: "ui.qml"
isFavorite: true
gpuAlt: "movit.opacity"
allowMultiple: false
}
1 change: 1 addition & 0 deletions src/qml/filters/fadein_movit/meta.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Metadata {
needsGPU: true
qml: "ui.qml"
isFavorite: true
allowMultiple: false
}
1 change: 1 addition & 0 deletions src/qml/filters/fadeout_brightness/meta.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Metadata {
qml: "ui.qml"
isFavorite: true
gpuAlt: "movit.opacity"
allowMultiple: false
}
1 change: 1 addition & 0 deletions src/qml/filters/fadeout_movit/meta.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Metadata {
needsGPU: true
qml: "ui.qml"
isFavorite: true
allowMultiple: false
}
1 change: 1 addition & 0 deletions src/qml/filters/size_position/meta_affine.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Metadata {
qml: 'ui_affine.qml'
vui: 'vui_affine.qml'
gpuAlt: 'movit.rect'
allowMultiple: false
}
1 change: 1 addition & 0 deletions src/qml/filters/size_position/meta_movit.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Metadata {
needsGPU: true
qml: 'ui_movit.qml'
vui: 'vui_movit.qml'
allowMultiple: false
}
6 changes: 6 additions & 0 deletions src/qmltypes/qmlmetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ QmlMetadata::QmlMetadata(QObject *parent)
, m_isHidden(false)
, m_isFavorite(false)
, m_gpuAlt("")
, m_allowMultiple(true)
{
}

Expand Down Expand Up @@ -137,3 +138,8 @@ void QmlMetadata::setGpuAlt(const QString& gpuAlt)
m_gpuAlt = gpuAlt;
emit changed();
}

void QmlMetadata::setAllowMultiple(bool allowMultiple)
{
m_allowMultiple = allowMultiple;
}
4 changes: 4 additions & 0 deletions src/qmltypes/qmlmetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class QmlMetadata : public QObject
Q_PROPERTY(bool isHidden READ isHidden WRITE setIsHidden NOTIFY changed)
Q_PROPERTY(bool isFavorite READ isFavorite WRITE setIsFavorite NOTIFY changed)
Q_PROPERTY(QString gpuAlt READ gpuAlt WRITE setGpuAlt NOTIFY changed)
Q_PROPERTY(bool allowMultiple READ allowMultiple WRITE setAllowMultiple)

public:
enum PluginType {
Expand Down Expand Up @@ -76,6 +77,8 @@ class QmlMetadata : public QObject
void setIsFavorite(bool isFavorite);
QString gpuAlt() const { return m_gpuAlt; }
void setGpuAlt(const QString&);
bool allowMultiple() const { return m_allowMultiple; }
void setAllowMultiple(bool allowMultiple);

signals:
void changed();
Expand All @@ -92,6 +95,7 @@ class QmlMetadata : public QObject
bool m_isHidden;
bool m_isFavorite;
QString m_gpuAlt;
bool m_allowMultiple;
};

#endif // QMLMETADATA_H

0 comments on commit 7f6ebaa

Please sign in to comment.