]> git.sesse.net Git - kdenlive/blobdiff - src/mainwindow.cpp
initial work for titleproducer
[kdenlive] / src / mainwindow.cpp
index 1125799a3d89b626cd9f7b8796d4fab755cb6316..106851e4df0d7faf0604ac1040d5f57b081cd1e2 100644 (file)
@@ -176,7 +176,7 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent
                        actionCollection());
     readOptions();
 
-    slotDetectAudioDriver();
+    //slotDetectAudioDriver();
 
     m_clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
     m_clipMonitorDock->setObjectName("clip_monitor");
@@ -495,17 +495,19 @@ void MainWindow::generateClip()
     }
 }
 
-void MainWindow::saveProperties(KConfig*)
+void MainWindow::saveProperties(KConfigGroup &config)
 {
     // save properties here,used by session management
     saveFile();
+    KMainWindow::saveProperties(config);
 }
 
 
-void MainWindow::readProperties(KConfig *config)
+void MainWindow::readProperties(const KConfigGroup &config)
 {
     // read properties here,used by session management
-    QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
+    KMainWindow::readProperties(config);
+    QString Lastproject = config.group("Recent Files").readPathEntry("File1", QString());
     openFile(KUrl(Lastproject));
 }
 
@@ -788,7 +790,6 @@ void MainWindow::setupActions()
     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
     statusBar()->addPermanentWidget(m_timecodeFormat);
     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
-    m_messageLabel->hide();
 
     collection->addAction("select_tool", m_buttonSelectTool);
     collection->addAction("razor_tool", m_buttonRazorTool);
@@ -1235,6 +1236,7 @@ void MainWindow::slotRunWizard()
 
 void MainWindow::newFile(bool showProjectSettings)
 {
+    if (!m_timelineArea->isEnabled()) return;
     QString profileName;
     KUrl projectFolder;
     QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
@@ -1257,8 +1259,17 @@ void MainWindow::newFile(bool showProjectSettings)
     }
     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks, m_projectMonitor->render, this);
     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
-    TrackView *trackView = new TrackView(doc, this);
+    bool ok;
+    TrackView *trackView = new TrackView(doc, &ok, this);
     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
+    if (!ok) {
+        // MLT is broken
+        m_timelineArea->setEnabled(false);
+        m_projectList->setEnabled(false);
+        m_monitorManager->slotBlockMonitors();
+        slotPreferences(6);
+        return;
+    }
     if (m_timelineArea->count() == 1) {
         connectDocumentInfo(doc);
         connectDocument(trackView, doc);
@@ -1268,7 +1279,7 @@ void MainWindow::newFile(bool showProjectSettings)
 
 void MainWindow::activateDocument()
 {
-    if (m_timelineArea->currentWidget() == NULL) return;
+    if (m_timelineArea->currentWidget() == NULL || !m_timelineArea->isEnabled()) return;
     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
     KdenliveDoc *currentDoc = currentTab->document();
     connectDocumentInfo(currentDoc);
@@ -1434,6 +1445,7 @@ void MainWindow::openFile(const KUrl &url)
 
 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale)
 {
+    if (!m_timelineArea->isEnabled()) return;
     KdenliveDoc *doc = new KdenliveDoc(url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, this);
     if (stale == NULL) {
         stale = new KAutoSaveFile(url, doc);
@@ -1445,8 +1457,16 @@ void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale)
         stale->setParent(doc);
     }
     connectDocumentInfo(doc);
-    TrackView *trackView = new TrackView(doc, this);
+    bool ok;
+    TrackView *trackView = new TrackView(doc, &ok, this);
     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
+    if (!ok) {
+        m_timelineArea->setEnabled(false);
+        m_projectList->setEnabled(false);
+        m_monitorManager->slotBlockMonitors();
+        slotPreferences(6);
+        return;
+    }
     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
     trackView->setDuration(trackView->duration());
     trackView->projectView()->initCursorPos(m_projectMonitor->render->seekPosition().frames(doc->fps()));
@@ -1554,6 +1574,9 @@ void MainWindow::slotEditProfiles()
 
 void MainWindow::slotDetectAudioDriver()
 {
+    /* WARNING: do not use this method because sometimes detects wrong driver (pulse instead of alsa),
+    leading to no audio output, see bug #934 */
+
     //decide which audio driver is really best, in some cases SDL is wrong
     if (KdenliveSettings::audiodrivername().isEmpty()) {
         QString driver;
@@ -1589,11 +1612,18 @@ void MainWindow::slotEditProjectSettings()
         if (m_activeDocument->profilePath() != profile) {
             // Profile was changed
             double dar = m_activeDocument->dar();
+           
+           // Deselect current effect / transition
+           m_effectStack->slotClipItemSelected(NULL, 0);
+           m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
+           
             m_activeDocument->setProfilePath(profile);
             KdenliveSettings::setCurrent_profile(profile);
             KdenliveSettings::setProject_fps(m_activeDocument->fps());
             setCaption(m_activeDocument->description(), m_activeDocument->isModified());
             m_monitorManager->resetProfiles(m_activeDocument->timecode());
+           m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeTimeline->tracksNumber());
+           m_effectStack->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode());
             if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
             m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
             m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList());
@@ -1610,16 +1640,15 @@ void MainWindow::slotRenderProject()
     if (!m_renderWidget) {
         QString projectfolder = m_activeDocument ? m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) : KdenliveSettings::defaultprojectfolder();
         m_renderWidget = new RenderWidget(projectfolder, this);
-        connect(m_renderWidget, SIGNAL(doRender(const QStringList&, const QStringList&)), this, SLOT(slotDoRender(const QStringList&, const QStringList&)));
-        connect(m_renderWidget, SIGNAL(selectedRenderProfile(const QString &, const QString &)), this, SLOT(slotSetDocumentRenderProfile(const QString &, const QString &)));
+        connect(m_renderWidget, SIGNAL(selectedRenderProfile(const QString &, const QString &, const QString&)), this, SLOT(slotSetDocumentRenderProfile(const QString &, const QString &, const QString&)));
         connect(m_renderWidget, SIGNAL(prepareRenderingData(bool, bool, const QString&)), this, SLOT(slotPrepareRendering(bool, bool, const QString&)));
         connect(m_renderWidget, SIGNAL(abortProcess(const QString &)), this, SIGNAL(abortRenderJob(const QString &)));
         connect(m_renderWidget, SIGNAL(openDvdWizard(const QString &, const QString &)), this, SLOT(slotDvdWizard(const QString &, const QString &)));
         if (m_activeDocument) {
             m_renderWidget->setProfile(m_activeDocument->mltProfile());
             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
-            m_renderWidget->setRenderProfile(m_activeDocument->getDocumentProperty("renderdestination"), m_activeDocument->getDocumentProperty("renderprofile"));
             m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
+            m_renderWidget->setRenderProfile(m_activeDocument->getDocumentProperty("renderdestination"), m_activeDocument->getDocumentProperty("renderprofile"), m_activeDocument->getDocumentProperty("renderurl"));
         }
     }
     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
