]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
show effects for the clipin effectstack
[kdenlive] / src / customtrackview.cpp
index 08f940cebef05292fa59fac443407455cbdebf2f..83202edc58c7e951e3ca88652a900b77b65dbc87 100644 (file)
@@ -33,6 +33,7 @@
 #include "moveclipcommand.h"
 #include "resizeclipcommand.h"
 #include "addtimelineclipcommand.h"
+#include "addeffectcommand.h"
 
 CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent)
     : QGraphicsView(projectscene, parent), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_startPos(QPointF()), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(0), m_document(doc)
@@ -275,7 +276,16 @@ void CustomTrackView::mousePressEvent ( QMouseEvent * event )
     for (int i = 0; i < collisionList.size(); ++i) {
       QGraphicsItem *item = collisionList.at(i);
       if (item->type() == 70000) {
+       // select item
+       if (!item->isSelected()) {
+         QList<QGraphicsItem *> itemList = items();
+         for (int i = 0; i < itemList.count(); i++)
+           itemList.at(i)->setSelected(false);
+         item->setSelected(true);
+         update();
+       }
        m_dragItem = (ClipItem *) item;
+       emit clipItemSelected(m_dragItem);
        m_clickPoint = mapToScene(event->pos()).x() - m_dragItem->startPos() * m_scale;
        m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
        if (m_operationMode == MOVE || m_operationMode == RESIZESTART) 
@@ -297,30 +307,64 @@ void CustomTrackView::mousePressEvent ( QMouseEvent * event )
   }
   updateSnapPoints(m_dragItem);
   //kDebug()<<pos;
-  QGraphicsView::mousePressEvent(event);
+  //QGraphicsView::mousePressEvent(event);
 }
 
 void CustomTrackView::dragEnterEvent ( QDragEnterEvent * event )
 {
   if (event->mimeData()->hasText()) {
-    QString clip = event->mimeData()->text();
+    kDebug()<<"///////////////  DRAG ENTERED, TEXT: "<<event->mimeData()->text();
+    QStringList ids = QString(event->mimeData()->text()).split(";");
+    //TODO: drop of several clips
+    for (int i = 0; i < ids.size(); ++i) {
+    }
+    DocClipBase *clip = m_document->getBaseClip(ids.at(0).toInt());
+    if (clip == NULL) kDebug()<<" WARNING))))))))) CLIP NOT FOUND : "<<ids.at(0).toInt();
     addItem(clip, event->pos());
     event->acceptProposedAction();
   }
 }
 
+void CustomTrackView::addEffect(int track, GenTime pos, QString tag, QMap <QString, QString> args)
+{
+  m_document->renderer()->mltAddEffect(track, pos, tag, args);
+  ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track);
+       if (clip){ 
+               clip->addEffect(args);
+               emit clipItemSelected(clip);
+       }
+}
+
+void CustomTrackView::deleteEffect(int track, GenTime pos, QString tag)
+{
+  m_document->renderer()->mltRemoveEffect(track, pos, tag, -1);  
+  ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track);
+       if (clip){
+               clip->deleteEffect(tag);
+               emit clipItemSelected(clip);
+       }
+}
 
-void CustomTrackView::addItem(QString producer, QPoint pos)
+void CustomTrackView::slotAddEffect(QMap <QString, QString> filter)
 {
-  QDomDocument doc;
-  doc.setContent(producer);
-  QDomElement elem = doc.documentElement();
-  int in = elem.attribute("in", 0).toInt();
-  int out = elem.attribute("out", 0).toInt() - in;
-  if (out == 0) out = elem.attribute("duration", 0).toInt();
-  kDebug()<<"ADDING CLIP: "<<producer<<", OUT: "<<out<<", POS: "<<mapToScene(pos);
+  QList<QGraphicsItem *> itemList = items();
+  for (int i = 0; i < itemList.count(); i++) {
+    if (itemList.at(i)->type() == 70000 && itemList.at(i)->isSelected()) {
+      ClipItem *item = (ClipItem *)itemList.at(i);
+      QString tag = filter.value("mlt_service");
+      AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - item->track(),GenTime(item->startPos(), m_document->fps()), tag, filter, true);
+      m_commandStack->push(command);    
+    }
+  }
+}
+
+void CustomTrackView::addItem(DocClipBase *clip, QPoint pos)
+{
+  int in =0;
+  int out = clip->duration().frames(m_document->fps());
+  //kdDebug()<<"- - - -CREATING CLIP, duration = "<<out<<", URL: "<<clip->fileURL();
   int trackTop = ((int) mapToScene(pos).y()/50) * 50 + 1;
-  m_dropItem = new ClipItem(elem, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out);
+  m_dropItem = new ClipItem(clip, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out);
   scene()->addItem(m_dropItem);
 }
 
