Fix crash when creating project without audio tracks

parent 5a6235b1
...@@ -351,7 +351,6 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks) ...@@ -351,7 +351,6 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks)
QDomElement mlt = doc.createElement("mlt"); QDomElement mlt = doc.createElement("mlt");
mlt.setAttribute("LC_NUMERIC", ""); mlt.setAttribute("LC_NUMERIC", "");
doc.appendChild(mlt); doc.appendChild(mlt);
// Create black producer // Create black producer
// For some unknown reason, we have to build the black producer here and not in renderer.cpp, otherwise // For some unknown reason, we have to build the black producer here and not in renderer.cpp, otherwise
// the composite transitions with the black track are corrupted. // the composite transitions with the black track are corrupted.
...@@ -419,7 +418,6 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks) ...@@ -419,7 +418,6 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks)
//QDomElement multitrack = doc.createElement("multitrack"); //QDomElement multitrack = doc.createElement("multitrack");
QDomElement playlist = doc.createElement("playlist"); QDomElement playlist = doc.createElement("playlist");
playlist.setAttribute("id", "black_track"); playlist.setAttribute("id", "black_track");
mlt.appendChild(playlist); mlt.appendChild(playlist);
QDomElement blank0 = doc.createElement("entry"); QDomElement blank0 = doc.createElement("entry");
...@@ -430,12 +428,11 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks) ...@@ -430,12 +428,11 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks)
// create playlists // create playlists
int total = tracks.count(); int total = tracks.count();
for (int i = 0; i < total; ++i) {
for (int i = 1; i <= total; ++i) {
QDomElement playlist = doc.createElement("playlist"); QDomElement playlist = doc.createElement("playlist");
playlist.setAttribute("id", "playlist" + QString::number(i)); playlist.setAttribute("id", "playlist" + QString::number(i+1));
playlist.setAttribute("kdenlive:track_name", tracks.at(i-1).trackName); playlist.setAttribute("kdenlive:track_name", tracks.at(i).trackName);
if (tracks.at(i-1).type == AudioTrack) { if (tracks.at(i).type == AudioTrack) {
playlist.setAttribute("kdenlive:audio_track", 1); playlist.setAttribute("kdenlive:audio_track", 1);
} }
mlt.appendChild(playlist); mlt.appendChild(playlist);
...@@ -446,26 +443,25 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks) ...@@ -446,26 +443,25 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks)
tractor.appendChild(track0); tractor.appendChild(track0);
// create audio and video tracks // create audio and video tracks
for (int i = 1; i <= total; ++i) { for (int i = 0; i < total; ++i) {
QDomElement track = doc.createElement("track"); QDomElement track = doc.createElement("track");
track.setAttribute("producer", "playlist" + QString::number(i)); track.setAttribute("producer", "playlist" + QString::number(i+1));
if (tracks.at(i-1).type == AudioTrack) { if (tracks.at(i).type == AudioTrack) {
track.setAttribute("hide", "video"); track.setAttribute("hide", "video");
} else if (tracks.at(i-1).isBlind) { } else if (tracks.at(i).isBlind) {
if (tracks.at(i-1).isMute) { if (tracks.at(i).isMute) {
track.setAttribute("hide", "all"); track.setAttribute("hide", "all");
} }
else track.setAttribute("hide", "video"); else track.setAttribute("hide", "video");
} }
else if (tracks.at(i-1).isMute) else if (tracks.at(i).isMute)
track.setAttribute("hide", "audio"); track.setAttribute("hide", "audio");
tractor.appendChild(track); tractor.appendChild(track);
} }
for (int i = 1; i <= total; i++) { for (int i = 0; i < total; i++) {
QDomElement transition = doc.createElement("transition"); QDomElement transition = doc.createElement("transition");
transition.setAttribute("always_active", "1"); transition.setAttribute("always_active", "1");
QDomElement property = doc.createElement("property"); QDomElement property = doc.createElement("property");
property.setAttribute("name", "mlt_service"); property.setAttribute("name", "mlt_service");
value = doc.createTextNode("mix"); value = doc.createTextNode("mix");
...@@ -480,7 +476,7 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks) ...@@ -480,7 +476,7 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks)
property = doc.createElement("property"); property = doc.createElement("property");
property.setAttribute("name", "b_track"); property.setAttribute("name", "b_track");
value = doc.createTextNode(QString::number(i)); value = doc.createTextNode(QString::number(i + 1));
property.appendChild(value); property.appendChild(value);
transition.appendChild(property); transition.appendChild(property);
...@@ -497,8 +493,7 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks) ...@@ -497,8 +493,7 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks)
transition.appendChild(property); transition.appendChild(property);
tractor.appendChild(transition); tractor.appendChild(transition);
if (i > 0 && tracks.at(i).type == VideoTrack && tracks.at(i-1).type == VideoTrack) {
if (tracks.at(i-1).type == VideoTrack && tracks.at(i-2).type == VideoTrack) {
// Only add composite transition if both tracks are video // Only add composite transition if both tracks are video
transition = doc.createElement("transition"); transition = doc.createElement("transition");
property = doc.createElement("property"); property = doc.createElement("property");
...@@ -508,12 +503,12 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks) ...@@ -508,12 +503,12 @@ QDomDocument KdenliveDoc::createEmptyDocument(const QList <TrackInfo> &tracks)
property = doc.createElement("property"); property = doc.createElement("property");
property.setAttribute("name", "a_track"); property.setAttribute("name", "a_track");
property.appendChild(doc.createTextNode(QString::number(i-1))); property.appendChild(doc.createTextNode(QString::number(i)));
transition.appendChild(property); transition.appendChild(property);
property = doc.createElement("property"); property = doc.createElement("property");
property.setAttribute("name", "b_track"); property.setAttribute("name", "b_track");
property.appendChild(doc.createTextNode(QString::number(i))); property.appendChild(doc.createTextNode(QString::number(i+1)));
transition.appendChild(property); transition.appendChild(property);
property = doc.createElement("property"); property = doc.createElement("property");
......
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