]> git.sesse.net Git - kdenlive/commitdiff
User can now control video4linux webcams and firewire cams from the record monitor...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 16 Mar 2008 02:45:08 +0000 (02:45 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 16 Mar 2008 02:45:08 +0000 (02:45 +0000)
svn path=/branches/KDE4/; revision=2063

src/monitor.cpp
src/monitor.h
src/recmonitor.cpp
src/recmonitor.h
src/widgets/recmonitor_ui.ui

index d36288cfa400234fb5c3b12fa49ad21df309effa..f5207af8688f2f3d31afd9be2a88ca8955025cc6 100644 (file)
@@ -22,6 +22,7 @@
 #include <QStylePainter>
 #include <QMenu>
 #include <QToolButton>
+#include <QToolBar>
 
 #include <KDebug>
 #include <KLocale>
@@ -38,22 +39,22 @@ Monitor::Monitor(QString name, MonitorManager *manager, QWidget *parent)
     layout->addWidget(m_ruler);
     ui.ruler_frame->setLayout(layout);
 
-    m_toolbar = new QToolBar(name, this);
+    QToolBar *toolbar = new QToolBar(name, this);
     QVBoxLayout *layout2 = new QVBoxLayout;
 
     m_playIcon = KIcon("media-playback-start");
     m_pauseIcon = KIcon("media-playback-pause");
 
-    QAction *m_rewAction = m_toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"));
+    QAction *m_rewAction = toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"));
     connect(m_rewAction, SIGNAL(triggered()), this, SLOT(slotRewind()));
-    QAction *m_rew1Action = m_toolbar->addAction(KIcon("media-skip-backward"), i18n("Rewind 1 frame"));
+    QAction *m_rew1Action = toolbar->addAction(KIcon("media-skip-backward"), i18n("Rewind 1 frame"));
     connect(m_rew1Action, SIGNAL(triggered()), this, SLOT(slotRewindOneFrame()));
 
-    QToolButton *playButton = new QToolButton(m_toolbar);
+    QToolButton *playButton = new QToolButton(toolbar);
     QMenu *playMenu = new QMenu(this);
     playButton->setMenu(playMenu);
     playButton->setPopupMode(QToolButton::MenuButtonPopup);
-    m_toolbar->addWidget(playButton);
+    toolbar->addWidget(playButton);
 
     m_playAction = playMenu->addAction(m_playIcon, i18n("Play"));
     m_playAction->setCheckable(true);
@@ -63,18 +64,18 @@ Monitor::Monitor(QString name, MonitorManager *manager, QWidget *parent)
     QAction *m_loopSectionAction = playMenu->addAction(m_playIcon, i18n("Loop Section"));
     connect(m_loopSectionAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
 
-    QAction *m_fwd1Action = m_toolbar->addAction(KIcon("media-skip-forward"), i18n("Forward 1 frame"));
+    QAction *m_fwd1Action = toolbar->addAction(KIcon("media-skip-forward"), i18n("Forward 1 frame"));
     connect(m_fwd1Action, SIGNAL(triggered()), this, SLOT(slotForwardOneFrame()));
-    QAction *m_fwdAction = m_toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"));
+    QAction *m_fwdAction = toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"));
     connect(m_fwdAction, SIGNAL(triggered()), this, SLOT(slotForward()));
 
     playButton->setDefaultAction(m_playAction);
 
     m_timePos = new KRestrictedLine(this);
     m_timePos->setInputMask("99:99:99:99");
-    m_toolbar->addWidget(m_timePos);
+    toolbar->addWidget(m_timePos);
 
-    layout2->addWidget(m_toolbar);
+    layout2->addWidget(toolbar);
     ui.button_frame->setLayout(layout2);
 
     //m_ruler->setPixelPerMark(3);
index 647478d23bdef05c017b634ace1f985f7236ce1c..d5909cc45e9b882649d7913de03085b8171e51f9 100644 (file)
@@ -21,7 +21,6 @@
 #ifndef MONITOR_H
 #define MONITOR_H
 
-#include <QToolBar>
 #include <KIcon>
 #include <KAction>
 #include <KRestrictedLine>
@@ -60,7 +59,6 @@ private:
     KIcon m_playIcon;
     KIcon m_pauseIcon;
     bool m_isActive;
-    QToolBar *m_toolbar;
     KRestrictedLine *m_timePos;
     QAction *m_playAction;
 
index 57f4c4913bc2f16260553625d61e355fbc1b9b5e..9803769475203ea489e216b4878add0fd49763b2 100644 (file)
 #include <KDebug>
 #include <KLocale>
 #include <KStandardDirs>
+#include <KComboBox>
 
 #include "gentime.h"
 #include "kdenlivesettings.h"
 #include "recmonitor.h"
 
 RecMonitor::RecMonitor(QString name, QWidget *parent)
-        : QWidget(parent), m_name(name), m_isActive(false), m_isCapturing(false) {
+        : QWidget(parent), m_name(name), m_isActive(false), m_isCapturing(false), m_isPlaying(false) {
     ui.setupUi(this);
 
     ui.video_frame->setAttribute(Qt::WA_PaintOnScreen);
-    connect(ui.buttonConnect, SIGNAL(clicked()), this, SLOT(slotSwitchCapture()));
-    connect(ui.buttonRec, SIGNAL(clicked()), this, SLOT(slotCapture()));
-    ui.buttonRec->setCheckable(true);
+    ui.device_selector->setCurrentIndex(KdenliveSettings::defaultcapture());
+    connect(ui.device_selector, SIGNAL(currentIndexChanged(int)), this, SLOT(slotVideoDeviceChanged(int)));
 
+
+
+    QToolBar *toolbar = new QToolBar(name, this);
+    QHBoxLayout *layout = new QHBoxLayout;
+
+    m_playIcon = KIcon("media-playback-start");
+    m_pauseIcon = KIcon("media-playback-pause");
+
+    m_discAction = toolbar->addAction(KIcon("network-connect"), i18n("Connect"));
+    connect(m_discAction, SIGNAL(triggered()), this, SLOT(slotDisconnect()));
+
+    m_rewAction = toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"));
+    connect(m_rewAction, SIGNAL(triggered()), this, SLOT(slotRewind()));
+
+    m_playAction = toolbar->addAction(m_playIcon, i18n("Play"));
+    connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotStartCapture()));
+
+    m_stopAction = toolbar->addAction(KIcon("media-playback-stop"), i18n("Stop"));
+    connect(m_stopAction, SIGNAL(triggered()), this, SLOT(slotStopCapture()));
+    m_stopAction->setEnabled(false);
+    m_fwdAction = toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"));
+    connect(m_fwdAction, SIGNAL(triggered()), this, SLOT(slotForward()));
+
+    m_recAction = toolbar->addAction(KIcon("media-record"), i18n("Record"));
+    connect(m_recAction, SIGNAL(triggered()), this, SLOT(slotRecord()));
+    m_recAction->setCheckable(true);
+
+    layout->addWidget(toolbar);
+    ui.control_frame_firewire->setLayout(layout);
+
+    slotVideoDeviceChanged(ui.device_selector->currentIndex());
     displayProcess = new QProcess;
     captureProcess = new QProcess;
 
-    connect(displayProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(slotProcessStatus(QProcess::ProcessState)));
+    connect(captureProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(slotProcessStatus(QProcess::ProcessState)));
 
     QStringList env = QProcess::systemEnvironment();
     env << "SDL_WINDOWID=" + QString::number(ui.video_frame->winId());
@@ -58,7 +89,69 @@ QString RecMonitor::name() const {
     return m_name;
 }
 
-void RecMonitor::slotSwitchCapture() {
+void RecMonitor::slotVideoDeviceChanged(int ix) {
+
+    if (ix == 1) {
+        m_discAction->setEnabled(false);
+        m_rewAction->setEnabled(false);
+        m_fwdAction->setEnabled(false);
+        m_recAction->setEnabled(true);
+        m_stopAction->setEnabled(false);
+        m_playAction->setEnabled(true);
+    } else {
+        m_discAction->setEnabled(true);
+        m_recAction->setEnabled(false);
+        m_stopAction->setEnabled(false);
+        m_playAction->setEnabled(false);
+        m_rewAction->setEnabled(false);
+        m_fwdAction->setEnabled(false);
+    }
+}
+
+void RecMonitor::slotDisconnect() {
+    if (captureProcess->state() == QProcess::NotRunning) {
+        slotStartCapture(false);
+        m_discAction->setIcon(KIcon("network-disconnect"));
+        m_discAction->setText(i18n("Disonnect"));
+        m_recAction->setEnabled(true);
+        m_stopAction->setEnabled(true);
+        m_playAction->setEnabled(true);
+        m_rewAction->setEnabled(true);
+        m_fwdAction->setEnabled(true);
+    } else {
+        captureProcess->write("q", 1);
+        m_discAction->setIcon(KIcon("network-connect"));
+        m_discAction->setText(i18n("Connect"));
+        m_recAction->setEnabled(false);
+        m_stopAction->setEnabled(false);
+        m_playAction->setEnabled(false);
+        m_rewAction->setEnabled(false);
+        m_fwdAction->setEnabled(false);
+    }
+}
+
+void RecMonitor::slotRewind() {
+    captureProcess->write("a", 1);
+}
+
+void RecMonitor::slotForward() {
+    captureProcess->write("z", 1);
+}
+
+void RecMonitor::slotStopCapture() {
+    // stop capture
+    if (ui.device_selector->currentIndex() == 0) {
+        captureProcess->write("\e", 2);
+        m_playAction->setIcon(m_playIcon);
+        m_isPlaying = false;
+    } else {
+        if (m_isCapturing && ui.autoaddbox->isChecked()) emit addProjectClip(m_captureFile);
+        captureProcess->kill();
+        displayProcess->kill();
+    }
+}
+
+void RecMonitor::slotStartCapture(bool play) {
 
     /*
     *captureProcess<<"dvgrab";
@@ -96,38 +189,71 @@ void RecMonitor::slotSwitchCapture() {
         ui.video_frame->setScaledContents(false);
         captureProcess->start("dvgrab",captureArgs);
         displayProcess->start("ffplay",  displayArgs);*/
-    ui.buttonRec->setChecked(false);
-    m_isCapturing = false;
-    if (captureProcess->state() == QProcess::Starting) return;
-    else if (captureProcess->state() == QProcess::NotRunning) {
-        m_captureArgs.clear();
-        m_displayArgs.clear();
 
-        if (KdenliveSettings::defaultcapture() == 0) {
-            m_captureArgs << "--format" << "hdv" << "-i" << "capture" << "-";
-            m_displayArgs << "-f" << "mpegts" << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
-        } else {
-            if (!KdenliveSettings::video4adevice().isEmpty()) m_captureArgs << "-f" << KdenliveSettings::video4aformat() << "-i" << KdenliveSettings::video4adevice();
-            m_captureArgs << "-f" << "video4linux2" << "-s" << QString::number(KdenliveSettings::video4width()) + "x" + QString::number(KdenliveSettings::video4height()) << "-r" << QString::number(KdenliveSettings::video4rate()) << "-i" << KdenliveSettings::video4vdevice() << "-f" << KdenliveSettings::video4vformat() << "-";
-            m_displayArgs << "-f" << KdenliveSettings::video4vformat() << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
+
+    if (captureProcess->state() != QProcess::NotRunning) {
+        if (ui.device_selector->currentIndex() == 0) {
+            if (m_isPlaying) {
+                captureProcess->write("k", 1);
+                //captureProcess->write("\e", 2);
+                m_playAction->setIcon(m_playIcon);
+                m_isPlaying = false;
+            } else {
+                captureProcess->write("p", 1);
+                m_playAction->setIcon(m_pauseIcon);
+                m_isPlaying = true;
+            }
         }
+        return;
+    }
+    m_captureArgs.clear();
+    m_displayArgs.clear();
+    m_isPlaying = false;
 
-        captureProcess->setStandardOutputProcess(displayProcess);
-        if (KdenliveSettings::defaultcapture() == 0) captureProcess->start("dvgrab", m_captureArgs);
-        else captureProcess->start("ffmpeg", m_captureArgs);
-        displayProcess->start("ffplay", m_displayArgs);
-        ui.video_frame->setText(i18n("Initialising..."));
+    if (ui.device_selector->currentIndex() == 0) {
+        m_captureArgs << "--format" << "hdv" << "-i" << "capture" << "-";
+        m_displayArgs << "-f" << "mpegts" << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
     } else {
-        // stop capture
-        displayProcess->kill();
-        captureProcess->kill();
+        if (!KdenliveSettings::video4adevice().isEmpty()) m_captureArgs << "-f" << KdenliveSettings::video4aformat() << "-i" << KdenliveSettings::video4adevice();
+        m_captureArgs << "-f" << "video4linux2" << "-s" << QString::number(KdenliveSettings::video4width()) + "x" + QString::number(KdenliveSettings::video4height()) << "-r" << QString::number(KdenliveSettings::video4rate()) << "-i" << KdenliveSettings::video4vdevice() << "-f" << KdenliveSettings::video4vformat() << "-";
+        m_displayArgs << "-f" << KdenliveSettings::video4vformat() << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
     }
-}
 
-void RecMonitor::slotCapture() {
+    captureProcess->setStandardOutputProcess(displayProcess);
+    if (ui.device_selector->currentIndex() == 0) {
+        captureProcess->setWorkingDirectory(KdenliveSettings::capturefolder());
+        captureProcess->start("dvgrab", m_captureArgs);
+        if (play) captureProcess->write(" ", 1);
+        m_discAction->setEnabled(true);
+    } else captureProcess->start("ffmpeg", m_captureArgs);
+    displayProcess->start("ffplay", m_displayArgs);
+    ui.video_frame->setText(i18n("Initialising..."));
 
+}
+
+void RecMonitor::slotRecord() {
+    if (captureProcess->state() == QProcess::NotRunning && ui.device_selector->currentIndex() == 0) {
+        slotStartCapture();
+    }
+    if (m_isCapturing) {
+        if (ui.device_selector->currentIndex() == 0) {
+            captureProcess->write("\e", 2);
+            m_playAction->setIcon(m_playIcon);
+            m_isCapturing = false;
+            m_isPlaying = false;
+            m_recAction->setChecked(false);
+        } else {
+            slotStopCapture();
+            QTimer::singleShot(1000, this, SLOT(slotStartCapture()));
+        }
+        return;
+    } else if (ui.device_selector->currentIndex() == 0) {
+        m_isCapturing = true;
+        captureProcess->write("c\n", 3);
+        return;
+    }
     if (captureProcess->state() == QProcess::NotRunning) {
-        ui.buttonConnect->setEnabled(false);
+        m_recAction->setChecked(true);
 
         QString path = KdenliveSettings::capturefolder() + "/capture0000.mpg";
         int i = 1;
@@ -137,7 +263,7 @@ void RecMonitor::slotCapture() {
             else if (i < 100) num.prepend("00");
             else num.prepend("0");
             path = KdenliveSettings::capturefolder() + "/capture" + num + ".mpg";
-           i++;
+            i++;
         }
 
         m_captureFile = KUrl(path);
@@ -146,7 +272,7 @@ void RecMonitor::slotCapture() {
         m_captureArgs.clear();
         m_displayArgs.clear();
 
-        if (KdenliveSettings::defaultcapture() == 0) {
+        if (ui.device_selector->currentIndex() == 0) {
             m_captureArgs << "--format" << "hdv" << "-i" << "capture" << "-";
             m_displayArgs << "-f" << "mpegts" << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
         } else {
@@ -157,33 +283,31 @@ void RecMonitor::slotCapture() {
 
         captureProcess->setStandardOutputProcess(displayProcess);
         //ui.video_frame->setScaledContents(false);
-        if (KdenliveSettings::defaultcapture() == 0) captureProcess->start("dvgrab", m_captureArgs);
+        if (ui.device_selector->currentIndex() == 0) captureProcess->start("dvgrab", m_captureArgs);
         else captureProcess->start("ffmpeg", m_captureArgs);
         displayProcess->start("ffplay", m_displayArgs);
         ui.video_frame->setText(i18n("Initialising..."));
-        ui.buttonRec->setChecked(true);
     } else {
         // stop capture
         displayProcess->kill();
         captureProcess->kill();
-        if (m_isCapturing) {
-            QTimer::singleShot(1000, this, SLOT(slotSwitchCapture()));
-            ui.buttonRec->setChecked(false);
-            ui.buttonConnect->setEnabled(true);
-            if (ui.autoaddbox->isChecked()) emit addProjectClip(m_captureFile);
-        } else {
-            QTimer::singleShot(1000, this, SLOT(slotCapture()));
-            ui.buttonRec->setChecked(true);
-        }
+        QTimer::singleShot(1000, this, SLOT(slotRecord()));
     }
 }
 
 void RecMonitor::slotProcessStatus(QProcess::ProcessState status) {
-    if (status == QProcess::Starting) ui.buttonConnect->setText(i18n("Starting..."));
-    else if (status == QProcess::NotRunning) {
-        ui.buttonConnect->setText(i18n("Connect"));
+    if (status == QProcess::NotRunning) {
+        m_isCapturing = false;
+        m_isPlaying = false;
+        m_playAction->setIcon(m_playIcon);
+        m_recAction->setChecked(false);
+        m_stopAction->setEnabled(false);
+        ui.device_selector->setEnabled(true);
         ui.video_frame->setText(i18n("Not connected"));
-    } else ui.buttonConnect->setText(i18n("Disconnect"));
+    } else {
+        m_stopAction->setEnabled(true);
+        ui.device_selector->setEnabled(false);
+    }
 }
 
 // virtual
index 20bba7b36b707b6dd69b8f0034d813e5cdf19ba8..c2f2c37ab3651cff660bd3cc84a0dfc03b2124f1 100644 (file)
@@ -53,18 +53,32 @@ private:
 
 
     KUrl m_captureFile;
+    KIcon m_playIcon;
+    KIcon m_pauseIcon;
 
     QProcess *captureProcess;
     QProcess *displayProcess;
     QTimer *m_initTimer;
     bool m_isCapturing;
+    bool m_isPlaying;
     QStringList m_captureArgs;
     QStringList m_displayArgs;
+    QAction *m_recAction;
+    QAction *m_playAction;
+    QAction *m_fwdAction;
+    QAction *m_rewAction;
+    QAction *m_stopAction;
+    QAction *m_discAction;
 
 private slots:
-    void slotSwitchCapture();
-    void slotCapture();
+    void slotStartCapture(bool play = true);
+    void slotStopCapture();
+    void slotRecord();
     void slotProcessStatus(QProcess::ProcessState status);
+    void slotVideoDeviceChanged(int ix);
+    void slotRewind();
+    void slotForward();
+    void slotDisconnect();
 
 public slots:
     void refreshRecMonitor(bool visible);
index 90a9910564be0efdc78645e406303ea2e9eab117..21b41a2b9581ffbf2b0a513e42419564daaef322 100644 (file)
@@ -5,12 +5,12 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>301</width>
-    <height>248</height>
+    <width>306</width>
+    <height>242</height>
    </rect>
   </property>
-  <layout class="QGridLayout" name="gridLayout" >
-   <item row="0" column="0" colspan="4" >
+  <layout class="QGridLayout" name="gridLayout_2" >
+   <item row="0" column="0" colspan="2" >
     <widget class="QLabel" name="video_frame" >
      <property name="text" >
       <string>Not connected</string>
      </property>
     </widget>
    </item>
-   <item row="1" column="0" >
-    <widget class="KPushButton" name="buttonConnect" >
-     <property name="text" >
-      <string>Connect</string>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="2" >
-    <spacer name="horizontalSpacer" >
-     <property name="orientation" >
-      <enum>Qt::Horizontal</enum>
-     </property>
-     <property name="sizeHint" stdset="0" >
-      <size>
-       <width>40</width>
-       <height>20</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
-   <item row="1" column="3" >
-    <widget class="KPushButton" name="buttonRec" >
-     <property name="text" >
-      <string>Record</string>
-     </property>
-    </widget>
-   </item>
-   <item row="3" column="0" colspan="4" >
-    <widget class="QFrame" name="control_frame" >
+   <item row="1" column="0" colspan="2" >
+    <widget class="QFrame" name="control_frame_firewire" >
      <property name="sizePolicy" >
       <sizepolicy vsizetype="Maximum" hsizetype="Preferred" >
        <horstretch>0</horstretch>
      </property>
     </widget>
    </item>
+   <item row="2" column="1" >
+    <widget class="KComboBox" name="device_selector" >
+     <item>
+      <property name="text" >
+       <string>Firewire / dvgrab</string>
+      </property>
+     </item>
+     <item>
+      <property name="text" >
+       <string>Video4Linux / ffmpeg</string>
+      </property>
+     </item>
+    </widget>
+   </item>
   </layout>
  </widget>
  <customwidgets>
   <customwidget>
-   <class>KPushButton</class>
-   <extends>QPushButton</extends>
-   <header>kpushbutton.h</header>
+   <class>KComboBox</class>
+   <extends>QComboBox</extends>
+   <header>kcombobox.h</header>
   </customwidget>
  </customwidgets>
  <resources/>