]> git.sesse.net Git - kdenlive/blobdiff - src/kdenlivedoc.cpp
Add center-crop option to slideshow clip.
[kdenlive] / src / kdenlivedoc.cpp
index 2e0b13aca5df3ed8b5a4d12e90ed9d758113e10b..88cb4712054024d30998784743693909fba0c395 100644 (file)
@@ -114,13 +114,13 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                         // Build tracks
                         QDomElement e;
                         QDomElement tracksinfo = infoXml.firstChildElement("tracksinfo");
-                        TrackInfo projectTrack;
                         if (!tracksinfo.isNull()) {
                             QDomNodeList trackslist = tracksinfo.childNodes();
                             int maxchild = trackslist.count();
                             for (int k = 0; k < maxchild; k++) {
                                 e = trackslist.at(k).toElement();
                                 if (e.tagName() == "trackinfo") {
+                                    TrackInfo projectTrack;
                                     if (e.attribute("type") == "audio") projectTrack.type = AUDIOTRACK;
                                     else projectTrack.type = VIDEOTRACK;
                                     projectTrack.isMute = e.attribute("mute").toInt();
@@ -203,9 +203,20 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
         m_document = createEmptyDocument(tracks.x(), tracks.y());
     }
 
+    // Set the video profile (empty == default)
     KdenliveSettings::setCurrent_profile(profilePath());
 
-    // Set the video profile (empty == default)
+    // Ask to create the project directory if it does not exist
+    if (!QFile::exists(m_projectFolder.path())) {
+        int create = KMessageBox::questionYesNo(parent, i18n("Project directory %1 does not exist. Create it?", m_projectFolder.path()));
+        if (create == KMessageBox::Yes) {
+            QDir projectDir(m_projectFolder.path());
+            bool ok = projectDir.mkpath(m_projectFolder.path());
+            if (!ok) {
+                KMessageBox::sorry(parent, i18n("The directory %1, could not be created.\nPlease make sure you have the required permissions.", m_projectFolder.path()));
+            }
+        }
+    }
 
     // Make sure the project folder is usable
     if (m_projectFolder.isEmpty() || !KIO::NetAccess::exists(m_projectFolder.path(), KIO::NetAccess::DestinationSide, parent)) {
@@ -218,10 +229,6 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
     KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/");
     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(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()));
 }
@@ -255,29 +262,27 @@ int KdenliveDoc::setSceneList()
 
 QDomDocument KdenliveDoc::createEmptyDocument(int videotracks, int audiotracks)
 {
-    TrackInfo videoTrack;
-    videoTrack.type = VIDEOTRACK;
-    videoTrack.isMute = false;
-    videoTrack.isBlind = false;
-    videoTrack.isLocked = false;
-
-    TrackInfo audioTrack;
-    audioTrack.type = AUDIOTRACK;
-    audioTrack.isMute = false;
-    audioTrack.isBlind = true;
-    audioTrack.isLocked = false;
-
     m_tracksList.clear();
 
     // Tracks are added «backwards», so we need to reverse the track numbering
     // mbt 331: http://www.kdenlive.org/mantis/view.php?id=331
     // Better default names for tracks: Audio 1 etc. instead of blank numbers
     for (int i = 0; i < audiotracks; i++) {
+        TrackInfo audioTrack;
+        audioTrack.type = AUDIOTRACK;
+        audioTrack.isMute = false;
+        audioTrack.isBlind = true;
+        audioTrack.isLocked = false;
         audioTrack.trackName = QString("Audio ") + QString::number(audiotracks - i);
         m_tracksList.append(audioTrack);
 
     }
     for (int i = 0; i < videotracks; i++) {
+        TrackInfo videoTrack;
+        videoTrack.type = VIDEOTRACK;
+        videoTrack.isMute = false;
+        videoTrack.isBlind = false;
+        videoTrack.isLocked = false;
         videoTrack.trackName = QString("Video ") + QString::number(videotracks - i);
         m_tracksList.append(videoTrack);
     }
@@ -489,7 +494,7 @@ bool KdenliveDoc::saveSceneList(const QString &path, const QString &scene)
     QDomElement mlt = sceneList.firstChildElement("mlt");
     if (mlt.isNull() || !mlt.hasChildNodes()) {
         //Make sure we don't save if scenelist is corrupted
-        KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
+        KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1, scene list is corrupted.", path));
         return false;
     }
     QDomElement addedXml = sceneList.createElement("kdenlivedoc");
@@ -709,8 +714,7 @@ bool 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(m_fps, true);
-    else m_timecode.setFormat(m_fps);
+    m_timecode.setFormat(m_fps);
     return (current_fps != m_fps);
 }
 
@@ -1070,9 +1074,9 @@ void KdenliveDoc::slotCreateColorClip(const QString &name, const QString &color,
     emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
 }
 
-void KdenliveDoc::slotCreateSlideshowClipFile(const QString name, const QString path, int count, const QString duration, const bool loop, const bool fade, const QString &luma_duration, const QString &luma_file, const int softness, QString group, const QString &groupId)
+void KdenliveDoc::slotCreateSlideshowClipFile(const QString name, const QString path, int count, const QString duration, const bool loop, const bool crop, const bool fade, const QString &luma_duration, const QString &luma_file, const int softness, QString group, const QString &groupId)
 {
-    m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, fade, luma_duration, luma_file, softness, group, groupId);
+    m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, crop, fade, luma_duration, luma_file, softness, group, groupId);
     setModified(true);
     emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
 }
