+void TrackView::parseDocument(QDomDocument doc) {
+ int cursorPos = 0;
+ m_documentErrors = QString();
+ // kDebug() << "//// DOCUMENT: " << doc.toString();
+ /*QDomNode props = doc.elementsByTagName("properties").item(0);
+ if (!props.isNull()) {
+ cursorPos = props.toElement().attribute("timeline_position").toInt();
+ }*/
+
+ // parse project tracks
+ QDomNodeList tracks = doc.elementsByTagName("track");
+ QDomNodeList playlists = doc.elementsByTagName("playlist");
+ int duration = 300;
+ m_projectTracks = tracks.count();
+ int trackduration = 0;
+ QDomElement e;
+ QDomElement p;
+
+ int pos = m_projectTracks - 1;
+
+
+ for (int i = 0; i < m_projectTracks; i++) {
+ e = tracks.item(i).toElement();
+ QString playlist_name = e.attribute("producer");
+ if (playlist_name != "black_track" && playlist_name != "playlistmain") {
+ // find playlist related to this track
+ p = QDomElement();
+ for (int j = 0; j < m_projectTracks; j++) {
+ p = playlists.item(j).toElement();
+ if (p.attribute("id") == playlist_name) break;
+ }
+ if (e.attribute("hide") == "video") {
+ m_doc->switchTrackVideo(i - 1, true);
+ } else if (e.attribute("hide") == "audio") {
+ m_doc->switchTrackAudio(i - 1, true);
+ } else if (e.attribute("hide") == "both") {
+ m_doc->switchTrackVideo(i - 1, true);
+ m_doc->switchTrackAudio(i - 1, true);
+ }
+ trackduration = slotAddProjectTrack(pos, p);
+ pos--;
+ //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
+ if (trackduration > duration) duration = trackduration;
+ } else {
+ // background black track
+ for (int j = 0; j < m_projectTracks; j++) {
+ p = playlists.item(j).toElement();
+ if (p.attribute("id") == playlist_name) break;
+ }
+ int black_clips = p.childNodes().count();
+ for (int i = 0; i < black_clips; i++)
+ m_doc->loadingProgressed();
+ qApp->processEvents();
+ pos--;
+ }
+ }
+
+ // parse transitions
+ QDomNodeList transitions = doc.elementsByTagName("transition");
+ int projectTransitions = transitions.count();
+ //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
+ for (int i = 0; i < projectTransitions; i++) {
+ e = transitions.item(i).toElement();
+ QDomNodeList transitionparams = e.childNodes();
+ bool transitionAdd = true;
+ int a_track = 0;
+ int b_track = 0;
+ bool isAutomatic = false;
+ bool forceTrack = false;
+ QString mlt_geometry;
+ QString mlt_service;
+ for (int k = 0; k < transitionparams.count(); k++) {
+ p = transitionparams.item(k).toElement();
+ if (!p.isNull()) {
+ QString paramName = p.attribute("name");
+ // do not add audio mixing transitions
+ if (paramName == "internal_added" && p.text() == "237") {
+ transitionAdd = false;
+ //kDebug() << "// TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
+ //break;
+ } else if (paramName == "a_track") a_track = p.text().toInt();
+ else if (paramName == "b_track") b_track = p.text().toInt();
+ else if (paramName == "mlt_service") mlt_service = p.text();
+ else if (paramName == "geometry") mlt_geometry = p.text();
+ else if (paramName == "automatic" && p.text() == "1") isAutomatic = true;
+ else if (paramName == "force_track" && p.text() == "1") forceTrack = true;
+ }
+ }
+ if (transitionAdd || mlt_service != "mix") {
+ // Transition should be added to the scene
+ ItemInfo transitionInfo;
+ QString transitionId;
+ if (mlt_service == "composite") {
+ // When adding composite transition, check if it is a wipe transition
+ if (mlt_geometry == "0%,0%:100%x100%") transitionId = "alphatransparency";
+ else if (mlt_geometry.count(';') == 1) {
+ mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
+ mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
+ QString start = mlt_geometry.section(';', 0, 0);
+ start = start.section(':', 0, 1);
+ start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
+ QString end = mlt_geometry.section('=', 1, 1);
+ end = end.section(':', 0, 1);
+ end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
+ start.append(',' + end);
+ QStringList numbers = start.split(',', QString::SkipEmptyParts);
+ bool isWipeTransition = true;
+ int checkNumber;
+ for (int i = 0; i < numbers.size(); ++i) {
+ checkNumber = qAbs(numbers.at(i).toInt());
+ if (checkNumber != 0 && checkNumber != 100) {
+ isWipeTransition = false;
+ break;
+ }
+ }
+ if (isWipeTransition) transitionId = "wipe";
+ }
+ }
+ QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, transitionId).cloneNode().toElement();
+
+ for (int k = 0; k < transitionparams.count(); k++) {
+ p = transitionparams.item(k).toElement();
+ if (!p.isNull()) {
+ QString paramName = p.attribute("name");
+ QString paramValue = p.text();
+
+ QDomNodeList params = base.elementsByTagName("parameter");
+ if (paramName != "a_track" && paramName != "b_track") for (int i = 0; i < params.count(); i++) {
+ QDomElement e = params.item(i).toElement();
+ if (!e.isNull() && e.attribute("tag") == paramName) {
+ if (e.attribute("type") == "double") {
+ QString factor = e.attribute("factor", "1");
+ if (factor != "1") {
+ double val = paramValue.toDouble() * factor.toDouble();
+ paramValue = QString::number(val);
+ }
+ }
+ e.setAttribute("value", paramValue);
+ break;
+ }
+ }
+ }
+ }
+
+ /*QDomDocument doc;
+ doc.appendChild(doc.importNode(base, true));
+ kDebug() << "/////// TRANSITION XML: "<< doc.toString();*/
+
+ transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
+ transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
+ transitionInfo.track = m_projectTracks - 1 - b_track;
+ //kDebug() << "/////////////// +++++++++++ ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
+ Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
+ if (forceTrack) tr->setForcedTrack(true, a_track);
+ m_scene->addItem(tr);
+ }
+ }
+
+ // Add guides
+ QDomNodeList guides = doc.elementsByTagName("guide");
+ for (int i = 0; i < guides.count(); i++) {
+ e = guides.item(i).toElement();
+ const QString comment = e.attribute("comment");
+ const GenTime pos = GenTime(e.attribute("time").toDouble());
+ m_trackview->addGuide(pos, comment);
+ }
+
+ m_trackview->setDuration(duration);
+ kDebug() << "/////////// TOTAL PROJECT DURATION: " << duration;
+ slotRebuildTrackHeaders();
+ if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
+ //m_trackview->setCursorPos(cursorPos);
+ //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());