bool EffectManager::enableEffects(const QList <int> &effectIndexes, bool disable, bool rememberState) { int ct = 0; bool success = false; Mlt::Filter *filter = m_producer.filter(ct); while (filter) { if (effectIndexes.isEmpty() || effectIndexes.contains(filter->get_int("kdenlive_ix"))) { //m_producer.lock(); if (rememberState) { if (disable && filter->get_int("disable") == 0) { filter->set("auto_disable", 1); filter->set("disable", (int) disable); } else if (!disable && filter->get_int("auto_disable") == 1) { filter->set("disable", (char*) NULL); filter->set("auto_disable", (char*) NULL); } } else { filter->set("disable", (int) disable); } success = true; //m_producer.unlock(); } delete filter; ct++; filter = m_producer.filter(ct); } return success; }
Frei0rColoradjWidget::Frei0rColoradjWidget(Mlt::Filter filter, bool setDefaults, QWidget *parent) : QWidget(parent), ui(new Ui::Frei0rColoradjWidget), m_filter(filter) { ui->setupUi(this); ui->keepLumaCheckBox->hide(); m_defaultAction = 0.5; m_defaultLuma = false; m_defaultRGB = QColor::fromRgbF(0.5, 0.5, 0.5); if (setDefaults) { ui->modeComboBox->setCurrentIndex(2 * m_defaultAction); ui->keepLumaCheckBox->setChecked(m_defaultLuma); ui->wheel->setColor(m_defaultRGB); m_filter.set(kParamAction, m_defaultAction); m_filter.set(kParamKeepLuma, m_defaultLuma? 1 : 0); m_filter.set(kParamRed, m_defaultRGB.redF()); m_filter.set(kParamGreen, m_defaultRGB.greenF()); m_filter.set(kParamBlue, m_defaultRGB.blueF()); ui->preset->saveDefaultPreset(m_filter); } else { ui->modeComboBox->setCurrentIndex(2 * filter.get_double(kParamAction)); ui->keepLumaCheckBox->setChecked(filter.get_int(kParamKeepLuma)); ui->wheel->setColor(QColor::fromRgbF(filter.get_double(kParamRed), filter.get_double(kParamGreen), filter.get_double(kParamBlue))); } ui->preset->loadPresets(); m_filter.set(kParamLumaFormula, (MLT.profile().colorspace() == 709? kLumaFormula709 : kLumaFormula601)); }
QVariant AttachedFiltersModel::data(const QModelIndex &index, int role) const { if ( !m_producer || !m_producer->is_valid() || index.row() >= m_producer->filter_count()) return QVariant(); switch (role ) { case Qt::DisplayRole: { QVariant result; Mlt::Filter* filter = filterForRow(index.row()); if (filter && filter->is_valid()) { // Relabel by QML UI QmlMetadata* meta = MAIN.filtersDock()->qmlMetadataForService(filter); if (meta) result = meta->name(); // Fallback is raw mlt_service name else if (filter->get("mlt_service")) result = QString::fromUtf8(filter->get("mlt_service")); } // Relabel for widgets UIs if (result == "movit.blur" || result == "boxblur") result = tr("Blur"); else if (result == "movit.lift_gamma_gain" || result == "frei0r.coloradj_RGB") result = tr("Color Grading"); else if (result == "crop") result = tr("Crop"); else if (result == "movit.glow" || result == "frei0r.glow") result = tr("Glow"); else if (result == "movit.mirror" || result == "mirror") result = tr("Mirror"); else if (result == "webvfx") result = tr("Overlay HTML"); else if (result == "movit.sharpen" || result == "frei0r.sharpness") result = tr("Sharpen"); else if (result == "movit.white_balance" || result == "frei0r.colgate") result = tr("White Balance"); else if (result == "sox" && filter->get("use_peak")) result = tr("Normalize"); delete filter; return result; } case Qt::CheckStateRole: { Mlt::Filter* filter = filterForRow(index.row()); QVariant result = Qt::Unchecked; if (filter && filter->is_valid() && !filter->get_int("disable")) result = Qt::Checked; delete filter; return result; } break; default: break; } return QVariant(); }
bool EffectManager::moveEffect(int oldPos, int newPos) { int ct = 0; QList <Mlt::Filter *> filtersList; QList <Mlt::Filter *> toDelete; Mlt::Filter *filter = m_producer.filter(ct); if (newPos > oldPos) { bool found = false; while (filter) { toDelete << filter; if (!found && filter->get_int("kdenlive_ix") == oldPos) { filter->set("kdenlive_ix", newPos); filtersList.append(filter); m_producer.detach(*filter); filter = m_producer.filter(ct); while (filter && filter->get_int("kdenlive_ix") <= newPos) { filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1); ct++; filter = m_producer.filter(ct); } found = true; } if (filter && filter->get_int("kdenlive_ix") > newPos) { filtersList.append(filter); m_producer.detach(*filter); } else ct++; filter = m_producer.filter(ct); } } else { while (filter) { toDelete << filter; if (filter->get_int("kdenlive_ix") == oldPos) { filter->set("kdenlive_ix", newPos); filtersList.append(filter); m_producer.detach(*filter); } else ct++; filter = m_producer.filter(ct); } ct = 0; filter = m_producer.filter(ct); while (filter) { toDelete << filter; int pos = filter->get_int("kdenlive_ix"); if (pos >= newPos) { if (pos < oldPos) filter->set("kdenlive_ix", pos + 1); filtersList.append(filter); m_producer.detach(*filter); } else ct++; filter = m_producer.filter(ct); } } for (int i = 0; i < filtersList.count(); ++i) { m_producer.attach(*(filtersList.at(i))); } qDeleteAll(toDelete); //TODO: check for success return true; }
bool AttachedFiltersModel::setData(const QModelIndex& index, const QVariant& , int role) { if (role == Qt::CheckStateRole) { Mlt::Filter* filter = getFilter(index.row()); if (filter && filter->is_valid()) { filter->set("disable", !filter->get_int("disable")); emit changed(); emit dataChanged(createIndex(index.row(), 0), createIndex(index.row(), 0)); } delete filter; return true; } return false; }
void AttachedFiltersModel::calculateRows() { m_rows =-0; if (MLT.isPlaylist()) return; if (m_producer && m_producer->is_valid()) { int n = m_producer->filter_count(); while (n--) { Mlt::Filter* filter = m_producer->filter(n); if (filter && filter->is_valid() && !filter->get_int("_loader")) m_rows++; delete filter; } } }
bool EffectManager::removeEffect(int effectIndex, bool updateIndex) { m_producer.lock(); int ct = 0; bool success = false; Mlt::Filter *filter = m_producer.filter(ct); QList <Mlt::Filter *> filters; while (filter) { filters << filter; if ((effectIndex == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == effectIndex) { if (m_producer.detach(*filter) == 0) { success = true; } } else if (updateIndex) { // Adjust the other effects index if (filter->get_int("kdenlive_ix") > effectIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1); ct++; } else ct++; filter = m_producer.filter(ct); } m_producer.unlock(); qDeleteAll(filters); return success; }
QVariant AttachedFiltersModel::data(const QModelIndex &index, int role) const { if ( !m_producer || !m_producer->is_valid() || index.row() >= m_producer->filter_count()) return QVariant(); switch (role ) { case Qt::DisplayRole: { QVariant result; const QmlMetadata* meta = m_metaList[index.row()]; if (meta) { result = meta->name(); } else { // Fallback is raw mlt_service name Mlt::Filter* filter = getFilter(index.row()); if (filter && filter->is_valid() && filter->get("mlt_service")) { result = QString::fromUtf8(filter->get("mlt_service")); } delete filter; } return result; } case Qt::CheckStateRole: { Mlt::Filter* filter = getFilter(index.row()); QVariant result = Qt::Unchecked; if (filter && filter->is_valid() && !filter->get_int("disable")) result = Qt::Checked; delete filter; return result; } break; case TypeDisplayRole: { QVariant result; const QmlMetadata* meta = m_metaList[index.row()]; if (meta && meta->isAudio()) { result = tr("Audio"); } else if (meta && meta->needsGPU()) { result = tr("GPU"); } else { result = tr("Video"); } return result; } break; default: break; } return QVariant(); }
bool AttachedFiltersModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (role == Qt::CheckStateRole) { Mlt::Filter* filter = filterForRow(index.row()); if (filter && filter->is_valid()) { double speed = MLT.producer()->get_speed(); MLT.pause(); filter->set("disable", !filter->get_int("disable")); MLT.play(speed); emit changed(); emit dataChanged(createIndex(index.row(), 0), createIndex(index.row(), 0)); } delete filter; return true; } return false; }
void AttachedFiltersModel::reset(Mlt::Producer* producer) { beginResetModel(); m_event.reset(); if (producer && producer->is_valid()) m_producer.reset(new Mlt::Producer(producer)); else if (MLT.isClip()) m_producer.reset(new Mlt::Producer(MLT.producer())); else m_producer.reset(); m_metaList.clear(); m_mltIndexMap.clear(); if (m_producer && 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); if (filter && filter->is_valid() && !filter->get_int("_loader")) { QmlMetadata* newMeta = MAIN.filterController()->metadataForService(filter); int newIndex = m_metaList.count(); for (int j = newIndex - 1; j >= 0; j--) { const QmlMetadata* prevMeta = m_metaList[j]; if (sortIsLess(prevMeta, newMeta)) { newIndex = j; } else { break; } } m_metaList.insert(newIndex, newMeta); m_mltIndexMap.insert(newIndex, i); } delete filter; } } endResetModel(); emit trackTitleChanged(); emit isProducerSelectedChanged(); emit readyChanged(); }
int AttachedFiltersModel::indexForRow(int row) const { int result = -1; if (m_producer && m_producer->is_valid()) { int count = m_producer->filter_count(); int j = 0; for (int i = 0; i < count; i++) { Mlt::Filter* filter = m_producer->filter(i); if (filter && filter->is_valid() && !filter->get_int("_loader")) { if (j == row) { result = i; break; } j++; } delete filter; } } return result; }
QVariant AttachedFiltersModel::data(const QModelIndex &index, int role) const { if ( !m_producer || !m_producer->is_valid() || index.row() >= m_producer->filter_count()) return QVariant(); switch (role ) { case Qt::DisplayRole: { QVariant result; Mlt::Filter* filter = filterForRow(index.row()); if (filter && filter->is_valid()) { // Relabel by QML UI QmlMetadata* meta = MAIN.filtersDock()->qmlMetadataForService(filter); if (meta) result = meta->name(); // Fallback is raw mlt_service name else if (filter->get("mlt_service")) result = QString::fromUtf8(filter->get("mlt_service")); } // Relabel for widgets UIs if (result == "movit.mirror" || result == "mirror") result = tr("Mirror"); delete filter; return result; } case Qt::CheckStateRole: { Mlt::Filter* filter = filterForRow(index.row()); QVariant result = Qt::Unchecked; if (filter && filter->is_valid() && !filter->get_int("disable")) result = Qt::Checked; delete filter; return result; } break; default: break; } return QVariant(); }
bool EffectManager::addEffect(EffectsParameterList params, int duration) { bool updateIndex = false; const int filter_ix = params.paramValue(QStringLiteral("kdenlive_ix")).toInt(); int ct = 0; QList <Mlt::Filter *> filters; m_producer.lock(); Mlt::Filter *filter = m_producer.filter(ct); while (filter) { filters << filter; if (filter->get_int("kdenlive_ix") == filter_ix) { // A filter at that position already existed, so we will increase all indexes later updateIndex = true; break; } ct++; filter = m_producer.filter(ct); } if (params.paramValue(QStringLiteral("id")) == QLatin1String("speed")) { // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix) ct = 0; filter = m_producer.filter(ct); while (filter) { filters << filter; if (filter->get_int("kdenlive_ix") >= filter_ix) { if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1); } ct++; filter = m_producer.filter(ct); } m_producer.unlock(); qDeleteAll(filters); return true; } // temporarily remove all effects after insert point QList <Mlt::Filter *> filtersList; ct = 0; filter = m_producer.filter(ct); while (filter) { if (filter->get_int("kdenlive_ix") >= filter_ix) { filtersList.append(filter); m_producer.detach(*filter); } else ct++; filter = m_producer.filter(ct); } // Add new filter bool success = doAddFilter(params, duration); // re-add following filters for (int i = 0; i < filtersList.count(); ++i) { Mlt::Filter *filter = filtersList.at(i); if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1); m_producer.attach(*filter); } m_producer.unlock(); qDeleteAll(filters); qDeleteAll(filtersList); return success; }
bool EffectManager::editEffect(EffectsParameterList params, int duration, bool replaceEffect) { int index = params.paramValue(QStringLiteral("kdenlive_ix")).toInt(); QString tag = params.paramValue(QStringLiteral("tag")); if (!params.paramValue(QStringLiteral("keyframes")).isEmpty() || replaceEffect || tag.startsWith(QLatin1String("ladspa")) || tag == QLatin1String("sox") || tag == QLatin1String("autotrack_rectangle")) { // This is a keyframe effect, to edit it, we remove it and re-add it. if (removeEffect(index, false)) { return addEffect(params, duration); } } // find filter int ct = 0; Mlt::Filter *filter = m_producer.filter(ct); while (filter) { if (filter->get_int("kdenlive_ix") == index) { break; } delete filter; ct++; filter = m_producer.filter(ct); } if (!filter) { qDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag; // filter was not found, it was probably a disabled filter, so add it to the correct place... bool success = addEffect(params, duration); return success; } ct = 0; QString ser = filter->get("mlt_service"); QList <Mlt::Filter *> filtersList; m_producer.lock(); if (ser != tag) { // Effect service changes, delete effect and re-add it m_producer.detach(*filter); delete filter; // Delete all effects after deleted one filter = m_producer.filter(ct); while (filter) { if (filter->get_int("kdenlive_ix") > index) { filtersList.append(filter); m_producer.detach(*filter); } else ct++; delete filter; filter = m_producer.filter(ct); } // re-add filter doAddFilter(params, duration); m_producer.unlock(); return true; } if (params.hasParam(QStringLiteral("kdenlive:sync_in_out"))) { if (params.paramValue(QStringLiteral("kdenlive:sync_in_out")) == QLatin1String("1")) { // This effect must sync in / out with parent clip //params.removeParam(QStringLiteral("sync_in_out")); Mlt::Producer prod(m_producer); filter->set_in_and_out(prod.get_in(), prod.get_out()); } else { // Reset in/out properties filter->set("in", (char*)NULL); filter->set("out", (char*)NULL); } } for (int j = 0; j < params.count(); ++j) { filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData()); } for (int j = 0; j < filtersList.count(); ++j) { m_producer.attach(*(filtersList.at(j))); } qDeleteAll(filtersList); m_producer.unlock(); delete filter; return true; }