Fix loading of compositions

parent 85019dbb
......@@ -114,13 +114,15 @@ bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timelin
Mlt::Transition t((mlt_transition)service->get_service());
int compoId;
QString id(t.get("mlt_service"));
qDebug() << "////////// BUILD TRANS ON TK: " << t.get_b_track() << "id: " << id;
// ok = timeline->requestCompositionInsertion(id, t.get_b_track(), t.get_in(), compoId, undo, redo);
if (!ok) {
qDebug() << "ERROR : failed to insert composition in track " << t.get_b_track() << ", position" << t.get_in();
break;
QString internal(t.get("internal_added"));
if (internal.isEmpty()) {
ok = timeline->requestCompositionInsertion(id, timeline->getTrackIndexFromPosition(t.get_b_track() - 1), timeline->getTrackIndexFromPosition(t.get_a_track() - 1), t.get_in(), t.get_length(), compoId, undo, redo);
if (!ok) {
qDebug() << "ERROR : failed to insert composition in track " << t.get_b_track() << ", position" << t.get_in();
break;
}
qDebug() << "Inserted composition in track " << t.get_b_track() << ", position" << t.get_in();
}
qDebug() << "Inserted composition in track " << t.get_b_track() << ", position" << t.get_in();
}
service.reset(service->producer());
}
......
......@@ -399,7 +399,7 @@ int TimelineModel::suggestCompositionMove(int compoId, int trackId, int position
// we check if move is possible
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool possible = requestCompositionMove(compoId, trackId, position, false, undo, redo);
bool possible = requestCompositionMove(compoId, trackId, m_allCompositions[compoId]->getATrack(), position, false, undo, redo);
qDebug() << "Original move success" << possible;
if (possible) {
bool undone = undo();
......@@ -1194,7 +1194,7 @@ bool TimelineModel::requestCompositionInsertion(const QString &transitionId, int
QWriteLocker locker(&m_lock);
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool result = requestCompositionInsertion(transitionId, trackId, position, length, id, undo, redo);
bool result = requestCompositionInsertion(transitionId, trackId, -1, position, length, id, undo, redo);
if (result && logUndo) {
PUSH_UNDO(undo, redo, i18n("Insert Composition"));
}
......@@ -1202,7 +1202,7 @@ bool TimelineModel::requestCompositionInsertion(const QString &transitionId, int
return result;
}
bool TimelineModel::requestCompositionInsertion(const QString &transitionId, int trackId, int position, int length, int &id, Fun &undo, Fun &redo)
bool TimelineModel::requestCompositionInsertion(const QString &transitionId, int trackId, int compositionTrack, int position, int length, int &id, Fun &undo, Fun &redo)
{
qDebug() << "Inserting compo track" << trackId << "pos" << position << "length" << length;
int compositionId = TimelineModel::getNextId();
......@@ -1216,7 +1216,7 @@ bool TimelineModel::requestCompositionInsertion(const QString &transitionId, int
registerComposition(composition);
return true;
};
bool res = requestCompositionMove(compositionId, trackId, position, true, local_undo, local_redo);
bool res = requestCompositionMove(compositionId, trackId, compositionTrack, position, true, local_undo, local_redo);
qDebug() << "trying to move" << trackId << "pos" << position << "succes " << res;
if (res) {
res = requestItemResize(compositionId, length, true, true, local_undo, local_redo, true);
......@@ -1307,7 +1307,7 @@ bool TimelineModel::requestCompositionMove(int compoId, int trackId, int positio
int min = getCompositionPosition(compoId);
int max = min + getCompositionPlaytime(compoId);
int tk = getCompositionTrackId(compoId);
bool res = requestCompositionMove(compoId, trackId, position, updateView, undo, redo);
bool res = requestCompositionMove(compoId, trackId, m_allCompositions[compoId]->getATrack(), position, updateView, undo, redo);
if (tk > -1) {
min = qMin(min, getCompositionPosition(compoId));
max = qMax(max, getCompositionPosition(compoId));
......@@ -1323,14 +1323,16 @@ bool TimelineModel::requestCompositionMove(int compoId, int trackId, int positio
return res;
}
bool TimelineModel::requestCompositionMove(int compoId, int trackId, int position, bool updateView, Fun &undo, Fun &redo)
bool TimelineModel::requestCompositionMove(int compoId, int trackId, int compositionTrack, int position, bool updateView, Fun &undo, Fun &redo)
{
qDebug() << "Requesting composition move" << trackId << "," << position;
QWriteLocker locker(&m_lock);
Q_ASSERT(isComposition(compoId));
Q_ASSERT(isTrack(trackId));
int previousTrack = getPreviousVideoTrackId(trackId);
if (previousTrack == -1) {
if (compositionTrack == -1) {
compositionTrack = getPreviousVideoTrackId(trackId);
}
if (compositionTrack == -1) {
// it doesn't make sense to insert a composition on the last track
qDebug() << "Move failed because of last track";
return false;
......@@ -1374,8 +1376,8 @@ bool TimelineModel::requestCompositionMove(int compoId, int trackId, int positio
Fun insert_operation = []() { return true; };
Fun insert_reverse = []() { return true; };
if (old_trackId != trackId) {
insert_operation = [this, compoId, trackId, previousTrack]() {
m_allCompositions[compoId]->setATrack(previousTrack);
insert_operation = [this, compoId, trackId, compositionTrack]() {
m_allCompositions[compoId]->setATrack(compositionTrack);
return replantCompositions(compoId);
};
insert_reverse = [this, compoId]() {
......
......@@ -96,6 +96,7 @@ public:
friend class ClipModel;
friend class CompositionModel;
friend class GroupsModel;
friend class TimelineController;
/// Two level model: tracks and clips on track
enum {
......@@ -262,7 +263,7 @@ public:
/* Same function, but accumulates undo and redo, and doesn't check
for group*/
bool requestClipMove(int clipId, int trackId, int position, bool updateView, Fun &undo, Fun &redo);
bool requestCompositionMove(int transid, int trackId, int position, bool updateView, Fun &undo, Fun &redo);
bool requestCompositionMove(int transid, int trackId, int compositionTrack, int position, bool updateView, Fun &undo, Fun &redo);
Q_INVOKABLE int getCompositionPosition(int compoId) const;
Q_INVOKABLE int suggestCompositionMove(int compoId, int trackId, int position, int snapDistance = -1);
......@@ -447,7 +448,7 @@ public:
*/
bool requestCompositionInsertion(const QString &transitionId, int trackId, int position, int length, int &id, bool logUndo = true);
/* Same function, but accumulates undo and redo*/
bool requestCompositionInsertion(const QString &transitionId, int trackId, int position, int length, int &id, Fun &undo, Fun &redo);
bool requestCompositionInsertion(const QString &transitionId, int trackId, int compositionTrack, int position, int length, int &id, Fun &undo, Fun &redo);
/* @brief This function change the global (timeline-wise) enabled state of the effects
It disables/enables track and clip effects (recursively)
......
......@@ -46,14 +46,13 @@ Item {
property int trackHeight
property int trackIndex //Index in track repeater
property int trackId: -42 //Id in the model
property int a_track: -1
property int aTrack: -1
property int clipId //Id of the clip in the model
property int originalTrackId: trackId
property int originalX: x
property int originalDuration: clipDuration
property int lastValidDuration: clipDuration
property int draggedX: x
property int a_trackPos: -1
property bool selected: false
property double speed: 1.0
property color color: displayRect.color
......@@ -69,10 +68,6 @@ Item {
signal trimmingOut(var clip, real newDuration, var mouse)
signal trimmedOut(var clip)
onTrackHeightChanged: {
a_trackPos = root.getTrackYFromId(a_track) - trackRoot.mapToItem(null, 0, 0).y + ruler.height
}
onModelStartChanged: {
x = modelStart * timeScale;
}
......@@ -93,9 +88,6 @@ Item {
isAudio = track.isAudio
displayHeight = track.height / 2
}
onA_trackChanged: {
a_trackPos = root.getTrackYFromId(a_track) - trackRoot.mapToItem(null, 0, 0).y + ruler.height
}
SystemPalette { id: activePalette }
Rectangle {
......@@ -311,11 +303,11 @@ Item {
GradientStop { position: 0.0; color: selected ? 'red' : 'mediumpurple' }
GradientStop { position: 1.0; color: "#00000000" }
}
y: a_trackPos
y: root.getTrackYFromId(compositionRoot.aTrack) - trackRoot.mapToItem(null, 0, 0).y + ruler.height
height: clabel.height + 4
Text {
id: clabel
text: a_track
text: timeline.getTrackName(compositionRoot.aTrack)
font.pixelSize: root.baseUnit
anchors {
top: parent.top
......
......@@ -105,7 +105,7 @@ Column{
Binding {
target: loader.item
property: "a_track"
property: "aTrack"
value: model.a_track
when: loader.status == Loader.Ready && loader.item.isComposition
}
......@@ -162,7 +162,7 @@ Column{
item.fadeOut = model.fadeOut
item.hasAudio = model.hasAudio
} else {
item.a_track = model.a_track
item.aTrack = model.a_track
}
item.trackIndex= trackRoot.DelegateModel.itemsIndex
item.trackId= trackRoot.trackId
......
......@@ -30,6 +30,7 @@
#include "kdenlivesettings.h"
#include "project/projectmanager.h"
#include "timeline2/model/timelineitemmodel.hpp"
#include "timeline2/model/trackmodel.hpp"
#include "timelinewidget.h"
#include "utils/KoIconUtils.h"
......@@ -92,6 +93,14 @@ double TimelineController::scaleFactor() const
return m_scale;
}
const QString TimelineController::getTrackName(int trackId)
{
if (trackId == -1) {
return i18n("unknown");
}
return m_model->getTrackById(trackId)->getProperty("kdenlive:track_name").toString();
}
void TimelineController::setScaleFactor(double scale)
{
/*if (m_duration * scale < width() - 160) {
......
......@@ -199,6 +199,8 @@ public:
/* @brief Request a Fade in effect for clip
*/
Q_INVOKABLE void adjustFade(int cid, const QString &effectId, int duration);
Q_INVOKABLE const QString getTrackName(int trackId);
/* @brief Seeks to selected clip start / end
*/
void seekCurrentClip(bool seekToEnd = false);
......
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