Commits

Anonymous committed 142e3e4

Implement deinterlacer and rescale options for MLT consumer

Comments (0)

Files changed (7)

src/kdenlivesettings.kcfg

       <label>Default category for newly created clip markers.</label>
       <default>0</default>
     </entry>
+    
+    <entry name="mltdeinterlacer" type="String">
+      <label>Name of the chosen deinterlacer.</label>
+      <default>onefield</default>
+    </entry>
+    
+    <entry name="mltinterpolation" type="String">
+      <label>Name of the chosen interpol method.</label>
+      <default>nearest</default>
+    </entry>
 
   </group>
 
 #include <KFileDialog>
 #include <KApplication>
 #include <KMessageBox>
+#include <KSelectAction>
 
 #include <QMouseEvent>
 #include <QStylePainter>
     showTips->setCheckable(true);
     connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
     showTips->setChecked(KdenliveSettings::displayMonitorInfo());
+    
+    KSelectAction *interlace = new KSelectAction(i18n("Deinterlacer"), this);
+    interlace->addAction(i18n("One Field (fast)"));
+    interlace->addAction(i18n("Linear Blend (fast)"));
+    interlace->addAction(i18n("YADIF - temporal only (good)"));
+    interlace->addAction(i18n("YADIF - temporal + spacial (best)"));
+    if (KdenliveSettings::mltdeinterlacer() == "linearblend") interlace->setCurrentItem(1);
+    else if (KdenliveSettings::mltdeinterlacer() == "yadif-temporal") interlace->setCurrentItem(2);
+    else if (KdenliveSettings::mltdeinterlacer() == "yadif") interlace->setCurrentItem(3);
+    else interlace->setCurrentItem(0);
+    connect(interlace, SIGNAL(triggered(int)), this, SLOT(slotSetDeinterlacer(int)));
+    
+    KSelectAction *interpol = new KSelectAction(i18n("Interpolation"), this);
+    interpol->addAction(i18n("Nearest Neighbor (fast)"));
+    interpol->addAction(i18n("Bilinear (good)"));
+    interpol->addAction(i18n("Bicubic (better)"));
+    interpol->addAction(i18n("Hyper/Lanczos (best)"));
+    if (KdenliveSettings::mltinterpolation() == "bilinear") interpol->setCurrentItem(1);
+    else if (KdenliveSettings::mltinterpolation() == "bicubic") interpol->setCurrentItem(2);
+    else if (KdenliveSettings::mltinterpolation() == "hyper") interpol->setCurrentItem(3);
+    else interpol->setCurrentItem(0);
+    connect(interpol, SIGNAL(triggered(int)), this, SLOT(slotSetInterpolation(int)));
 
     QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
     dropFrames->setCheckable(true);
     dropFrames->setChecked(true);
     connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
-
+    
     m_configMenu->addAction(showTips);
     m_configMenu->addAction(dropFrames);
+    m_configMenu->addAction(interlace);
+    m_configMenu->addAction(interpol);
 
 }
 
     render->setDropFrames(show);
 }
 
+void Monitor::slotSetDeinterlacer(int ix)
+{
+    QString value;
+    switch (ix) {
+      
+      case 1:
+	value = "linearblend";
+	break;
+      case 2:
+	value = "yadif-nospatial";
+	break;
+      case 3:
+	value = "yadif";
+	break;
+      default:
+	value = "onefield";
+    }
+    KdenliveSettings::setMltdeinterlacer(value);
+    m_monitorManager->setConsumerProperty("deinterlace_method", value);
+}
+
+void Monitor::slotSetInterpolation(int ix)
+{
+    QString value;
+    switch (ix) {
+      case 1:
+	value = "bilinear";
+	break;
+      case 2:
+	value = "bicubic";
+	break;
+      case 3:
+	value = "hyper";
+	break;
+      default:
+	value = "nearest";
+    }
+    KdenliveSettings::setMltinterpolation(value);
+    m_monitorManager->setConsumerProperty("rescale", value);
+}
+
+
 void Monitor::slotSwitchMonitorInfo(bool show)
 {
     KdenliveSettings::setDisplayMonitorInfo(show);
     void setClipZone(QPoint pos);
     void slotSwitchMonitorInfo(bool show);
     void slotSwitchDropFrames(bool show);
+    void slotSetDeinterlacer(int ix);
+    void slotSetInterpolation(int ix);
     void slotGoToMarker(QAction *action);
     void slotSetVolume(int volume);
     void slotShowVolume();

src/monitormanager.cpp

     return monitor;
 }
 