@@ -349,10 +393,12 @@ void CustomTrackView::dragLeaveEvent ( QDragLeaveEvent * event ) {
 
 void CustomTrackView::dropEvent ( QDropEvent * event ) {
   if (m_dropItem) {
-    AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false);
+    AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->clipProducer(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false, false);
     m_commandStack->push(command);
+    m_dropItem->baseClip()->addReference();
+    m_document->updateClip(m_dropItem->baseClip()->getId());
     kDebug()<<"IIIIIIIIIIIIIIIIIIIIIIII TRAX CNT: "<<m_tracksCount<<", DROP: "<<m_dropItem->track();
-    m_document->renderer()->mltInsertClip(m_tracksCount - m_dropItem->track(), GenTime(m_dropItem->startPos(), 25), m_dropItem->xml());
+    m_document->renderer()->mltInsertClip(m_tracksCount - m_dropItem->track(), GenTime(m_dropItem->startPos(), m_document->fps()), m_dropItem->xml());
   }
   m_dropItem = NULL;
 }
@@ -395,12 +441,27 @@ void CustomTrackView::removeTrack ()
   m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount);
 }
 
+void CustomTrackView::deleteClip(int clipId)
+{
+  QList<QGraphicsItem *> itemList = items();
+  for (int i = 0; i < itemList.count(); i++) {
+    if (itemList.at(i)->type() == 70000) {
+      ClipItem *item = (ClipItem *)itemList.at(i);
+      if (item->clipProducer() == clipId) {
+       AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->track(), item->startPos(), item->rect(), item->duration(), true, true);
+       m_commandStack->push(command);
+       //delete item;
+      }
+    }
+  }
+}
+
 void CustomTrackView::setCursorPos(int pos, bool seek)
 {
   m_cursorPos = pos;
   m_cursorLine->setPos(pos, 0);
   int frame = mapToScene(QPoint(pos, 0)).x() / m_scale;
-  if (seek) m_document->renderer()->seek(GenTime(frame, 25));
+  if (seek) m_document->renderer()->seek(GenTime(frame, m_document->fps()));
 }
 
 int CustomTrackView::cursorPos()
@@ -414,7 +475,7 @@ void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
   setDragMode(QGraphicsView::NoDrag);
   if (m_dragItem == NULL) return;
   //kDebug()<<"/// MOVING CLIP: "<<m_startPos<<", END: "<<QPoint(m_dragItem->rect().x(),m_dragItem->rect().y());
-  if (m_operationMode == MOVE) {
+  if (m_operationMode == MOVE && m_startPos.x() != m_dragItem->startPos()) {
     // move clip
     MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), false);
     m_commandStack->push(command);
@@ -423,12 +484,18 @@ void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
   else if (m_operationMode == RESIZESTART) {
     // resize start
     ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), true, false);
+
+    m_document->renderer()->mltResizeClipStart(m_tracksCount - m_dragItem->track(), GenTime(m_dragItem->endPos(), m_document->fps()), GenTime(m_dragItem->startPos(), m_document->fps()), GenTime(m_startPos.x(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()) + GenTime(m_dragItem->endPos(), m_document->fps()) - GenTime(m_dragItem->startPos(), m_document->fps()));
     m_commandStack->push(command);
+    m_document->renderer()->doRefresh();
   }
   else if (m_operationMode == RESIZEEND) {
     // resize end
     ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->endPos(), m_dragItem->track()), false, false);