@@ -1762,7 +1791,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //cha
     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
-    m_zoomSlider->setValue(doc->zoom());
+    m_zoomSlider->setValue(doc->zoom().x());
     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
@@ -1790,7 +1819,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //cha
         m_renderWidget->setProfile(doc->mltProfile());
         m_renderWidget->setGuides(doc->guidesXml(), doc->projectDuration());
         m_renderWidget->setDocumentPath(doc->projectFolder().path(KUrl::AddTrailingSlash));
-        m_renderWidget->setRenderProfile(doc->getDocumentProperty("renderdestination"), doc->getDocumentProperty("renderprofile"));
+        m_renderWidget->setRenderProfile(doc->getDocumentProperty("renderdestination"), doc->getDocumentProperty("renderprofile"), doc->getDocumentProperty("renderurl"));
     }
     //doc->setRenderer(m_projectMonitor->render);
     m_commandStack->setActiveStack(doc->commandStack());
@@ -1837,7 +1866,7 @@ void MainWindow::slotPreferences(int page, int option)
     // create it :
     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
-    connect(dialog, SIGNAL(doResetProfile()), this, SLOT(slotDetectAudioDriver()));
+    //connect(dialog, SIGNAL(doResetProfile()), this, SLOT(slotDetectAudioDriver()));
     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
     connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
     connect(dialog, SIGNAL(updateCaptureFolder()), m_recMonitor, SLOT(slotUpdateCaptureFolder()));
@@ -1934,7 +1963,7 @@ void MainWindow::slotAddClipMarker()
         if (m_activeTimeline) {
             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
             if (item) {
-                pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
+                pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
                 clip = item->baseClip();
             }
         }
@@ -1963,7 +1992,7 @@ void MainWindow::slotDeleteClipMarker()
         if (m_activeTimeline) {
             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
             if (item) {
-                pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
+                pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
                 clip = item->baseClip();
             }
         }
@@ -2016,7 +2045,7 @@ void MainWindow::slotEditClipMarker()
         if (m_activeTimeline) {
             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
             if (item) {
-                pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
+                pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
                 clip = item->baseClip();
             }
         }
@@ -2295,8 +2324,7 @@ void MainWindow::slotShowClipProperties(DocClipBase *clip)
 void MainWindow::customEvent(QEvent* e)
 {
     if (e->type() == QEvent::User) {
-        // The timeline playing position changed...
-        kDebug() << "RECEIVED JOG EVEMNT!!!";
+        m_messageLabel->setMessage(static_cast <MltErrorEvent *>(e)->message(), MltError);
     }
 }
 void MainWindow::slotActivateEffectStackView()
@@ -2476,6 +2504,7 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event)
     }
 }
 
+
 void MainWindow::slotSaveZone(Render *render, QPoint zone)
 {
     KDialog *dialog = new KDialog(this);
@@ -2676,11 +2705,12 @@ void MainWindow::slotTranscodeClip()
     slotTranscode(urls);
 }
 
-void MainWindow::slotSetDocumentRenderProfile(const QString &dest, const QString &name)
+void MainWindow::slotSetDocumentRenderProfile(const QString &dest, const QString &name, const QString &file)
 {
     if (m_activeDocument == NULL) return;
     m_activeDocument->setDocumentProperty("renderdestination", dest);
     m_activeDocument->setDocumentProperty("renderprofile", name);
+    m_activeDocument->setDocumentProperty("renderurl", file);
     m_activeDocument->setModified(true);
 }