@@ -1112,26 +1116,46 @@ int KdenliveDoc::tracksCount() const
 
 TrackInfo KdenliveDoc::trackInfoAt(int ix) const
 {
+    if (ix < 0 || ix >= m_tracksList.count()) {
+        kWarning() << "Track INFO outisde of range";
+        return TrackInfo();
+    }
     return m_tracksList.at(ix);
 }
 
 void KdenliveDoc::switchTrackAudio(int ix, bool hide)
 {
+    if (ix < 0 || ix >= m_tracksList.count()) {
+        kWarning() << "SWITCH Track outisde of range";
+        return;
+    }
     m_tracksList[ix].isMute = hide; // !m_tracksList.at(ix).isMute;
 }
 
 void KdenliveDoc::switchTrackLock(int ix, bool lock)
 {
+    if (ix < 0 || ix >= m_tracksList.count()) {
+        kWarning() << "Track Lock outisde of range";
+        return;
+    }
     m_tracksList[ix].isLocked = lock;
 }
 
 bool KdenliveDoc::isTrackLocked(int ix) const
 {
+    if (ix < 0 || ix >= m_tracksList.count()) {
+        kWarning() << "Track Lock outisde of range";
+        return true;
+    }
     return m_tracksList.at(ix).isLocked;
 }
 
 void KdenliveDoc::switchTrackVideo(int ix, bool hide)
 {
+    if (ix < 0 || ix >= m_tracksList.count()) {
+        kWarning() << "SWITCH Track outisde of range";
+        return;
+    }
     m_tracksList[ix].isBlind = hide; // !m_tracksList.at(ix).isBlind;
 }
 
@@ -1143,11 +1167,19 @@ void KdenliveDoc::insertTrack(int ix, TrackInfo type)
 
 void KdenliveDoc::deleteTrack(int ix)
 {
+    if (ix < 0 || ix >= m_tracksList.count()) {
+        kWarning() << "Delete Track outisde of range";
+        return;
+    }
     m_tracksList.removeAt(ix);
 }
 
 void KdenliveDoc::setTrackType(int ix, TrackInfo type)
 {
+    if (ix < 0 || ix >= m_tracksList.count()) {
+        kWarning() << "SET Track Type outisde of range";
+        return;
+    }
     m_tracksList[ix].type = type.type;
     m_tracksList[ix].isMute = type.isMute;
     m_tracksList[ix].isBlind = type.isBlind;
@@ -1234,5 +1266,79 @@ const QString KdenliveDoc::getDocumentProperty(const QString &name) const
     return m_documentProperties.value(name);
 }
 
+QMap <QString, QString> KdenliveDoc::getRenderProperties() const
+{
+    QMap <QString, QString> renderProperties;
+    QMapIterator<QString, QString> i(m_documentProperties);
+    while (i.hasNext()) {
+        i.next();
+        if (i.key().startsWith("render")) renderProperties.insert(i.key(), i.value());
+    }
+    return renderProperties;
+}
+
+void KdenliveDoc::addTrackEffect(int ix, QDomElement effect)
+{
+    if (ix < 0 || ix >= m_tracksList.count()) {
+        kWarning() << "Add Track effect outisde of range";
+        return;
+    }
+    effect.setAttribute("kdenlive_ix", m_tracksList.at(ix).effectsList.count() + 1);
+    m_tracksList[ix].effectsList.append(effect);
+}
+
+void KdenliveDoc::removeTrackEffect(int ix, QDomElement effect)
+{
+    if (ix < 0 || ix >= m_tracksList.count()) {
+        kWarning() << "Remove Track effect outisde of range";
+        return;
+    }
+    QString index;
+    QString toRemove = effect.attribute("kdenlive_ix");
+    for (int i = 0; i < m_tracksList.at(ix).effectsList.count(); ++i) {
+        index = m_tracksList.at(ix).effectsList.at(i).attribute("kdenlive_ix");
+        if (toRemove == index) {
+            m_tracksList[ix].effectsList.removeAt(i);
+            i--;
+        } else if (index.toInt() > toRemove.toInt()) {
+            m_tracksList[ix].effectsList.item(i).setAttribute("kdenlive_ix", index.toInt() - 1);
+        }
+    }
+}
+
+void KdenliveDoc::setTrackEffect(int trackIndex, int effectIndex, QDomElement effect)
+{
+    if (trackIndex < 0 || trackIndex >= m_tracksList.count()) {
+        kWarning() << "Set Track effect outisde of range";
+        return;
+    }
+    if (effectIndex < 0 || effectIndex > (m_tracksList.at(trackIndex).effectsList.count() - 1) || effect.isNull()) {
+        kDebug() << "Invalid effect index: " << effectIndex;
+        return;
+    }
+    effect.setAttribute("kdenlive_ix", effectIndex + 1);
+    m_tracksList[trackIndex].effectsList.replace(effectIndex, effect);
+}
+
+const EffectsList KdenliveDoc::getTrackEffects(int ix)
+{
+    if (ix < 0 || ix >= m_tracksList.count()) {
+        kWarning() << "Get Track effects outisde of range";
+        return EffectsList();
+    }
+    return m_tracksList.at(ix).effectsList;
+}
+
+QDomElement KdenliveDoc::getTrackEffect(int trackIndex, int effectIndex) const
+{
+    if (trackIndex < 0 || trackIndex >= m_tracksList.count()) {
+        kWarning() << "Get Track effect outisde of range";
+        return QDomElement();
+    }
+    EffectsList list = m_tracksList.at(trackIndex).effectsList;
+    if (effectIndex > list.count() - 1 || effectIndex < 0 || list.at(effectIndex).isNull()) return QDomElement();
+    return list.at(effectIndex).cloneNode().toElement();
+}
+
 #include "kdenlivedoc.moc"