]> git.sesse.net Git - kdenlive/blobdiff - src/monitor.cpp
Move mlt interlace and rescale into main menu
[kdenlive] / src / monitor.cpp
index 7c2f5b8599a265c47a9c2ecfaf5b8eef2e9dc9d6..34f1c7bd0d8bb35258eb0c05f3f1bc2230c69488 100644 (file)
@@ -31,6 +31,7 @@
 #include <KFileDialog>
 #include <KApplication>
 #include <KMessageBox>
+#include <KSelectAction>
 
 #include <QMouseEvent>
 #include <QStylePainter>
 
 
 Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profile, QWidget *parent) :
-    AbstractMonitor(id, manager, parent),
-    render(NULL),
-    m_currentClip(NULL),
-    m_overlay(NULL),
-    m_scale(1),
-    m_length(0),
-    m_dragStarted(false),
-    m_contextMenu(NULL),
-    m_effectWidget(NULL),
-    m_selectedClip(NULL),
-    m_loopClipTransition(true),
-    m_editMarker(NULL)
+    AbstractMonitor(id, manager, parent)
+    , render(NULL)
+    , m_currentClip(NULL)
+    , m_overlay(NULL)
+    , m_scale(1)
+    , m_length(2)
+    , m_dragStarted(false)
+    , m_loopClipAction(NULL)
+    , m_contextMenu(NULL)
+    , m_effectWidget(NULL)
+    , m_selectedClip(NULL)
+    , m_loopClipTransition(true)
+#ifdef USE_OPENGL
+    , m_glWidget(NULL)
+#endif
+    , m_editMarker(NULL)
 {
     QVBoxLayout *layout = new QVBoxLayout;
     layout->setContentsMargins(0, 0, 0, 0);
@@ -170,7 +175,7 @@ Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profil
 #endif
 
     // Monitor ruler
-    m_ruler = new SmallRuler(m_monitorManager, render);
+    m_ruler = new SmallRuler(this, render);
     if (id == Kdenlive::dvdMonitor) m_ruler->setZone(-3, -2);
     layout->addWidget(m_ruler);
     
@@ -203,7 +208,7 @@ Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profil
     m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
     m_toolbar->addWidget(m_timePos);
     connect(m_timePos, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotSeek()));
-    m_toolbar->setMaximumHeight(s * 1.5);
+    m_toolbar->setMaximumHeight(m_timePos->height());
     layout->addWidget(m_toolbar);
 }
 
@@ -226,7 +231,6 @@ QWidget *Monitor::container()
 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
 {
     render = new Render(id(), 0, profile, this);
-    kDebug()<<"+++++++++++++\nCREATED OPENGL WIDG\n++++++++++++++";
     m_glWidget = new VideoGLWidget(parent);
     if (m_glWidget == NULL) {
         // Creation failed, we are in trouble...
@@ -291,10 +295,9 @@ void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMe
     dropFrames->setCheckable(true);
     dropFrames->setChecked(true);
     connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
-
+    
     m_configMenu->addAction(showTips);
     m_configMenu->addAction(dropFrames);
-
 }
 
 void Monitor::slotGoToMarker(QAction *action)
@@ -348,6 +351,16 @@ void Monitor::resetSize()
     videoBox->setMinimumSize(0, 0);
 }
 
+QString Monitor::getTimecodeFromFrames(int pos)
+{
+    return m_monitorManager->timecode().getTimecodeFromFrames(pos);
+}
+
+double Monitor::fps() const
+{
+    return m_monitorManager->timecode().fps();
+}
+
 DocClipBase *Monitor::activeClip()
 {
     return m_currentClip;
@@ -373,6 +386,11 @@ void Monitor::updateMarkers(DocClipBase *source)
     }
 }
 