+
+    m_document->renderer()->mltResizeClipEnd(m_tracksCount - m_dragItem->track(), GenTime(m_dragItem->startPos(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()) + GenTime(m_dragItem->endPos(), m_document->fps()) - GenTime(m_dragItem->startPos(), m_document->fps()));
     m_commandStack->push(command);
+    m_document->renderer()->doRefresh();
   }
   m_operationMode = NONE;
   m_dragItem = NULL; 
@@ -436,26 +503,38 @@ void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
 
 void CustomTrackView::deleteClip (int track, int startpos, const QRectF &rect )
 {
-  ClipItem *item = (ClipItem *) scene()->itemAt(rect.x() + 1, rect.y() + 1);
+  ClipItem *item = getClipItemAt(startpos, track);
   if (!item) {
     kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<<rect.x();
     return;
   }
+  item->baseClip()->removeReference();
+  m_document->updateClip(item->baseClip()->getId());
   delete item;
-  m_document->renderer()->mltRemoveClip(m_tracksCount - track, GenTime(startpos, 25));
+  m_document->renderer()->mltRemoveClip(m_tracksCount - track, GenTime(startpos, m_document->fps()));
+  m_document->renderer()->doRefresh();
 }
 
-void CustomTrackView::addClip ( QDomElement xml, int track, int startpos, const QRectF &rect, int duration )
+void CustomTrackView::addClip ( QDomElement xml, int clipId, int track, int startpos, const QRectF &rect, int duration )
 {
   QRect r(startpos * m_scale, 50 * track, duration * m_scale, 49); 
-  ClipItem *item = new ClipItem(xml, track, startpos, r, duration);
+  DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId);
+  ClipItem *item = new ClipItem(baseclip, track, startpos, r, duration);
   scene()->addItem(item);
-  m_document->renderer()->mltInsertClip(m_tracksCount - track, GenTime(startpos, 25), xml);
+  baseclip->addReference();
+  m_document->updateClip(baseclip->getId());
+  m_document->renderer()->mltInsertClip(m_tracksCount - track, GenTime(startpos, m_document->fps()), xml);
+  m_document->renderer()->doRefresh();
+}
+
+ClipItem *CustomTrackView::getClipItemAt(int pos, int track)
+{
+  return (ClipItem *) scene()->itemAt(pos * m_scale, track * 50 + 25);
 }
 
 void CustomTrackView::moveClip ( const QPointF &startPos, const QPointF &endPos )
 {
-  ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + 1) * m_scale, startPos.y() * 50 + 25);
+  ClipItem *item = getClipItemAt(startPos.x() + 1, startPos.y());
   if (!item) {
     kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<<startPos.x() * m_scale * FRAME_SIZE + 1<<", "<<startPos.y() * 50 + 25;
     return;
@@ -470,18 +549,21 @@ void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPo
   int offset;
   if (resizeClipStart) offset = 1;
   else offset = -1;
-  ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + offset) * m_scale, startPos.y() * 50 + 25);
+  ClipItem *item = getClipItemAt(startPos.x() + offset, startPos.y());
   if (!item) {
     kDebug()<<"----------------  ERROR, CANNOT find clip to resize at: "<<startPos;
     return;
   }
   qreal diff = endPos.x() - startPos.x();
   if (resizeClipStart) {
+    m_document->renderer()->mltResizeClipStart(m_tracksCount - item->track(), GenTime(item->endPos(), m_document->fps()), GenTime(endPos.x(), m_document->fps()), GenTime(item->startPos(), m_document->fps()), GenTime(item->cropStart() + diff, m_document->fps()), GenTime(item->cropStart() + diff, m_document->fps()) + GenTime(item->endPos(), m_document->fps()) - GenTime(endPos.x(), m_document->fps()));
     item->resizeStart(endPos.x(), m_scale);
   }
   else {
+    m_document->renderer()->mltResizeClipEnd(m_tracksCount - item->track(), GenTime(item->startPos(), m_document->fps()), GenTime(item->cropStart(), m_document->fps()), GenTime(item->cropStart(), m_document->fps()) + GenTime(endPos.x(), m_document->fps()) - GenTime(item->startPos(), m_document->fps()));
     item->resizeEnd(endPos.x(), m_scale);
   }
+  m_document->renderer()->doRefresh();
 }
 
 double CustomTrackView::getSnapPointForPos(double pos)