]> git.sesse.net Git - kdenlive/blobdiff - src/stopmotion/stopmotion.cpp
Make the choose color widget more consistent with other parameter widgets.
[kdenlive] / src / stopmotion / stopmotion.cpp
index c93a15acae959f0dde0656cabfe7f2d8027844e0..f3251fa68306078c26fa9a8a132928e4fa956507 100644 (file)
  ***************************************************************************/
 
 #include "stopmotion.h"
-#include "../blackmagic/devices.h"
-#include "../v4l/v4lcapture.h"
-#include "../slideshowclip.h"
-#include "../profilesdialog.h"
-#include "../mltdevicecapture.h"
-#include "../recmonitor.h"
-#include "../monitormanager.h"
+#include "blackmagic/devices.h"
+#ifdef USE_V4L
+#include "v4l/v4lcapture.h"
+#endif
+#include "slideshowclip.h"
+#include "profilesdialog.h"
+#include "mltdevicecapture.h"
+#include "recmonitor.h"
+#include "monitormanager.h"
 #include "ui_smconfig_ui.h"
 #include "kdenlivesettings.h"
 
-
 #include <KDebug>
 #include <KGlobalSettings>
 #include <KFileDialog>
 #include <kdeversion.h>
 #include <KNotification>
 
-#ifdef QIMAGEBLITZ
-#include <qimageblitz/qimageblitz.h>
-#endif
-
 #include <QtConcurrentRun>
 #include <QInputDialog>
 #include <QComboBox>
@@ -150,6 +147,12 @@ StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder,
     analyse->setCheckable(true);
     analyse->setChecked(KdenliveSettings::analyse_stopmotion());
     connect(analyse, SIGNAL(triggered(bool)), this, SLOT(slotSwitchAnalyse(bool)));
+
+    QAction* mirror = new QAction(i18n("Mirror display"), this);
+    mirror->setCheckable(true);
+    //mirror->setChecked(KdenliveSettings::analyse_stopmotion());
+    connect(mirror, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMirror(bool)));
+
     addActions(actions);
     setupUi(this);
     setWindowTitle(i18n("Stop Motion Capture"));
@@ -170,10 +173,10 @@ StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder,
     intervalCapture->setCheckable(true);
     intervalCapture->setChecked(false);
     capture_interval->setDefaultAction(intervalCapture);
-        
+
     preview_button->setIcon(KIcon("media-playback-start"));
     capture_button->setEnabled(false);
-    
+
 
     // Build config menu
     QMenu* confMenu = new QMenu;
@@ -182,22 +185,21 @@ StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder,
     overlay_button->setDefaultAction(m_showOverlay);
     //confMenu->addAction(m_showOverlay);
 
-#ifdef QIMAGEBLITZ
-    m_effectIndex = KdenliveSettings::blitzeffect();
+    m_effectIndex = KdenliveSettings::stopmotioneffect();
     QMenu* effectsMenu = new QMenu(i18n("Overlay effect"));
     QActionGroup* effectGroup = new QActionGroup(this);
     QAction* noEffect = new QAction(i18n("No Effect"), effectGroup);
-    noEffect->setData(1);
+    noEffect->setData(0);
     QAction* contrastEffect = new QAction(i18n("Contrast"), effectGroup);
-    contrastEffect->setData(2);
+    contrastEffect->setData(1);
     QAction* edgeEffect = new QAction(i18n("Edge detect"), effectGroup);
-    edgeEffect->setData(3);
+    edgeEffect->setData(2);
     QAction* brightEffect = new QAction(i18n("Brighten"), effectGroup);
-    brightEffect->setData(4);
+    brightEffect->setData(3);
     QAction* invertEffect = new QAction(i18n("Invert"), effectGroup);
-    invertEffect->setData(5);
+    invertEffect->setData(4);
     QAction* thresEffect = new QAction(i18n("Threshold"), effectGroup);
-    thresEffect->setData(6);
+    thresEffect->setData(5);
 
     effectsMenu->addAction(noEffect);
     effectsMenu->addAction(contrastEffect);
@@ -214,7 +216,6 @@ StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder,
     }
     connect(effectsMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotUpdateOverlayEffect(QAction*)));
     confMenu->addMenu(effectsMenu);
-#endif
 
     QAction* showThumbs = new QAction(KIcon("image-x-generic"), i18n("Show sequence thumbnails"), this);
     showThumbs->setCheckable(true);
@@ -231,6 +232,7 @@ StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder,
     confMenu->addAction(showThumbs);
     confMenu->addAction(removeCurrent);
     confMenu->addAction(analyse);
+    confMenu->addAction(mirror);
     confMenu->addAction(conf);
     config_button->setIcon(KIcon("configure"));
     config_button->setMenu(confMenu);