+void Monitor::setMarkers(QList <CommentedTime> markers)
+{
+    m_ruler->setMarkers(markers);
+}
+
 void Monitor::slotSeekToPreviousSnap()
 {
     if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
@@ -441,6 +459,7 @@ void Monitor::slotSetZoneEnd()
 // virtual
 void Monitor::mousePressEvent(QMouseEvent * event)
 {
+    if (render) render->setActiveMonitor();
     if (event->button() != Qt::RightButton) {
         if (videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) {
             m_dragStarted = true;
@@ -769,6 +788,9 @@ void Monitor::stop()
 void Monitor::start()
 {
     if (!isVisible() || !isActive()) return;
+#ifdef USE_OPENGL    
+    if (m_glWidget) m_glWidget->activateMonitor();
+#endif
     if (render) render->startConsumer();
 }
 
@@ -850,7 +872,7 @@ void Monitor::slotLoopClip()
 void Monitor::updateClipProducer(Mlt::Producer *prod)
 {
     if (render == NULL) return;
-   render->setProducer(prod, render->seekFramePosition());
+    render->setProducer(prod, render->seekFramePosition());
 }
 
 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
@@ -858,7 +880,6 @@ void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpda
     if (render == NULL) return;
     if (clip == NULL && m_currentClip != NULL) {
        m_currentClip->lastSeekPosition = render->seekFramePosition();
-        kDebug()<<"// SETTING NULL CLIP MONITOR";
         m_currentClip = NULL;
         m_length = -1;
         render->setProducer(NULL, -1);
@@ -875,12 +896,17 @@ void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpda
         if (render->setProducer(prod, position) == -1) {
             // MLT CONSUMER is broken
             kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
-        }
+        } else start();
     } else {
         if (m_currentClip) {
             slotActivateMonitor();
             if (position == -1) position = render->seekFramePosition();
             render->seek(position);
+           if (zone.isNull()) {
+               zone = m_currentClip->zone();
+               m_ruler->setZone(zone.x(), zone.y());
+               return;
+           }
         }
     }
     if (!zone.isNull()) {
@@ -893,14 +919,7 @@ void Monitor::slotOpenFile(const QString &file)
 {
     if (render == NULL) return;
     slotActivateMonitor();
-    QDomDocument doc;
-    QDomElement mlt = doc.createElement("mlt");
-    doc.appendChild(mlt);
-    QDomElement prod = doc.createElement("producer");
-    mlt.appendChild(prod);
-    prod.setAttribute("mlt_service", "avformat");
-    prod.setAttribute("resource", file);
-    render->setSceneList(doc, 0);
+    render->loadUrl(file);
 }
 
 void Monitor::slotSaveZone()
@@ -911,6 +930,19 @@ void Monitor::slotSaveZone()
     //render->setSceneList(doc, 0);
 }
 
+void Monitor::setCustomProfile(const QString &profile, Timecode tc)
+{
+    m_timePos->updateTimeCode(tc);
+    if (render == NULL) return;
+    if (!render->hasProfile(profile)) {
+        slotActivateMonitor();
+        render->resetProfile(profile);
+#ifdef USE_OPENGL    
+       if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar());
+#endif
+    }
+}
+
 void Monitor::resetProfile(const QString &profile)
 {
     m_timePos->updateTimeCode(m_monitorManager->timecode());
@@ -918,6 +950,9 @@ void Monitor::resetProfile(const QString &profile)
     if (!render->hasProfile(profile)) {
         slotActivateMonitor();
         render->resetProfile(profile);
+#ifdef USE_OPENGL
+       if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar());
+#endif
     }
     if (m_effectWidget)
         m_effectWidget->resetProfile(render);
@@ -1003,10 +1038,10 @@ QStringList Monitor::getZoneInfo() const
 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
 {
     if (item) {
-        m_loopClipAction->setEnabled(true);
+        if (m_loopClipAction) m_loopClipAction->setEnabled(true);
         m_selectedClip = item;
     } else {
-        m_loopClipAction->setEnabled(false);
+        if (m_loopClipAction) m_loopClipAction->setEnabled(false);
     }
 }
 
@@ -1114,6 +1149,16 @@ void Monitor::reloadProducer(const QString &id)
         slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
 }
 
+QString Monitor::getMarkerThumb(GenTime pos)
+{
+    if (!m_currentClip) return QString();
+    if (!m_currentClip->getClipHash().isEmpty()) {
+       QString url = m_monitorManager->getProjectFolder() + "thumbs/" + m_currentClip->getClipHash() + '#' + QString::number((int) pos.frames(m_monitorManager->timecode().fps())) + ".png";
+        if (QFile::exists(url)) return url;
+    }
+    return QString();
+}
+
 void Monitor::setPalette ( const QPalette & p)
 {
     QWidget::setPalette(p);