]> git.sesse.net Git - kdenlive/commitdiff
Looks like I finally got the profile switching work!
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Thu, 13 Mar 2008 22:46:24 +0000 (22:46 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Thu, 13 Mar 2008 22:46:24 +0000 (22:46 +0000)
svn path=/branches/KDE4/; revision=2053

src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/mainwindow.cpp
src/mainwindow.h
src/monitor.cpp
src/monitor.h
src/monitormanager.cpp
src/monitormanager.h
src/profilesdialog.cpp
src/renderer.cpp
src/renderer.h

index fa83913fd818ddc12af6190fa8a5d46a5add3917..e01e86f18cabf0d2e1b3721439001c18a97e9630 100644 (file)
 
 #include "kdenlivedoc.h"
 #include "docclipbase.h"
+#include "profilesdialog.h"
+#include "kdenlivesettings.h"
 
-KdenliveDoc::KdenliveDoc(const KUrl &url, MltVideoProfile profile, QUndoGroup *undoGroup, QWidget *parent): QObject(parent), m_render(NULL), m_url(url), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack(undoGroup)) {
+KdenliveDoc::KdenliveDoc(const KUrl &url, MltVideoProfile profile, QUndoGroup *undoGroup, QWidget *parent): QObject(parent), m_render(NULL), m_url(url), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack(undoGroup)), m_modified(false) {
     m_clipManager = new ClipManager(this);
     if (!url.isEmpty()) {
         QString tmpFile;
@@ -36,6 +38,12 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, MltVideoProfile profile, QUndoGroup *u
             QFile file(tmpFile);
             m_document.setContent(&file, false);
             file.close();
+            QDomNode infoXmlNode = m_document.elementsByTagName("kdenlive").at(0);
+            if (!infoXmlNode.isNull()) {
+                QDomElement infoXml = infoXmlNode.toElement();
+                QString profilePath = infoXml.attribute("profile");
+                if (!profilePath.isEmpty()) setProfilePath(profilePath);
+            }
             KIO::NetAccess::removeTempFile(tmpFile);
         } else {
             KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
@@ -110,6 +118,15 @@ KdenliveDoc::~KdenliveDoc() {
     delete m_clipManager;
 }
 
+QDomElement KdenliveDoc::documentInfoXml() {
+    QDomDocument doc;
+    QDomElement addedXml = doc.createElement("kdenlive");
+    addedXml.setAttribute("version", "0.7");
+    addedXml.setAttribute("profile", profilePath());
+    return addedXml;
+}
+
+
 ClipManager *KdenliveDoc::clipManager() {
     return m_clipManager;
 }
@@ -124,6 +141,16 @@ QString KdenliveDoc::profilePath() const {
     return m_profile.path;
 }
 
+void KdenliveDoc::setProfilePath(QString path) {
+    KdenliveSettings::setCurrent_profile(path);
+    m_profile = ProfilesDialog::getVideoProfile(path);
+    m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
+    m_width = m_profile.width;
+    m_height = m_profile.height;
+    if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
+    else m_timecode.setFormat((int) m_fps);
+}
+
 void KdenliveDoc::setThumbsProgress(KUrl url, int progress) {
     emit thumbsProgress(url, progress);
 }
@@ -230,6 +257,11 @@ KUrl KdenliveDoc::url() const {
     return m_url;
 }
 
+void KdenliveDoc::setUrl(KUrl url) {
+    m_url = url;
+    m_modified = false;
+}
+
 QString KdenliveDoc::description() const {
     if (m_url.isEmpty())
         return i18n("Untitled") + " / " + m_profile.description;
index 738e3898d815255a1b68c05e1350425e67a64659..6d09167d00dc069d62cb632f7b57d4ba0397412c 100644 (file)
@@ -71,6 +71,9 @@ Q_OBJECT public:
     QString description() const;
     /** Returns the document format: PAL or NTSC */
     QString getDocumentStandard();
+    void setUrl(KUrl url);
+    QDomElement documentInfoXml();
+    void setProfilePath(QString path);
 
 private:
     KUrl m_url;
@@ -86,6 +89,8 @@ private:
     ClipManager *m_clipManager;
     MltVideoProfile m_profile;
     QString m_scenelist;
+    /** tells whether current doc has been changed since last save event */
+    bool m_modified;
 
 public slots:
 
index 8d443e1587db3b0e77345055a7956ac73452a006..4faeff4ff476d8384a67ef8a5a863a6e7e422d55 100644 (file)
@@ -42,7 +42,7 @@
 #include <kstandarddirs.h>
 #include <KUrlRequesterDialog>
 #include <KTemporaryFile>
-#include <kuiserverjobtracker.h>
+#include <ktogglefullscreenaction.h>
 
 #include <mlt++/Mlt.h>
 
@@ -64,7 +64,7 @@
 
 MainWindow::MainWindow(QWidget *parent)
         : KXmlGuiWindow(parent),
-        fileName(QString()), m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL) {
+        m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL) {
     parseProfiles();
 
     m_commandStack = new QUndoGroup;
@@ -202,6 +202,10 @@ bool MainWindow::queryClose() {
     }
 }
 
+void MainWindow::slotFullScreen() {
+    KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
+}
+
 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
     if (!m_activeDocument) return;
     if (effect.isNull()) {
@@ -293,7 +297,9 @@ void MainWindow::setupActions() {
     KStandardAction::redo(this, SLOT(redo()),
                           actionCollection());
 
-    connect(actionCollection(), SIGNAL(actionHighlighted(QAction*)),
+    KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
+
+    connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
             this, SLOT(slotDisplayActionMessage(QAction*)));
     //connect(actionCollection(), SIGNAL( clearStatusText() ),
     //statusBar(), SLOT( clear() ) );
@@ -365,27 +371,27 @@ void MainWindow::closeDocument(QWidget *w) {
 }
 
 void MainWindow::saveFileAs(const QString &outputFileName) {
-    KSaveFile file(outputFileName);
-    file.open();
-
-    QByteArray outputByteArray;
-    //outputByteArray.append(textArea->toPlainText());
-    file.write(outputByteArray);
-    file.finalize();
-    file.close();
-
-    fileName = outputFileName;
+    m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
+    m_activeDocument->setUrl(KUrl(outputFileName));
+    setCaption(m_activeDocument->description());
+    m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
+    m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
 }
 
 void MainWindow::saveFileAs() {
-    saveFileAs(KFileDialog::getSaveFileName());
+    QString outputFile = KFileDialog::getSaveFileName();
+    if (QFile::exists(outputFile)) {
+        if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
+    }
+    saveFileAs(outputFile);
 }
 
 void MainWindow::saveFile() {
-    if (!fileName.isEmpty()) {
-        saveFileAs(fileName);
-    } else {
+    if (!m_activeDocument) return;
+    if (m_activeDocument->url().isEmpty()) {
         saveFileAs();
+    } else {
+        saveFileAs(m_activeDocument->url().path());
     }
 }
 
@@ -468,7 +474,19 @@ void MainWindow::slotEditProfiles() {
 
 void MainWindow::slotEditProjectSettings() {
     ProjectSettings *w = new ProjectSettings;
-    w->exec();
+    if (w->exec() == QDialog::Accepted) {
+        QString profile = w->selectedProfile();
+        m_activeDocument->setProfilePath(profile);
+        m_monitorManager->resetProfiles(profile);
+        setCaption(m_activeDocument->description());
+        KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
+        if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
+        m_monitorManager->setTimecode(m_activeDocument->timecode());
+        m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
+
+        // We need to desactivate & reactivate monitors to get a refresh
+        m_monitorManager->switchMonitors();
+    }
     delete w;
 }
 
@@ -565,6 +583,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
 
 
     m_activeTimeline = trackView;
+    KdenliveSettings::setCurrent_profile(doc->profilePath());
     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
     m_monitorManager->setTimecode(doc->timecode());
     doc->setRenderer(m_projectMonitor->render);
index 95dfb2c9b2b0ddcad68681fcc6b41fe5a21edfab..3c2657f97651dcf28a1c1dd4fb2aafa5f3b9e4e2 100644 (file)
@@ -62,7 +62,6 @@ private:
     QProgressBar *statusProgressBar;
     QLabel* statusLabel;
     void setupActions();
-    QString fileName;
     KdenliveDoc *m_activeDocument;
     TrackView *m_activeTimeline;
     MonitorManager *m_monitorManager;
@@ -135,6 +134,7 @@ private slots:
     void slotSwitchAudioThumbs();
     void slotRenderProject();
     void slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter);
+    void slotFullScreen();
 };
 
 #endif
index 2c9dc4493ffe704b6e76f8243af82a96b0600b04..92982dfe0ef975421569fe4d0faae0c29a3c6a60 100644 (file)
@@ -67,6 +67,10 @@ Monitor::Monitor(QString name, MonitorManager *manager, QWidget *parent)
     kDebug() << "/////// BUILDING MONITOR, ID: " << ui.video_frame->winId();
 }
 
+QString Monitor::name() const {
+    return m_name;
+}
+
 // virtual
 void Monitor::mousePressEvent(QMouseEvent * event) {
     slotPlay();
@@ -223,9 +227,9 @@ void Monitor::resetProfile(QString prof) {
     render->resetProfile(prof);
 }
 
-void Monitor::saveSceneList(QString path) {
+void Monitor::saveSceneList(QString path, QDomElement e) {
     if (render == NULL) return;
-    render->saveSceneList(path);
+    render->saveSceneList(path, e);
 }
 
 void Monitor::paintEvent(QPaintEvent * event) {
index deaffa90bac78185febbcaf485b9eeb256d6a998..6297738143de96805abaa7477884d0590ff893de 100644 (file)
@@ -37,6 +37,7 @@ public:
     Monitor(QString name, MonitorManager *manager, QWidget *parent = 0);
     Render *render;
     void resetProfile(QString prof);
+    QString name() const;
 
     virtual void resizeEvent(QResizeEvent * event);
 protected:
@@ -74,7 +75,7 @@ public slots:
     void start();
     void activateMonitor();
     void slotPlay();
-    void saveSceneList(QString path);
+    void saveSceneList(QString path, QDomElement e = QDomElement());
 
 signals:
     void renderPosition(int);
index 3cad95b4e229bac35a37859efef29934323e2a6f..1765fa86cc4567ef0be401c32891741332050bf4 100644 (file)
@@ -59,13 +59,28 @@ void MonitorManager::activateMonitor(QString name) {
     m_activeMonitor = name;
 }
 
+void MonitorManager::switchMonitors() {
+    if (m_activeMonitor == "clip") {
+        m_clipMonitor->stop();
+        m_projectMonitor->start();
+        m_projectMonitor->raise();
+        m_activeMonitor = m_projectMonitor->name();
+        emit raiseClipMonitor(false);
+    } else {
+        m_projectMonitor->stop();
+        m_clipMonitor->start();
+        m_activeMonitor = m_clipMonitor->name();
+        emit raiseClipMonitor(true);
+    }
+}
+
 void MonitorManager::slotPlay() {
     if (m_activeMonitor == "clip") m_clipMonitor->slotPlay();
     else m_projectMonitor->slotPlay();
 }
 
 void MonitorManager::resetProfiles(QString prof) {
-    //m_clipMonitor->resetProfile(prof);
+    m_clipMonitor->resetProfile(prof);
     m_projectMonitor->resetProfile(prof);
 }
 
index 03eeaec6f42fbec606cfc7e9e65a329bffa3478e..c2160b1adc89a60f7f05a6e8a4e539cb71405f27 100644 (file)
@@ -35,6 +35,7 @@ public:
     Timecode timecode();
     void setTimecode(Timecode tc);
     void resetProfiles(QString prof);
+    void switchMonitors();
 
 public slots:
     void activateMonitor(QString name = QString::null);
index 6bec5c5badf1a48e3bbe3340a0840037470591f4..e85b0e45c48fafb5dcda4fb9e667a3f90341e101 100644 (file)
@@ -57,26 +57,30 @@ MltVideoProfile ProfilesDialog::getVideoProfile(QString name) {
     QStringList profilesFilter;
     profilesFilter << "*";
     QString path;
+    bool isCustom = false;
+    if (name.contains('/')) isCustom = true;
 
-    // List the Mlt profiles
-    profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
-    if (profilesFiles.contains(name)) path = KdenliveSettings::mltpath() + "/" + name;
-
-    if (path.isEmpty()) {
+    if (!isCustom) {
+        // List the Mlt profiles
+        profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
+        if (profilesFiles.contains(name)) path = KdenliveSettings::mltpath() + "/" + name;
+    }
+    if (isCustom  || path.isEmpty()) {
         // List custom profiles
-        QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
-        for (int i = 0; i < customProfiles.size(); ++i) {
-            profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
-            if (profilesFiles.contains(name)) {
-                path = customProfiles.at(i) + "/" + name;
-                break;
-            }
-        }
+        path = name;
+        /*        QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
+                for (int i = 0; i < customProfiles.size(); ++i) {
+                    profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
+                    if (profilesFiles.contains(name)) {
+                        path = customProfiles.at(i) + "/" + name;
+                        break;
+                    }
+                }*/
     }
 
     if (path.isEmpty()) return result;
     KConfig confFile(path);
-    result.path = path;
+    result.path = name;
     result.description = confFile.entryMap().value("description");
     result.frame_rate_num = confFile.entryMap().value("frame_rate_num").toInt();
     result.frame_rate_den = confFile.entryMap().value("frame_rate_den").toInt();
index d86af5a2288c193bc7e06aab70aaaf29b5e023e4..c7b0c109c6ab437d6a3425656638e5b6b51d79b5 100644 (file)
@@ -25,7 +25,7 @@
 // ffmpeg Header files
 
 extern "C" {
-#include <ffmpeg/avformat.h>
+#include <libavformat/avformat.h>
 }
 #include <QTimer>
 #include <QDir>
@@ -76,7 +76,7 @@ Render::Render(const QString & rendererName, int winid, int extid, QWidget *pare
         m_externalwinid = extid;
         m_winid = winid;
         m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
-        Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", "<westley><playlist><producer mlt_service=\"colour\" colour=\"blue\" /></playlist></westley>");
+        Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", "<westley><playlist><producer mlt_service=\"colour\" colour=\"blue\" in=\"0\" out=\"25\" /></playlist></westley>");
         m_mltProducer = producer;
         m_mltConsumer->connect(*m_mltProducer);
         m_mltProducer->set_speed(0.0);
@@ -120,16 +120,35 @@ int Render::resetProfile(QString profile) {
     if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
     m_mltConsumer->set("refresh", 0);
     m_mltConsumer->purge();
-    //TODO: we should also rebuild filters and delete existing m_mltProfile
+    delete m_mltConsumer;
+    m_mltConsumer = NULL;
+    QString scene = sceneList();
+    if (m_mltProducer) delete m_mltProducer;
+    m_mltProducer = NULL;
+    if (m_mltProfile) delete m_mltProfile;
+    m_mltProfile = NULL;
 
-    //delete m_mltProfile;
     m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
-    kDebug() << " ++++++++++ RESET CONSUMER WITH PROFILE: " << m_mltProfile->width();
+    m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer;
+    m_mltConsumer->set("resize", 1);
+    m_mltConsumer->set("window_id", m_winid);
+    m_mltConsumer->set("terminate_on_pause", 1);
+    m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
+
+    Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", (char *) scene.toUtf8().data());
+    m_mltProducer = producer;
+    m_mltConsumer->connect(*m_mltProducer);
+    m_mltProducer->set_speed(0.0);
+
+    //delete m_mltProfile;
     // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
     //mlt_profile prof = m_mltProfile->get_profile();
     //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
     //mlt_properties_set(properties, "profile", "hdv_1080_50i");
-    m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
+    //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
+    //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
+    kDebug() << " ++++++++++ RESET CONSUMER WITH PROFILE: " << profile << ", WIDTH: " << m_mltProfile->width();
+
     //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
     //refresh();
     return 1;
@@ -489,12 +508,7 @@ void Render::setSceneList(QString playlist, int position) {
 
     if (m_mltConsumer) {
         m_mltConsumer->set("refresh", 0);
-        if (!m_mltConsumer->is_stopped()) {
-            //emitConsumerStopped();
-            m_mltConsumer->stop();
-        }
-    }
-
+    } else return;
     if (m_mltProducer) {
         m_mltProducer->set_speed(0.0);
         //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
@@ -536,7 +550,7 @@ void Render::setSceneList(QString playlist, int position) {
 
     m_fps = m_mltProducer->get_fps();
     emit durationChanged(m_mltProducer->get_playtime());
-    //m_connectTimer->start( 500 );
+    //m_connectTimer->start( 1000 );
     connectPlaylist();
     m_generateScenelist = false;
 
@@ -544,16 +558,16 @@ void Render::setSceneList(QString playlist, int position) {
 
 /** Create the producer from the Westley QDomDocument */
 QString Render::sceneList() {
-    if (m_winid == -1) return QString();
     KTemporaryFile temp;
     QString result;
 
     if (temp.open()) {
         saveSceneList(temp.fileName());
         QFile file(temp.fileName());
-        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+        if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+            kWarning() << "++++++++++++++++   CANNOT READ TMP SCENELIST FILE";
             return QString();
-
+        }
         QTextStream in(&file);
         while (!in.atEnd()) {
             result.append(in.readLine());
@@ -562,7 +576,7 @@ QString Render::sceneList() {
     return result;
 }
 
-void Render::saveSceneList(QString path) {
+void Render::saveSceneList(QString path, QDomElement addedXml) {
     char *tmppath = decodedString("westley:" + path);
     Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
     delete[] tmppath;
@@ -570,6 +584,21 @@ void Render::saveSceneList(QString path) {
     Mlt::Producer prod(m_mltProducer->get_producer());
     westleyConsumer.connect(prod);
     westleyConsumer.start();
+    if (!addedXml.isNull()) {
+        // add Kdenlive specific tags
+        QFile file(path);
+        QDomDocument doc;
+        doc.setContent(&file, false);
+        doc.documentElement().appendChild(doc.importNode(addedXml, true));
+        file.close();
+        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+            kWarning() << "//////  ERROR writing to file: " << path;
+            return;
+        }
+        QTextStream out(&file);
+        out << doc.toString();
+        file.close();
+    }
 }
 
 
@@ -578,12 +607,13 @@ const double Render::fps() const {
 }
 
 void Render::connectPlaylist() {
-
+    if (!m_mltConsumer) return;
     m_connectTimer->stop();
+    m_mltConsumer->set("refresh", "0");
     m_mltConsumer->connect(*m_mltProducer);
     m_mltProducer->set_speed(0.0);
     m_mltConsumer->start();
-    //refresh();
+    refresh();
     /*
      if (m_mltConsumer->start() == -1) {
           KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it."));
index 7c8bd0317caf45748695258e5787c0c326811535..a63219f9ff4a4400c7c09af7fc37217f8bbdb741 100644 (file)
@@ -95,7 +95,7 @@ Q_OBJECT public:
     void setSceneList(QDomDocument list, int position = 0);
     void setSceneList(QString playlist, int position = 0);
     QString sceneList();
-    void saveSceneList(QString path);
+    void saveSceneList(QString path, QDomElement addedXml = QDomElement());
 
     /** Wraps the VEML command of the same name. Tells the renderer to
     play the current scene at the speed specified, relative to normal