Commit a50a24f1 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Removing a remap effect now restores input duration

parent b4c0505c
......@@ -376,6 +376,33 @@ bool ClipModel::isChain() const
return m_producer->parent().type() == mlt_service_chain_type;
}
int ClipModel::getRemapInputDuration() const
{
Mlt::Chain fromChain(m_producer->parent());
int count = fromChain.link_count();
for (int i = 0; i < count; i++) {
QScopedPointer<Mlt::Link> fromLink(fromChain.link(i));
if (fromLink && fromLink->is_valid() && fromLink->get("mlt_service")) {
if (fromLink->get("mlt_service") == QLatin1String("timeremap")) {
// Found a timeremap effect, read params
std::shared_ptr<Mlt::Link> link = std::make_shared<Mlt::Link>(fromChain.link(i)->get_link());
QString mapData = link->get("map");
int min = GenTime(link->anim_get_double("map", getIn())).frames(pCore->getCurrentFps());
QStringList str = mapData.split(QLatin1Char(';'));
int max = -1;
for (auto &s : str) {
int val = GenTime(s.section(QLatin1Char('='), 1).toDouble()).frames(pCore->getCurrentFps());
if (val > max) {
max = val;
}
}
return max - min;
}
}
}
return 0;
}
std::shared_ptr<Mlt::Producer> ClipModel::getProducer()
{
READ_LOCK();
......
......@@ -87,6 +87,8 @@ public:
/** @brief Returns true if the producer is embedded in a chain (for use with timeremap) */
bool isChain() const;
/** @brief Returns the duration of the input map */
int getRemapInputDuration() const;
/** @brief Returns a comma separated list of effect names */
const QString effectNames() const;
......
......@@ -4876,6 +4876,12 @@ bool TimelineModel::requestClipTimeRemap(int clipId, bool enable, Fun &undo, Fun
// in order to make the producer change effective, we need to unplant / replant the clip in int track
bool success = true;
int trackId = getClipTrackId(clipId);
int previousDuration = 0;
qDebug()<<"=== REQUEST REMAP: "<<enable<<"\n\nWWWWWWWWWWWWWWWWWWWWWWWWWWWW";
if (!enable && m_allClips[clipId]->isChain()) {
previousDuration = m_allClips[clipId]->getRemapInputDuration();
qDebug()<<"==== CALCULATED INPIUT DURATION: "<<previousDuration<<"\n\nHHHHHHHHHHHHHH";
}
if (trackId != -1) {
success = success && getTrackById(trackId)->requestClipDeletion(clipId, true, true, local_undo, local_redo, false, false);
}
......@@ -4884,6 +4890,10 @@ bool TimelineModel::requestClipTimeRemap(int clipId, bool enable, Fun &undo, Fun
}
if (trackId != -1) {
success = success && getTrackById(trackId)->requestClipInsertion(clipId, oldPos, true, true, local_undo, local_redo);
if (success && !enable && previousDuration > 0) {
// Restore input duration
requestItemResize(clipId, previousDuration, true, true, local_undo, local_redo);
}
}
if (!success) {
local_undo();
......
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