@@ -248,15 +250,13 @@ StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder,
     //m_videoBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
     m_videoBox->setLineWidth(4);
     layout->addWidget(m_videoBox);
-    
-    
-    if (BMInterface::getBlackMagicDeviceList(capture_device, NULL)) {
+
+
+    if (BMInterface::getBlackMagicDeviceList(capture_device)) {
         // Found a BlackMagic device
-        //m_bmCapture = new BmdCaptureHandler(m_layout);
-        //connect(m_bmCapture, SIGNAL(gotMessage(const QString&)), this, SLOT(slotGotHDMIMessage(const QString&)));
     }
     if (QFile::exists(KdenliveSettings::video4vdevice())) {
-#if !defined(Q_WS_MAC) && !defined(Q_OS_FREEBSD)
+#ifdef USE_V4L
         // Video 4 Linux device detection
         for (int i = 0; i < 10; i++) {
             QString path = "/dev/video" + QString::number(i);
@@ -270,22 +270,15 @@ StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder,
                 }
             }
         }
-
-        //if (m_bmCapture == NULL) {
-            
-            //m_captureDevice->sendFrameForAnalysis = m_analyse;
-            /*m_bmCapture = new V4lCaptureHandler(m_layout);
-            m_bmCapture->setDevice(capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString(), capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 2).toString());*/
-        //}
-#endif
+#endif /* USE_V4L */
     }
 
-    connect(capture_device, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateHandler()));
+    connect(capture_device, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDeviceHandler()));
     /*if (m_bmCapture) {
-        connect(m_bmCapture, SIGNAL(frameSaved(const QString)), this, SLOT(slotNewThumb(const QString)));
+        connect(m_bmCapture, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
         connect(m_bmCapture, SIGNAL(gotFrame(QImage)), this, SIGNAL(gotFrame(QImage)));
     } else live_button->setEnabled(false);*/
-    
+
     m_frame_preview = new MyLabel(this);
     connect(m_frame_preview, SIGNAL(seek(bool)), this, SLOT(slotSeekFrame(bool)));
     connect(m_frame_preview, SIGNAL(switchToLive()), this, SLOT(slotSwitchLive()));
@@ -294,13 +287,23 @@ StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder,
     video_preview->setLayout(layout);
 
     //kDebug()<<video_preview->winId();
-    
-    QString path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
-    m_captureDevice = new MltDeviceCapture(path, m_videoBox, this);
+
+    QString profilePath;
+    // Create MLT producer data
+    if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
+        // Capture using a video4linux device
+        profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
+    }
+    else {
+        // Decklink capture
+        profilePath = KdenliveSettings::current_profile();
+    }
+
+    m_captureDevice = new MltDeviceCapture(profilePath, m_videoBox, this);
     m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
     m_monitor->setRender(m_captureDevice);