+void MonitorManager::setConsumerProperty(const QString &name, const QString &value)
+{
+    if (m_clipMonitor) m_clipMonitor->render->setConsumerProperty(name, value);
+    if (m_projectMonitor) m_projectMonitor->render->setConsumerProperty(name, value);
+}
+
 bool MonitorManager::activateMonitor(Kdenlive::MONITORID name, bool forceRefresh)
 {
     if (m_clipMonitor == NULL || m_projectMonitor == NULL)
     QString getProjectFolder() const;
     /** @brief Sets current document for later reference. */
     void setDocument(KdenliveDoc *doc);
+    /** @brief Change an MLT consumer property for both monitors. */
+    void setConsumerProperty(const QString &name, const QString &value);
 
 public slots:
 
             if (m_mltConsumer->is_valid()) {
 		externalConsumer = true;
                 m_mltConsumer->set("terminate_on_pause", 0);
-                m_mltConsumer->set("deinterlace_method", "onefield");
-		m_mltConsumer->set("rescale", "nearest");
+                m_mltConsumer->set("deinterlace_method", KdenliveSettings::mltdeinterlacer().toUtf8().constData());
+		m_mltConsumer->set("rescale", KdenliveSettings::mltinterpolation().toUtf8().constData());
 		m_mltConsumer->set("buffer", "1");
                 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
             }
 		    // Set defaults for decklink consumer
 		    if (m_mltConsumer) {
 			m_mltConsumer->set("terminate_on_pause", 0);
-			m_mltConsumer->set("deinterlace_method", "onefield");
+			m_mltConsumer->set("deinterlace_method", KdenliveSettings::mltdeinterlacer().toUtf8().constData());
 			externalConsumer = true;
 		    }
 		}
     }
     //m_mltConsumer->set("resize", 1);
     m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
-    m_mltConsumer->set("rescale", "nearest");
+    m_mltConsumer->set("rescale", KdenliveSettings::mltinterpolation().toUtf8().constData());
     mlt_log_set_callback(kdenlive_callback);
 
     QString audioDevice = KdenliveSettings::audiodevicename();
         int dropFrames = KdenliveSettings::mltthreads();
         if (show == false) dropFrames = -dropFrames;
         m_mltConsumer->stop();
-        if (m_winid == 0)
-            m_mltConsumer->set("real_time", dropFrames);
-        else
-            m_mltConsumer->set("play.real_time", dropFrames);
-
+        m_mltConsumer->set("real_time", dropFrames);
         if (m_mltConsumer->start() == -1) {
             kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
         }
     }
 }
 
+void Render::setConsumerProperty(const QString &name, const QString &value)
+{
+    QMutexLocker locker(&m_mutex);
+    if (m_mltConsumer) {
+        m_mltConsumer->stop();
+        m_mltConsumer->set(name.toUtf8().constData(), value.toUtf8().constData());
+        if (m_isActive && m_mltConsumer->start() == -1) {
+            kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
+        }
+
+    }
+}
+
 bool Render::isPlaying() const
 {
     if (!m_mltConsumer || m_mltConsumer->is_stopped()) return false;
     const QList <Mlt::Producer *> producersList();
     void updatePreviewSettings();
     void setDropFrames(bool show);
+    /** @brief Sets an MLT consumer property. */
+    void setConsumerProperty(const QString &name, const QString &value);
     QString updateSceneListFps(double current_fps, double new_fps, QString scene);
 
     void showAudio(Mlt::Frame&);