]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
new: save clip part as westley playlist
[kdenlive] / src / renderer.cpp
index 629a4d5ed75d2274018a9da640c41699385b3158..a4321942b0d116b2e121856c156363f2cdaa92a3 100644 (file)
@@ -65,13 +65,13 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr
     }
 }
 
-Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent): QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_winid(winid), m_externalwinid(extid),  m_framePosition(0), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(false) {
+Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent): QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_winid(winid), m_externalwinid(extid),  m_framePosition(0), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(false), m_isZoneMode(false), m_isLoopMode(false) {
     kDebug() << "//////////  USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
     refreshTimer = new QTimer(this);
     connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
 
-    if (rendererName == "project") m_monitorId = 10000;
-    else m_monitorId = 10001;
+    /*if (rendererName == "project") m_monitorId = 10000;
+    else m_monitorId = 10001;*/
     osdTimer = new QTimer(this);
     connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
 
@@ -201,8 +201,11 @@ int Render::resetProfile() {
 
 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
 void Render::seek(GenTime time) {
-    sendSeekCommand(time);
-    //emit positionChanged(time);
+    if (!m_mltProducer)
+        return;
+    //kDebug()<<"//////////  KDENLIVE SEEK: "<<(int) (time.frames(m_fps));
+    m_mltProducer->seek((int)(time.frames(m_fps)));
+    refresh();
 }
 
 //static
@@ -579,6 +582,11 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
 
     AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL);
     if (context != NULL) {
+        /*if (context->duration == AV_NOPTS_VALUE) {
+        kDebug() << " / / / / / / / /ERRROR / / / CLIP HAS UNKNOWN DURATION";
+            emit removeInvalidClip(clipId);
+            return;
+        }*/
         // Get the video_index
         int index = mlt_properties_get_int(properties, "video_index");
 
@@ -795,7 +803,6 @@ void Render::saveSceneList(QString path, QDomElement kdenliveData) {
     if (split) slotSplitView(false);
     westleyConsumer.connect(prod);
     //prod.set("title", "kdenlive document");
-    //westleyConsumer.listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
     westleyConsumer.start();
     while (!westleyConsumer.is_stopped()) {}
     if (!kdenliveData.isNull()) {
@@ -818,6 +825,38 @@ void Render::saveSceneList(QString path, QDomElement kdenliveData) {
 }
 
 
+void Render::saveZone(KUrl url, QString desc, QPoint zone) {
+    kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
+    char *tmppath = decodedString("westley:" + url.path());
+    Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
+    m_mltProducer->optimise();
+    delete[] tmppath;
+    westleyConsumer.set("terminate_on_pause", 1);
+    if (m_name == "clip") {
+        Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
+        tmppath = decodedString(desc);
+        Mlt::Playlist list;
+        list.insert_at(0, prod, 0);
+        list.set("title", tmppath);
+        delete[] tmppath;
+        westleyConsumer.connect(list);
+
+    } else {
+        //TODO: not working yet, save zone from timeline
+        Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
+        /* Mlt::Service service(p1->parent().get_service());
+         if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
+
+        //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
+        tmppath = decodedString(desc);
+        //prod->set("title", tmppath);
+        delete[] tmppath;
+        westleyConsumer.connect(*p1); //list);
+    }
+
+    westleyConsumer.start();
+}
+
 const double Render::fps() const {
     return m_fps;
 }
@@ -937,6 +976,7 @@ void Render::stop() {
     m_isBlocked = true;
 
     if (m_mltProducer) {
+        if (m_isZoneMode) resetZoneMode();
         m_mltProducer->set_speed(0.0);
         //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
         //kDebug() << m_mltProducer->get_length();
@@ -948,6 +988,7 @@ void Render::stop(const GenTime & startTime) {
 
     kDebug() << "/////////////   RENDER STOP-------2";
     if (m_mltProducer) {
+        if (m_isZoneMode) resetZoneMode();
         m_mltProducer->set_speed(0.0);
         m_mltProducer->seek((int) startTime.frames(m_fps));
     }
@@ -957,6 +998,7 @@ void Render::stop(const GenTime & startTime) {
 void Render::switchPlay() {
     if (!m_mltProducer || !m_mltConsumer)
         return;
+    if (m_isZoneMode) resetZoneMode();
     if (m_mltProducer->get_speed() == 0.0) {
         //m_isBlocked = false;
         m_mltProducer->set_speed(1.0);
@@ -996,44 +1038,45 @@ void Render::play(double speed) {
     refresh();
 }
 
-void Render::play(double speed, const GenTime & startTime) {
-    kDebug() << "/////////////   RENDER PLAY2-------" << speed;
-    if (!m_mltProducer)
+void Render::play(const GenTime & startTime) {
+    if (!m_mltProducer || !m_mltConsumer)
         return;
-    //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
-    //if (speed == 0.0) m_mltConsumer->set("refresh", 0);
-    m_mltProducer->set_speed(speed);
     m_mltProducer->seek((int)(startTime.frames(m_fps)));
-    //m_mltConsumer->purge();
-    //refresh();
+    m_mltProducer->set_speed(1.0);
+    m_mltConsumer->set("refresh", 1);
 }
 
-void Render::play(double speed, const GenTime & startTime,
-                  const GenTime & stopTime) {
-    kDebug() << "/////////////   RENDER PLAY3-------" << speed << stopTime.frames(m_fps);
-    if (!m_mltProducer)
+void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
+    if (!m_mltProducer || !m_mltConsumer)
+        return;
+    //m_mltProducer->set("eof", "loop");
+    m_isLoopMode = true;
+    m_loopStart = startTime;
+    playZone(startTime, stopTime);
+}
+
+void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
+    if (!m_mltProducer || !m_mltConsumer)
         return;
     m_mltProducer->set("out", stopTime.frames(m_fps));
     m_mltProducer->seek((int)(startTime.frames(m_fps)));
-    m_mltConsumer->purge();
-    m_mltProducer->set_speed(speed);
-    refresh();
+    m_mltProducer->set_speed(1.0);
+    m_mltConsumer->set("refresh", 1);
+    m_isZoneMode = true;
 }
 
-
-void Render::sendSeekCommand(GenTime time) {
-    //kDebug()<<" *********  RENDER SEND SEEK";
-    if (!m_mltProducer)
-        return;
-    //kDebug()<<"//////////  KDENLIVE SEEK: "<<(int) (time.frames(m_fps));
-    m_mltProducer->seek((int)(time.frames(m_fps)));
-    refresh();
+void Render::resetZoneMode() {
+    m_mltProducer->set("out", m_mltProducer->get_length() - 1);
+    //m_mltProducer->set("eof", "pause");
+    m_isZoneMode = false;
+    m_isLoopMode = false;
 }
 
 void Render::seekToFrame(int pos) {
     //kDebug()<<" *********  RENDER SEEK TO POS";
     if (!m_mltProducer)
         return;
+    resetZoneMode();
     m_mltProducer->seek(pos);
     refresh();
 }
@@ -1057,17 +1100,6 @@ void Render::refresh() {
     }
 }
 
-/** Sets the description of this renderer to desc. */
-void Render::setDescription(const QString & description) {
-    m_description = description;
-}
-
-/** Returns the description of this renderer */
-QString Render::description() {
-    return m_description;
-}
-
-
 double Render::playSpeed() {
     if (m_mltProducer) return m_mltProducer->get_speed();
     return 0.0;
@@ -1094,6 +1126,8 @@ void Render::emitConsumerStopped() {
     // This is used to know when the playing stopped
     if (m_mltProducer) {
         double pos = m_mltProducer->position();
+        if (m_isLoopMode) play(m_loopStart);
+        else if (m_isZoneMode) resetZoneMode();
         emit rendererStopped((int) pos);
         //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
         //new QCustomEvent(10002));
@@ -1210,8 +1244,8 @@ void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pr
     mlt_service_lock(service.get_service());
     Mlt::Producer trackProducer(tractor.track(info.track));
     Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
-
-    Mlt::Producer *clip = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
+    //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
+    Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
     int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
 
     if (QString(prod->get("transparency")).toInt() == 1)
@@ -2268,7 +2302,6 @@ void Render::mltSavePlaylist() {
 
     fileConsumer.connect(service);
     fileConsumer.start();
-
 }
 
 #include "renderer.moc"