-    connect(m_captureDevice, SIGNAL(frameSaved(const QString)), this, SLOT(slotNewThumb(const QString)));
-    
+    connect(m_captureDevice, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
+
     live_button->setChecked(false);
     button_addsequence->setEnabled(false);
     connect(live_button, SIGNAL(toggled(bool)), this, SLOT(slotLive(bool)));
@@ -322,8 +325,7 @@ StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder,
 
 StopmotionWidget::~StopmotionWidget()
 {
-    /*if (m_bmCapture)
-        m_bmCapture->stopPreview();*/
+    m_manager->removeMonitor(m_monitor);
     if (m_captureDevice) {
         m_captureDevice->stop();
         delete m_captureDevice;
@@ -335,11 +337,9 @@ StopmotionWidget::~StopmotionWidget()
 
 void StopmotionWidget::slotUpdateOverlayEffect(QAction* act)
 {
-#ifdef QIMAGEBLITZ
     if (act) m_effectIndex = act->data().toInt();
-    KdenliveSettings::setBlitzeffect(m_effectIndex);
-    if (m_showOverlay->isChecked()) slotUpdateOverlay();
-#endif
+    KdenliveSettings::setStopmotioneffect(m_effectIndex);
+    slotUpdateOverlay();
 }
 
 void StopmotionWidget::closeEvent(QCloseEvent* e)
@@ -362,7 +362,7 @@ void StopmotionWidget::slotConfigure()
     ui.sm_prenotify->setChecked(KdenliveSettings::sm_prenotify());
     ui.sm_loop->setChecked(KdenliveSettings::sm_loop());
     ui.sm_framesplayback->setValue(KdenliveSettings::sm_framesplayback());
-    
+
     if (d.exec() == QDialog::Accepted) {
         KdenliveSettings::setSm_loop(ui.sm_loop->isChecked());
         KdenliveSettings::setCaptureinterval(ui.sm_interval->value());
@@ -387,8 +387,11 @@ void StopmotionWidget::slotShowThumbs(bool show)
 }
 
 
-void StopmotionWidget::slotUpdateHandler()
+void StopmotionWidget::slotUpdateDeviceHandler()
 {
+    slotLive(false);
+    delete m_captureDevice;
+    m_captureDevice = NULL;
     /*QString data = capture_device->itemData(capture_device->currentIndex()).toString();
     slotLive(false);
     if (m_bmCapture) {
@@ -396,7 +399,7 @@ void StopmotionWidget::slotUpdateHandler()
     }
     m_layout->removeWidget(m_frame_preview);
     if (data == "v4l") {
-#if !defined(Q_WS_MAC) && !defined(Q_OS_FREEBSD)
+#ifdef USE_V4L
         m_bmCapture = new V4lCaptureHandler(m_layout);
         m_bmCapture->setDevice(capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString(), capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 2).toString());
 #endif
@@ -457,24 +460,46 @@ void StopmotionWidget::slotLive(bool isOn)
     if (isOn) {
         m_frame_preview->setHidden(true);
         m_videoBox->setHidden(false);
-        QString path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
+        QLocale locale;
+
+        MltVideoProfile profile;
+        QString resource;
+        QString service;
+        QString profilePath;
+        // Create MLT producer data
+        if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
+            // Capture using a video4linux device
+            profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
+            profile = ProfilesDialog::getVideoProfile(profilePath);
+            service = "avformat-novalidate";
+            QString devicePath = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
+            resource = QString("video4linux2:%1?width:%2&amp;height:%3&amp;frame_rate:%4").arg(devicePath).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den);
+        }
+        else {
+            // Decklink capture
+            profilePath = KdenliveSettings::current_profile();
+            profile = ProfilesDialog::getVideoProfile(profilePath);
+            service = "decklink";
+            resource = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
+        }
 
-        kDebug()<<"SURFACE; "<<m_videoBox->width()<<"x"<<m_videoBox->height();
         if (m_captureDevice == NULL) {
-            m_captureDevice = new MltDeviceCapture(path, m_videoBox, this);
+            m_captureDevice = new MltDeviceCapture(profilePath, m_videoBox, this);
             m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
             m_monitor->setRender(m_captureDevice);
-            connect(m_captureDevice, SIGNAL(frameSaved(const QString)), this, SLOT(slotNewThumb(const QString)));
+            connect(m_captureDevice, SIGNAL(frameSaved(const QString &)), this, SLOT(slotNewThumb(const QString &)));
         }
 
-        MltVideoProfile profile = ProfilesDialog::getVideoProfile(path);
         m_manager->activateMonitor("stopmotion");
-        QString producer = QString("avformat-novalidate:video4linux2:%1?width:%2&height:%3&frame_rate:%4").arg(KdenliveSettings::video4vdevice()).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den);
-        if (m_captureDevice->slotStartPreview(producer)) {
-            kDebug()<<"// STARt CAPTURE GO";
+        QString producer = createProducer(profile, service, resource);
+        if (m_captureDevice->slotStartPreview(producer, true)) {
+            if (m_showOverlay->isChecked()) {
+                reloadOverlay();
+                slotUpdateOverlay();
+            }
             capture_button->setEnabled(true);
             live_button->setChecked(true);
-            log_box->insertItem(-1, i18n("Playing %1x%2 (%3 fps)", profile.width, profile.height, QString::number((double)profile.frame_rate_num/profile.frame_rate_den).rightJustified(2, '0')));
+            log_box->insertItem(-1, i18n("Playing %1x%2 (%3 fps)", profile.width, profile.height, locale.toString((double)profile.frame_rate_num/profile.frame_rate_den).rightJustified(2, '0')));
             log_box->setCurrentIndex(0);
         }
         else {
@@ -495,7 +520,7 @@ void StopmotionWidget::slotLive(bool isOn)
             //m_captureDevice = NULL;
         }
     }
-            
+
     /*
     if (isOn && m_bmCapture) {
         //m_frame_preview->setImage(QImage());
@@ -512,53 +537,62 @@ void StopmotionWidget::slotLive(bool isOn)
     live_button->blockSignals(false);
 }
 
-void StopmotionWidget::slotShowOverlay(bool /*isOn*/)
+void StopmotionWidget::slotShowOverlay(bool isOn)
 {
-/*    if (isOn) {
-        if (live_button->isChecked() && m_sequenceFrame > 0) {
-            slotUpdateOverlay();
-        }
-    } else if (m_bmCapture) {
-        m_bmCapture->hideOverlay();
-    }*/
+    if (isOn) {
+        // Overlay last frame of the sequence
+        reloadOverlay();
+        slotUpdateOverlay();
+    }
+    else {
+        // Remove overlay
+        m_captureDevice->setOverlay(QString());
+    }
 }
 
-void StopmotionWidget::slotUpdateOverlay()
+void StopmotionWidget::reloadOverlay()
 {
-    if (m_captureDevice == NULL) return;
     QString path = getPathForFrame(m_sequenceFrame - 1);
-    if (!QFile::exists(path)) return;
-    QImage img(path);
-    if (img.isNull()) {
-        QTimer::singleShot(1000, this, SLOT(slotUpdateOverlay()));
+    if (!QFile::exists(path)) {
+        log_box->insertItem(-1, i18n("No previous frame found"));
+        log_box->setCurrentIndex(0);
         return;
     }
+    m_captureDevice->setOverlay(path);
+}
+
+void StopmotionWidget::slotUpdateOverlay()
+{
+    if (m_captureDevice == NULL) return;
+
+    QString tag;
+    QStringList params;
 
-#ifdef QIMAGEBLITZ
-    //img = Blitz::convolveEdge(img, 0, Blitz::Low);
     switch (m_effectIndex) {
+    case 1:
+        tag = "frei0r.contrast0r";
+        params << "Contrast=1.2";
+        break;
     case 2:
-        img = Blitz::contrast(img, true, 6);
+        tag = "charcoal";
+        params << "x_scatter=4" << "y_scatter=4" << "scale=1" << "mix=0";
         break;
     case 3:
-        img = Blitz::edge(img);
+        tag = "frei0r.brightness";
+        params << "Brightness=0.7";
         break;
     case 4:
-        img = Blitz::intensity(img, 0.5);
+        tag = "invert";
         break;
     case 5:
-        Blitz::invert(img);
-        break;
-    case 6:
-        img = Blitz::threshold(img, 120, Blitz::Grayscale, qRgba(0, 0, 0, 0), qRgba(255, 0, 0, 255));
-        //img = Blitz::flatten(img, QColor(255, 0, 0, 255), QColor(0, 0, 0, 0));
+        tag = "threshold";
+        params << "midpoint=125";
         break;
     default:
         break;
 
     }
-#endif
-    //m_bmCapture->showOverlay(img);
+    m_captureDevice->setOverlayEffect(tag, params);
 }
 
 void StopmotionWidget::sequenceNameChanged(const QString& name)
@@ -629,12 +663,13 @@ void StopmotionWidget::slotPreNotify()
 }
 
 
-void StopmotionWidget::slotNewThumb(const QString path)
+void StopmotionWidget::slotNewThumb(const QString &path)
 {
     if (!KdenliveSettings::showstopmotionthumbs()) return;
     m_filesList.append(path);
-    if (m_showOverlay->isChecked()) slotUpdateOverlay();
+    if (m_showOverlay->isChecked()) reloadOverlay();
     if (!m_future.isRunning()) m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
+
 }
 
 void StopmotionWidget::slotPrepareThumbs()
@@ -686,7 +721,7 @@ void StopmotionWidget::slotShowFrame(const QString& path)
     slotLive(false);
     if (!img.isNull()) {
         //m_videoBox->setHidden(true);
-        
+
         m_frame_preview->setImage(img);
         m_frame_preview->setHidden(false);
         m_frame_preview->update();
@@ -839,7 +874,34 @@ void StopmotionWidget::slotSwitchAnalyse(bool isOn)
 {
     KdenliveSettings::setAnalyse_stopmotion(isOn);
     if (m_captureDevice) m_captureDevice->sendFrameForAnalysis = isOn;
-    //m_bmCapture->setAnalyse(isOn);
 }
 
+void StopmotionWidget::slotSwitchMirror(bool isOn)
+{
+    //KdenliveSettings::setAnalyse_stopmotion(isOn);
+    if (m_captureDevice) m_captureDevice->mirror(isOn);
+}
+
+const QString StopmotionWidget::createProducer(MltVideoProfile profile, const QString &service, const QString &resource)
+{
+    Q_UNUSED(profile)
+
+    QString playlist = "<mlt title=\"capture\"><producer id=\"producer0\" in=\"0\" out=\"99999\"><property name=\"mlt_type\">producer</property><property name=\"length\">100000</property><property name=\"eof\">pause</property><property name=\"resource\">" + resource + "</property><property name=\"mlt_service\">" + service + "</property></producer>";
+
+    // overlay track
+    playlist.append("<playlist id=\"playlist0\"></playlist>");
+
+    // video4linux track
+    playlist.append("<playlist id=\"playlist1\"><entry producer=\"producer0\" in=\"0\" out=\"99999\"/></playlist>");
+
+    playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"99999\">");
+    playlist.append("<track producer=\"playlist0\"/>");
+    playlist.append("<track producer=\"playlist1\"/>");
+    playlist.append("</tractor></mlt>");
+
+
+    return playlist;
+}
+
+