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

Correctly load and save mix cut position

parent 827c2a6e
......@@ -48,7 +48,7 @@ static QStringList m_errorMessage;
bool constructTrackFromMelt(const std::shared_ptr<TimelineItemModel> &timeline, int tid, Mlt::Tractor &track,
const std::unordered_map<QString, QString> &binIdCorresp, Fun &undo, Fun &redo, bool audioTrack, QString originalDecimalPoint, QProgressDialog *progressDialog = nullptr);
bool constructTrackFromMelt(const std::shared_ptr<TimelineItemModel> &timeline, int tid, Mlt::Playlist &track,
const std::unordered_map<QString, QString> &binIdCorresp, Fun &undo, Fun &redo, bool audioTrack, QString originalDecimalPoint, int playlist, QMap <int, int> mixList, QProgressDialog *progressDialog = nullptr);
const std::unordered_map<QString, QString> &binIdCorresp, Fun &undo, Fun &redo, bool audioTrack, QString originalDecimalPoint, int playlist, QProgressDialog *progressDialog = nullptr);
bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timeline, Mlt::Tractor tractor, QProgressDialog *progressDialog, QString originalDecimalPoint)
{
......@@ -127,7 +127,7 @@ bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timelin
timeline->setTrackProperty(tid, QStringLiteral("hide"), QString::number(muteState));
}
ok = ok && constructTrackFromMelt(timeline, tid, local_playlist, binIdCorresp, undo, redo, audioTrack, originalDecimalPoint, 0, {}, progressDialog);
ok = ok && constructTrackFromMelt(timeline, tid, local_playlist, binIdCorresp, undo, redo, audioTrack, originalDecimalPoint, 0, progressDialog);
if (local_playlist.get_int("kdenlive:locked_track") > 0) {
lockedTracksIndexes << tid;
}
......@@ -229,11 +229,9 @@ bool constructTrackFromMelt(const std::shared_ptr<TimelineItemModel> &timeline,
// Check same track transitions
QScopedPointer<Mlt::Service> service(track.field());
QList<Mlt::Transition *> compositions;
QMap <int, int> mixList;
while ((service != nullptr) && service->is_valid()) {
if (service->type() == transition_type) {
Mlt::Transition t((mlt_transition)service->get_service());
mixList.insert(t.get_in(), t.get_out());
QString id(t.get("kdenlive_id"));
compositions << new Mlt::Transition(t);
if (id.isEmpty()) {
......@@ -250,7 +248,7 @@ bool constructTrackFromMelt(const std::shared_ptr<TimelineItemModel> &timeline,
return false;
}
Mlt::Playlist playlist(*sub_track);
constructTrackFromMelt(timeline, tid, playlist, binIdCorresp, undo, redo, audioTrack, originalDecimalPoint, i, mixList, progressDialog);
constructTrackFromMelt(timeline, tid, playlist, binIdCorresp, undo, redo, audioTrack, originalDecimalPoint, i, progressDialog);
if (i == 0) {
// Pass track properties
int height = track.get_int("kdenlive:trackheight");
......@@ -314,10 +312,9 @@ PlaylistState::ClipState inferState(const std::shared_ptr<Mlt::Producer> &prod,
} // namespace
bool constructTrackFromMelt(const std::shared_ptr<TimelineItemModel> &timeline, int tid, Mlt::Playlist &track,
const std::unordered_map<QString, QString> &binIdCorresp, Fun &undo, Fun &redo, bool audioTrack, QString originalDecimalPoint, int playlist, QMap <int, int> mixList, QProgressDialog *progressDialog)
const std::unordered_map<QString, QString> &binIdCorresp, Fun &undo, Fun &redo, bool audioTrack, QString originalDecimalPoint, int playlist, QProgressDialog *progressDialog)
{
int max = track.count();
qDebug()<<"=====GOT MIXLIST FOR TID:\n"<<mixList<<"\n\n______________________________________________________";
for (int i = 0; i < max; i++) {
if (track.is_blank(i)) {
continue;
......@@ -368,12 +365,7 @@ bool constructTrackFromMelt(const std::shared_ptr<TimelineItemModel> &timeline,
if (pCore->bin()->getBinClip(binId)) {
PlaylistState::ClipState st = inferState(clip, audioTrack);
qDebug()<<"==== INSERTING CLIP IN PLAYLIST: "<<playlist<<"\n8888888888888888888888";
int mixDuration = 0;
if (mixList.contains(position)) {
// Clip has a mix
mixDuration = mixList.value(position) - position;
}
cid = ClipModel::construct(timeline, binId, clip, st, tid, originalDecimalPoint, playlist, mixDuration);
cid = ClipModel::construct(timeline, binId, clip, st, tid, originalDecimalPoint, playlist);
ok = timeline->requestClipMove(cid, tid, position, true, true, false, true, undo, redo);
} else {
qDebug() << "// Cannot find bin clip: " << binId << " - " << clip->get("id");
......
......@@ -102,7 +102,7 @@ void ClipModel::allSnaps(std::vector<int> &snaps, int offset)
}
int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, const std::shared_ptr<Mlt::Producer> &producer,
PlaylistState::ClipState state, int tid, QString originalDecimalPoint, int playlist, int mixDuration)
PlaylistState::ClipState state, int tid, QString originalDecimalPoint, int playlist)
{
// we hand the producer to the bin clip, and in return we get a cut to a good master producer
......@@ -131,7 +131,6 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt
}
clip->setClipState_lambda(state)();
clip->setSubPlaylistIndex(playlist);
clip->setMixDuration(mixDuration);
parent->registerClip(clip);
clip->m_effectStack->importEffects(producer, state, result.second, originalDecimalPoint);
clip->m_clipMarkerModel->setReferenceModel(binClip->getMarkerModel(), speed);
......
......@@ -65,7 +65,7 @@ public:
Note that there is no guarantee that this producer is actually going to be used. It might be discarded.
*/
static int construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, const std::shared_ptr<Mlt::Producer> &producer,
PlaylistState::ClipState state, int tid, QString originalDecimalPoint, int playlist = 0, int mixDuration = 0);
PlaylistState::ClipState state, int tid, QString originalDecimalPoint, int playlist = 0);
/** @brief returns a property of the clip, or from it's parent if it's a cut
*/
......
......@@ -2719,13 +2719,13 @@ int TimelineModel::requestItemResize(int itemId, int size, bool right, bool logU
adjust_mix = [this, tid, mixData, currentMixCut, itemId]() {
MixInfo secondMixData = getTrackById_const(tid)->getMixInfo(itemId).second;
int offset = mixData.second.firstClipInOut.second - secondMixData.firstClipInOut.second;
m_allClips[secondMixData.secondClipId]->setMixDuration(secondMixData.firstClipInOut.second - secondMixData.secondClipInOut.first, currentMixCut - offset);
getTrackById_const(tid)->setMixDuration(secondMixData.secondClipId, secondMixData.firstClipInOut.second - secondMixData.secondClipInOut.first, currentMixCut - offset);
QModelIndex ix = makeClipIndexFromID(secondMixData.secondClipId);
emit dataChanged(ix, ix, {TimelineModel::MixRole,TimelineModel::MixCutRole});
return true;
};
Fun adjust_mix_undo = [this, mixData, currentMixCut, currentMixDuration]() {
m_allClips[mixData.second.secondClipId]->setMixDuration(currentMixDuration, currentMixCut);
Fun adjust_mix_undo = [this, tid, mixData, currentMixCut, currentMixDuration]() {
getTrackById_const(tid)->setMixDuration(mixData.second.secondClipId, currentMixDuration, currentMixCut);
QModelIndex ix = makeClipIndexFromID(mixData.second.secondClipId);
emit dataChanged(ix, ix, {TimelineModel::MixRole,TimelineModel::MixCutRole});
return true;
......@@ -2921,7 +2921,7 @@ bool TimelineModel::requestItemResize(int itemId, int size, bool right, bool log
std::pair<MixInfo, MixInfo> mixData = getTrackById_const(tid)->getMixInfo(itemId);
// We have a mix at clip start
int mixDuration = mixData.first.firstClipInOut.second - (mixData.first.secondClipInOut.second - size);
m_allClips[itemId]->setMixDuration(qMax(1, mixDuration), m_allClips[itemId]->getMixCutPosition());
getTrackById_const(tid)->setMixDuration(itemId, qMax(1, mixDuration), m_allClips[itemId]->getMixCutPosition());
QModelIndex ix = makeClipIndexFromID(itemId);
emit dataChanged(ix, ix, {TimelineModel::MixRole,TimelineModel::MixCutRole});
}
......
......@@ -1503,6 +1503,7 @@ bool TrackModel::requestRemoveMix(std::pair<int, int> clipIds, Fun &undo, Fun &r
if (isAudioTrack()) {
std::shared_ptr<Mlt::Transition> t(new Mlt::Transition(*ptr->getProfile(), "mix"));
t->set_in_and_out(mixPosition, mixPosition + mixDuration);
t->set("kdenlive:mixcut", mixCutPos);
if (src_track == 0) {
t->set("reverse", 1);
}
......@@ -1511,6 +1512,7 @@ bool TrackModel::requestRemoveMix(std::pair<int, int> clipIds, Fun &undo, Fun &r
} else {
std::shared_ptr<Mlt::Transition> t(new Mlt::Transition(*ptr->getProfile(), "luma"));
t->set_in_and_out(mixPosition, mixPosition + mixDuration);
t->set("kdenlive:mixcut", mixCutPos);
if (src_track == 0) {
t->set("reverse", 1);
}
......@@ -1707,6 +1709,7 @@ bool TrackModel::requestClipMix(std::pair<int, int> clipIds, int mixDuration, bo
if (isAudioTrack()) {
std::shared_ptr<Mlt::Transition> t(new Mlt::Transition(*ptr->getProfile(), "mix"));
t->set_in_and_out(mixPosition, mixPosition + mixDuration);
t->set("kdenlive:mixcut", secondClipCut);
if (dest_track == 0) {
t->set("reverse", 1);
}
......@@ -1715,6 +1718,7 @@ bool TrackModel::requestClipMix(std::pair<int, int> clipIds, int mixDuration, bo
} else {
std::shared_ptr<Mlt::Transition> t(new Mlt::Transition(*ptr->getProfile(), "luma"));
t->set_in_and_out(mixPosition, mixPosition + mixDuration);
t->set("kdenlive:mixcut", secondClipCut);
if (dest_track == 0) {
t->set("reverse", 1);
}
......@@ -1937,6 +1941,12 @@ bool TrackModel::createMix(std::pair<int, int> clipIds, std::pair<int, int> mixD
return false;
}
void TrackModel::setMixDuration(int cid, int mixDuration, int mixCut)
{
m_allClips[cid]->setMixDuration(mixDuration, mixCut);
m_sameCompositions[cid]->set("kdenlive:mixcut", mixCut);
}
void TrackModel::syncronizeMixes(bool finalMove)
{
QList<int>toDelete;
......@@ -2027,5 +2037,6 @@ bool TrackModel::loadMix(Mlt::Transition &t)
std::shared_ptr<Mlt::Transition>tr(&t);
m_sameCompositions[cid2] = tr;
m_mixList.insert(cid1, cid2);
setMixDuration(cid2, t.get_length() - 1, t.get_int("kdenlive:mixcut"));
return true;
}
......@@ -136,6 +136,8 @@ public:
bool switchPlaylist(int clipId, int position, int sourcePlaylist, int destPlaylist);
/** @brief Load a same track transition from project */
bool loadMix(Mlt::Transition &t);
/** @brief Set mix duration and mix cut pos on a clip */
void setMixDuration(int cid, int mixDuration, int mixCut);
protected:
/* @brief This will lock the track: it will no longer allow insertion/deletion/resize of items
......
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