]> git.sesse.net Git - kdenlive/blobdiff - src/kdenlivedoc.cpp
Clean up timecode handling, improves:
[kdenlive] / src / kdenlivedoc.cpp
index c4dd40c75b6adc23121ab3ceea9b9f175e3146b1..b109c9d72668ac1817315910a28e6bef7169dac2 100644 (file)
@@ -208,6 +208,8 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
         m_document = createEmptyDocument(tracks.x(), tracks.y());
     }
 
+    KdenliveSettings::setCurrent_profile(profilePath());
+
     // Set the video profile (empty == default)
 
     // Make sure the project folder is usable
@@ -222,8 +224,8 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
     KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/");
 
     kDebug() << "Kdenlive document, init timecode: " << m_fps;
-    if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
-    else m_timecode.setFormat((int) m_fps);
+    if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(m_fps, true);
+    else m_timecode.setFormat(m_fps);
 
     //kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
     connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
@@ -231,8 +233,11 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
 
 KdenliveDoc::~KdenliveDoc()
 {
+    m_autoSaveTimer->stop();
     delete m_commandStack;
+    kDebug() << "// DEL CLP MAN";
     delete m_clipManager;
+    kDebug() << "// DEL CLP MAN done";
     delete m_autoSaveTimer;
     if (m_autosave) {
         if (!m_autosave->fileName().isEmpty()) m_autosave->remove();
@@ -242,6 +247,7 @@ KdenliveDoc::~KdenliveDoc()
 
 int KdenliveDoc::setSceneList()
 {
+    m_render->resetProfile();
     if (m_render->setSceneList(m_document.toString(), m_documentProperties.value("position").toInt()) == -1) {
         // INVALID MLT Consumer, something is wrong
         return -1;
@@ -273,6 +279,53 @@ QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int a
     audioTrack.isBlind = true;
     audioTrack.isLocked = false;
 
+    // Create black producer
+    // 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.
+    QDomElement blk = doc.createElement("producer");
+    blk.setAttribute("in", 0);
+    blk.setAttribute("out", 500);
+    blk.setAttribute("id", "black");
+
+    QDomElement property = doc.createElement("property");
+    property.setAttribute("name", "mlt_type");
+    QDomText value = doc.createTextNode("producer");
+    property.appendChild(value);
+    blk.appendChild(property);
+
+    property = doc.createElement("property");
+    property.setAttribute("name", "aspect_ratio");
+    value = doc.createTextNode(QString::number(0.0));
+    property.appendChild(value);
+    blk.appendChild(property);
+
+    property = doc.createElement("property");
+    property.setAttribute("name", "length");
+    value = doc.createTextNode(QString::number(15000));
+    property.appendChild(value);
+    blk.appendChild(property);
+
+    property = doc.createElement("property");
+    property.setAttribute("name", "eof");
+    value = doc.createTextNode("pause");
+    property.appendChild(value);
+    blk.appendChild(property);
+
+    property = doc.createElement("property");
+    property.setAttribute("name", "resource");
+    value = doc.createTextNode("black");
+    property.appendChild(value);
+    blk.appendChild(property);
+
+    property = doc.createElement("property");
+    property.setAttribute("name", "mlt_service");
+    value = doc.createTextNode("colour");
+    property.appendChild(value);
+    blk.appendChild(property);
+
+    mlt.appendChild(blk);
+
+
     QDomElement tractor = doc.createElement("tractor");
     tractor.setAttribute("id", "maintractor");
     QDomElement multitrack = doc.createElement("multitrack");
@@ -280,6 +333,11 @@ QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int a
     playlist.setAttribute("id", "black_track");
     mlt.appendChild(playlist);
 
+    QDomElement blank0 = doc.createElement("entry");
+    blank0.setAttribute("in", "0");
+    blank0.setAttribute("out", "0");
+    blank0.setAttribute("producer", "black");
+    playlist.appendChild(blank0);
 
     // create playlists
     int total = audiotracks + videotracks + 1;
@@ -635,8 +693,8 @@ void KdenliveDoc::setProfilePath(QString path)
     m_width = m_profile.width;
     m_height = m_profile.height;
     kDebug() << "Kdenlive document, init timecode from path: " << path << ",  " << m_fps;
-    if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
-    else m_timecode.setFormat((int) m_fps);
+    if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(m_fps, true);
+    else m_timecode.setFormat(m_fps);
 }
 
 double KdenliveDoc::dar()
@@ -701,7 +759,7 @@ void KdenliveDoc::updateClip(const QString &id)
 
 int KdenliveDoc::getFramePos(QString duration)
 {
-    return m_timecode.getFrameCount(duration, m_fps);
+    return m_timecode.getFrameCount(duration);
 }
 
 QString KdenliveDoc::producerName(const QString &id)
@@ -803,7 +861,7 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
         if (elem.attribute("type").toInt() == SLIDESHOW) {
             extension = KUrl(path).fileName();
             path = KUrl(path).directory();
-        } else if (elem.attribute("type").toInt() == TEXT && QFile::exists(path) == false) {
+        } /*else if (elem.attribute("type").toInt() == TEXT && QFile::exists(path) == false) {
             kDebug() << "// TITLE: " << elem.attribute("name") << " Preview file: " << elem.attribute("resource") << " DOES NOT EXIST";
             QString titlename = elem.attribute("name");
             QString titleresource;
@@ -826,7 +884,7 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
             elem.setAttribute("resource", titleresource);
             setNewClipResource(clipId, titleresource);
             delete dia_ui;
-        }
+        }*/
 
         if (path.isEmpty() == false && QFile::exists(path) == false && elem.attribute("type").toInt() != TEXT && !elem.hasAttribute("placeholder")) {
             kDebug() << "// FOUND MISSING CLIP: " << path << ", TYPE: " << elem.attribute("type").toInt();
@@ -992,7 +1050,6 @@ void KdenliveDoc::deleteProjectClip(QList <QString> ids)
 void KdenliveDoc::deleteClip(const QString &clipId)
 {
     emit signalDeleteProjectClip(clipId);
-    m_clipManager->deleteClip(clipId);
 }
 
 void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId)
@@ -1038,13 +1095,13 @@ void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId, cons
 {
     QString titlesFolder = projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
     KStandardDirs::makeDir(titlesFolder);
-    TitleWidget *dia_ui = new TitleWidget(templatePath, titlesFolder, m_render, kapp->activeWindow());
+    TitleWidget *dia_ui = new TitleWidget(templatePath, m_timecode, titlesFolder, m_render, kapp->activeWindow());
     if (dia_ui->exec() == QDialog::Accepted) {
-        QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
+        /*QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
         QImage pix = dia_ui->renderedPixmap();
-        pix.save(titleInfo.at(1));
+        pix.save(titleInfo.at(1));*/
         //dia_ui->saveTitle(path + ".kdenlivetitle");
-        m_clipManager->slotAddTextClipFile(titleInfo.at(0), titleInfo.at(1), dia_ui->xml().toString(), group, groupId);
+        m_clipManager->slotAddTextClipFile(i18n("Title clip"), dia_ui->duration(), dia_ui->xml().toString(), group, groupId);
         setModified(true);
         emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
     }
@@ -1062,12 +1119,13 @@ void KdenliveDoc::slotCreateTextTemplateClip(QString group, const QString &group
 
     QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder(), true);
 
-    TitleWidget *dia_ui = new TitleWidget(path, titlesFolder, m_render, kapp->activeWindow());
+    //TODO: rewrite with new title system (just set resource)
+    /*TitleWidget *dia_ui = new TitleWidget(path, titlesFolder, m_render, kapp->activeWindow());
     QImage pix = dia_ui->renderedPixmap();
     pix.save(titleInfo.at(1));
     delete dia_ui;
     m_clipManager->slotAddTextTemplateClip(titleInfo.at(0), titleInfo.at(1), path, group, groupId);
-    setModified(true);
+    setModified(true);*/
     emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
 }