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

speed effect: Fix effect lost on project opening and on copy/paste

parent c5c2d52d
......@@ -756,6 +756,9 @@ Bin::Bin(const std::shared_ptr<ProjectItemModel> &model, QWidget *parent)
m_headerInfo = QByteArray::fromBase64(KdenliveSettings::treeviewheaders().toLatin1());
m_propertiesPanel = new QScrollArea(this);
m_propertiesPanel->setFrameShape(QFrame::NoFrame);
// Insert listview
m_itemView = new MyTreeView(this);
m_layout->addWidget(m_itemView);
// Info widget for failed jobs, other errors
m_infoMessage = new KMessageWidget(this);
m_layout->addWidget(m_infoMessage);
......
......@@ -636,7 +636,7 @@ std::pair<std::shared_ptr<Mlt::Producer>, bool> ProjectClip::giveMasterAndGetTim
qDebug() << "Warning: weird, we received a master clip in lieue of a cut";
exit(1);
double speed = 1.0;
if (QString::fromUtf8(master->get("mlt_service")) == QLatin1String("timewarp")) {
if (QString::fromUtf8(master->parent().get("mlt_service")) == QLatin1String("timewarp")) {
speed = master->get_double("warp_speed");
}
return {getTimelineProducer(clipId, state, speed), false};
......
......@@ -63,7 +63,7 @@ ClipModel::ClipModel(std::shared_ptr<TimelineModel> parent, std::shared_ptr<Mlt:
});
}
int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, int id, PlaylistState::ClipState state)
int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, int id, PlaylistState::ClipState state, double speed)
{
id = (id == -1 ? TimelineModel::getNextId() : id);
std::shared_ptr<ProjectClip> binClip = pCore->projectItemModel()->getClipByBinID(binClipId);
......@@ -74,8 +74,8 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt
videoAudio.second = videoAudio.second && binClip->hasAudio();
state = stateFromBool(videoAudio);
std::shared_ptr<Mlt::Producer> cutProducer = binClip->getTimelineProducer(id, state, 1.);
std::shared_ptr<ClipModel> clip(new ClipModel(parent, cutProducer, binClipId, id, state));
std::shared_ptr<Mlt::Producer> cutProducer = binClip->getTimelineProducer(id, state, speed);
std::shared_ptr<ClipModel> clip(new ClipModel(parent, cutProducer, binClipId, id, state, speed));
clip->setClipState_lambda(state)();
parent->registerClip(clip);
return id;
......@@ -99,8 +99,8 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt
state = stateFromBool(videoAudio);
double speed = 1.0;
if (QString::fromUtf8(producer->get("mlt_service")) == QLatin1String("timewarp")) {
speed = producer->get_double("warp_speed");
if (QString::fromUtf8(producer->parent().get("mlt_service")) == QLatin1String("timewarp")) {
speed = producer->parent().get_double("warp_speed");
}
auto result = binClip->giveMasterAndGetTimelineProducer(id, producer, state);
std::shared_ptr<ClipModel> clip(new ClipModel(parent, result.first, binClipId, id, state, speed));
......@@ -621,6 +621,7 @@ QDomElement ClipModel::toXml(QDomDocument &document)
container.setAttribute(QStringLiteral("out"), getOut());
container.setAttribute(QStringLiteral("position"), getPosition());
container.setAttribute(QStringLiteral("track"), getCurrentTrackId());
container.setAttribute(QStringLiteral("speed"), m_speed);
container.appendChild(m_effectStack->toXml(document));
return container;
}
......@@ -58,7 +58,7 @@ public:
@param binClip is the id of the bin clip associated
@param id Requested id of the clip. Automatic if -1
*/
static int construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, int id, PlaylistState::ClipState state);
static int construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, int id, PlaylistState::ClipState state, double speed = 1.);
/* @brief Creates a clip, which references itself to the parent timeline
Returns the (unique) id of the created clip
......
......@@ -38,12 +38,9 @@ bool TimelineFunctions::copyClip(std::shared_ptr<TimelineItemModel> timeline, in
{
// Special case: slowmotion clips
double clipSpeed = timeline->m_allClips[clipId]->getSpeed();
bool res = timeline->requestClipCreation(timeline->getClipBinId(clipId), newId, state, undo, redo);
bool res = timeline->requestClipCreation(timeline->getClipBinId(clipId), newId, state, clipSpeed, undo, redo);
timeline->m_allClips[newId]->m_endlessResize = timeline->m_allClips[clipId]->m_endlessResize;
// Apply speed effect if necessary
if (!qFuzzyCompare(clipSpeed, 1.0)) {
timeline->m_allClips[newId]->useTimewarpProducer(clipSpeed, undo, redo);
}
// copy useful timeline properties
timeline->m_allClips[clipId]->passTimelineProperties(timeline->m_allClips[newId]);
......
......@@ -823,7 +823,7 @@ int TimelineModel::suggestCompositionMove(int compoId, int trackId, int position
return currentPos;
}
bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, Fun &undo, Fun &redo)
bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, double speed, Fun &undo, Fun &redo)
{
qDebug() << "requestClipCreation " << binClipId;
QString bid = binClipId;
......@@ -840,7 +840,7 @@ bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, Playl
int clipId = TimelineModel::getNextId();
id = clipId;
Fun local_undo = deregisterClip_lambda(clipId);
ClipModel::construct(shared_from_this(), bid, clipId, state);
ClipModel::construct(shared_from_this(), bid, clipId, state, speed);
auto clip = m_allClips[clipId];
Fun local_redo = [clip, this, state, clipId]() {
// We capture a shared_ptr to the clip, which means that as long as this undo object lives, the clip object is not deleted. To insert it back it is
......@@ -918,7 +918,7 @@ bool TimelineModel::requestClipInsertion(const QString &binClipId, int trackId,
trackId = m_audioTarget;
}
bool audioDrop = getTrackById_const(trackId)->isAudioTrack();
res = requestClipCreation(binClipId, id, getTrackById_const(trackId)->trackType(), local_undo, local_redo);
res = requestClipCreation(binClipId, id, getTrackById_const(trackId)->trackType(), 1.0, local_undo, local_redo);
res = res && requestClipMove(id, trackId, position, refreshView, logUndo, local_undo, local_redo);
int target_track = audioDrop ? m_videoTarget : m_audioTarget;
qDebug()<<"CLIP HAS A+V: "<<master->hasAudioAndVideo();
......@@ -940,7 +940,7 @@ bool TimelineModel::requestClipInsertion(const QString &binClipId, int trackId,
std::function<bool(void)> audio_undo = []() { return true; };
std::function<bool(void)> audio_redo = []() { return true; };
int newId;
res = requestClipCreation(binClipId, newId, audioDrop ? PlaylistState::VideoOnly : PlaylistState::AudioOnly, audio_undo, audio_redo);
res = requestClipCreation(binClipId, newId, audioDrop ? PlaylistState::VideoOnly : PlaylistState::AudioOnly, 1.0, audio_undo, audio_redo);
if (res) {
bool move = false;
while (!move && !possibleTracks.isEmpty()) {
......@@ -975,7 +975,7 @@ bool TimelineModel::requestClipInsertion(const QString &binClipId, int trackId,
if (normalisedBinId.startsWith(QLatin1Char('A')) || normalisedBinId.startsWith(QLatin1Char('V'))) {
normalisedBinId.remove(0, 1);
}
res = requestClipCreation(normalisedBinId, id, dropType, local_undo, local_redo);
res = requestClipCreation(normalisedBinId, id, dropType, 1.0, local_undo, local_redo);
res = res && requestClipMove(id, trackId, position, refreshView, logUndo, local_undo, local_redo);
}
if (!res) {
......
......@@ -390,7 +390,7 @@ public:
@param id: return parameter for the id of the newly created clip.
@param state: The desired clip state (original, audio/video only).
*/
bool requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, Fun &undo, Fun &redo);
bool requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, double speed, Fun &undo, Fun &redo);
/* @brief Deletes the given clip or composition from the timeline This
action is undoable Returns true on success. If it fails, nothing is
......
......@@ -609,6 +609,7 @@ bool TimelineController::pasteItem()
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
bool res = true;
QLocale locale;
QMap <int, int> correspondingIds;
for (int i = 0; res && i < clips.count(); i++) {
QDomElement prod = clips.at(i).toElement();
......@@ -617,8 +618,9 @@ bool TimelineController::pasteItem()
int out = prod.attribute(QStringLiteral("out")).toInt();
int trackId = prod.attribute(QStringLiteral("track")).toInt();
int pos = prod.attribute(QStringLiteral("position")).toInt() - offset;
double speed = locale.toDouble(prod.attribute(QStringLiteral("speed")));
int newId;
res = m_model->requestClipCreation(originalId, newId, m_model->getTrackById_const(trackId)->trackType(), undo, redo);
res = m_model->requestClipCreation(originalId, newId, m_model->getTrackById_const(trackId)->trackType(), speed, undo, redo);
if(m_model->m_allClips[newId]->m_endlessResize) {
out = out - in;
in = 0;
......
......@@ -1024,7 +1024,7 @@ TEST_CASE("Undo and Redo", "[ClipModel]")
int temp;
Fun undo = []() { return true; };
Fun redo = []() { return true; };
REQUIRE_FALSE(timeline->requestClipCreation("impossible bin id", temp, PlaylistState::VideoOnly, undo, redo));
REQUIRE_FALSE(timeline->requestClipCreation("impossible bin id", temp, PlaylistState::VideoOnly, 1., undo, redo));
}
auto state0 = [&]() {
......@@ -1038,7 +1038,7 @@ TEST_CASE("Undo and Redo", "[ClipModel]")
{
Fun undo = []() { return true; };
Fun redo = []() { return true; };
REQUIRE(timeline->requestClipCreation(binId3, cid3, PlaylistState::VideoOnly, undo, redo));
REQUIRE(timeline->requestClipCreation(binId3, cid3, PlaylistState::VideoOnly, 1., undo, redo));
pCore->pushUndo(undo, redo, QString());
}
......@@ -1055,7 +1055,7 @@ TEST_CASE("Undo and Redo", "[ClipModel]")
{
Fun undo = []() { return true; };
Fun redo = []() { return true; };
REQUIRE(timeline->requestClipCreation(binId4, cid4, PlaylistState::VideoOnly, undo, redo));
REQUIRE(timeline->requestClipCreation(binId4, cid4, PlaylistState::VideoOnly, 1., undo, redo));
pCore->pushUndo(undo, redo, QString());
}
......@@ -1483,7 +1483,7 @@ TEST_CASE("Undo and Redo", "[ClipModel]")
{
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
REQUIRE(timeline->requestClipCreation(binId, cid6, PlaylistState::VideoOnly, undo, redo));
REQUIRE(timeline->requestClipCreation(binId, cid6, PlaylistState::VideoOnly, 1., undo, redo));
pCore->pushUndo(undo, redo, QString());
}
int l = timeline->getClipPlaytime(cid6);
......
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