Commit 55c685bb authored by Nicolas Carion's avatar Nicolas Carion

wip to correctly apply bin's effect

parent 134b98b1
......@@ -425,6 +425,7 @@ void ProjectClip::createVideoMasterProducer()
// disable audio but activate video
m_videoProducer->set("set.test_audio", 1);
m_videoProducer->set("set.test_image", 0);
m_effectStack->addService(m_videoProducer);
}
}
void ProjectClip::createDisabledMasterProducer()
......@@ -433,6 +434,7 @@ void ProjectClip::createDisabledMasterProducer()
m_disabledProducer = cloneProducer(&pCore->getCurrentProfile()->profile());
m_disabledProducer->set("set.test_audio", 1);
m_disabledProducer->set("set.test_image", 1);
m_effectStack->addService(m_disabledProducer);
}
}
std::shared_ptr<Mlt::Producer> ProjectClip::getTimelineProducer(int clipId, PlaylistState::ClipState state, double speed)
......@@ -440,17 +442,24 @@ std::shared_ptr<Mlt::Producer> ProjectClip::getTimelineProducer(int clipId, Play
if (qFuzzyCompare(speed, 1.0)) {
// we are requesting a normal speed producer
// We can first cleen the speed producers we have for the current id
m_timewarpProducers.erase(clipId);
if (m_timewarpProducers.count(clipId) > 0) {
m_effectStack->removeService(m_timewarpProducers[clipId]);
m_timewarpProducers.erase(clipId);
}
if (state == PlaylistState::AudioOnly) {
// We need to get an audio producer, if none exists
if (m_audioProducers.count(clipId) == 0) {
m_audioProducers[clipId] = cloneProducer(&pCore->getCurrentProfile()->profile());
m_audioProducers[clipId]->set("set.test_audio", 0);
m_audioProducers[clipId]->set("set.test_image", 1);
m_effectStack->addService(m_audioProducers[clipId]);
}
return std::shared_ptr<Mlt::Producer>(m_audioProducers[clipId]->cut());
}
m_audioProducers.erase(clipId);
if (m_audioProducers.count(clipId) > 0) {
m_effectStack->removeService(m_audioProducers[clipId]);
m_audioProducers.erase(clipId);
}
if (state == PlaylistState::VideoOnly) {
// we return the video producer
createVideoMasterProducer();
......@@ -462,7 +471,10 @@ std::shared_ptr<Mlt::Producer> ProjectClip::getTimelineProducer(int clipId, Play
}
// in that case, we need to create a warp producer, if we don't have one
m_audioProducers.erase(clipId);
if (m_audioProducers.count(clipId) > 0) {
m_effectStack->removeService(m_audioProducers[clipId]);
m_audioProducers.erase(clipId);
}
std::shared_ptr<Mlt::Producer> warpProducer;
if (m_timewarpProducers.count(clipId) > 0) {
......@@ -470,6 +482,8 @@ std::shared_ptr<Mlt::Producer> ProjectClip::getTimelineProducer(int clipId, Play
// the producer we have is good, use it !
warpProducer = m_timewarpProducers[clipId];
}
// remove in all cases, we add it unconditionally anyways
m_effectStack->removeService(m_timewarpProducers[clipId]);
}
if (!warpProducer) {
QString resource = QString("timewarp:%1:%2").arg(speed).arg(originalProducer()->get("resource"));
......@@ -485,6 +499,7 @@ std::shared_ptr<Mlt::Producer> ProjectClip::getTimelineProducer(int clipId, Play
warpProducer->set("set.test_image", 0);
}
m_timewarpProducers[clipId] = warpProducer;
m_effectStack->addService(m_timewarpProducers[clipId]);
return warpProducer;
}
......@@ -534,20 +549,24 @@ std::pair<std::shared_ptr<Mlt::Producer>, bool> ProjectClip::giveMasterAndGetTim
master->parent().set("loaded", 1);
if (state == PlaylistState::AudioOnly) {
m_audioProducers[clipId] = std::shared_ptr<Mlt::Producer>(&master->parent());
m_effectStack->addService(m_audioProducers[clipId]);
return {master, true};
}
if (timeWarp) {
m_timewarpProducers[clipId] = std::shared_ptr<Mlt::Producer>(&master->parent());
m_effectStack->addService(m_timewarpProducers[clipId]);
return {master, true};
}
if (state == PlaylistState::VideoOnly && !m_videoProducer) {
// good, we found a master video producer, and we didn't have any
m_videoProducer.reset(&master->parent());
m_effectStack->addService(m_videoProducer);
return {master, true};
}
if (state == PlaylistState::Disabled && !m_disabledProducer) {
// good, we found a master disabled producer, and we didn't have any
m_disabledProducer.reset(&master->parent());
m_effectStack->addService(m_disabledProducer);
return {master, true};
}
qDebug() << "Warning: weird, we found a clip whose master is not loaded but we already have a master";
......
......@@ -67,6 +67,18 @@ void EffectStackModel::addService(std::weak_ptr<Mlt::Service> service)
std::static_pointer_cast<EffectItemModel>(rootItem->child(i))->plant(m_services.back());
}
}
void EffectStackModel::removeService(std::shared_ptr<Mlt::Service> service)
{
std::vector<int> to_delete;
for (int i = int(m_services.size()) - 1; i >= 0; --i) {
if (service.get() == m_services[i].lock().get()) {
to_delete.push_back(i);
}
}
for (int i : to_delete) {
m_services.erase(m_services.begin() + i);
}
}
void EffectStackModel::removeEffect(std::shared_ptr<EffectItemModel> effect)
{
......@@ -445,11 +457,14 @@ void EffectStackModel::moveEffect(int destRow, std::shared_ptr<AbstractEffectIte
void EffectStackModel::registerItem(const std::shared_ptr<TreeItem> &item)
{
qDebug() << "$$$$$$$$$$$$$$$$$$$$$ Planting effect";
QModelIndex ix;
if (!item->isRoot()) {
auto effectItem = std::static_pointer_cast<AbstractEffectItem>(item);
if (!m_loadingExisting) {
qDebug() << "$$$$$$$$$$$$$$$$$$$$$ Planting effect in " << m_services.size();
for (const auto &service : m_services) {
qDebug() << "$$$$$$$$$$$$$$$$$$$$$ Planting effect in " << (void *)service.lock().get();
effectItem->plant(service);
}
}
......
......@@ -112,6 +112,9 @@ public:
/* @brief Append a new service to be managed by this stack */
void addService(std::weak_ptr<Mlt::Service> service);
/* @brief Remove a service from those managed by this stack */
void removeService(std::shared_ptr<Mlt::Service> service);
public slots:
/* @brief Delete an effect from the stack */
void removeEffect(std::shared_ptr<EffectItemModel> effect);
......
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