]> git.sesse.net Git - kdenlive/commitdiff
Remove code duplication
authorTill Theato <root@ttill.de>
Tue, 21 Sep 2010 19:52:10 +0000 (19:52 +0000)
committerTill Theato <root@ttill.de>
Tue, 21 Sep 2010 19:52:10 +0000 (19:52 +0000)
svn path=/trunk/kdenlive/; revision=4921

src/clipitem.cpp
src/clipitem.h
src/customtrackview.cpp

index 0cd508bb093afead0ce35c38d170d05feb29053f..c346cc49571e4b3234fed9c061138d12b90cef23 100644 (file)
@@ -61,7 +61,8 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, i
     setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1);
 
     // set speed independant info
-    if (m_speed <= 0 && m_speed > -1) m_speed = 1.0;
+    if (m_speed <= 0 && m_speed > -1)
+        m_speed = -1.0;
     m_speedIndependantInfo = m_info;
     m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
     m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
@@ -69,10 +70,11 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, i
     m_videoPix = KIcon("kdenlive-show-video").pixmap(QSize(16, 16));
     m_audioPix = KIcon("kdenlive-show-audio").pixmap(QSize(16, 16));
 
-    if (m_speed == 1.0) m_clipName = m_clip->name();
-    else {
+    if (m_speed == 1.0)
+        m_clipName = m_clip->name();
+    else
         m_clipName = m_clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + '%';
-    }
+
     m_producer = m_clip->getId();
     m_clipType = m_clip->clipType();
     //m_cropStart = info.cropStart;
@@ -1584,7 +1586,7 @@ void ClipItem::setSpeed(const double speed, const int strobe)
 {
     m_speed = speed;
     if (m_speed <= 0 && m_speed > -1)
-        m_speed = 1.0;
+        m_speed = -1.0;
     m_strobe = strobe;
     if (m_speed == 1.0) m_clipName = baseClip()->name();
     else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
@@ -1852,4 +1854,14 @@ QList <int> ClipItem::updatePanZoom(int width, int height, int cut)
     return effectPositions;
 }
 
+Mlt::Producer *ClipItem::getProducer(int track, bool trackSpecific)
+{
+    if (isAudioOnly())
+        return m_clip->audioProducer(track);
+    else if (isVideoOnly())
+        return m_clip->videoProducer();
+    else
+        return m_clip->producer(trackSpecific ? track : -1);
+}
+
 #include "clipitem.moc"
index 473ec862949c0c483a63162ab9755c982aefae35..e5b02450d1ed91d8d5267f06be6b59a241449494 100644 (file)
 class DocClipBase;
 class Transition;
 
+namespace Mlt
+{
+class Producer;
+};
 
 class ClipItem : public AbstractClipItem
 {
@@ -169,6 +173,13 @@ public:
      * Can be used for all effects using mlt_geometry with keyframes, but at the moment Pan & Zoom is the only one. */
     QList <int> updatePanZoom(int width, int height, int cut = 0);
 
+    /** Returns the necessary (audio, video, general) producer.
+     * @param track Track of the requested producer
+     * @param trackSpecific (default = true) Whether to return general producer for a specific track.
+     * @return Fitting producer
+     * Which producer is returned depends on the type of this clip (audioonly, videoonly, normal) */
+    Mlt::Producer *getProducer(int track, bool trackSpecific = true);
+
 protected:
     //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
index 28f0c695766f6429fd451203679ba93f69629a8e..974cb86bd28fdb306e46aaae62134564e7a73396 100644 (file)
@@ -2545,10 +2545,7 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
                 if (clip->speed() != 1.0) continue;
                 // We add a move clip command so that we get the correct producer for new track number
                 if (clip->clipType() == AV || clip->clipType() == AUDIO) {
-                    Mlt::Producer *prod;
-                    if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track);
-                    else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
-                    else prod = clip->baseClip()->producer(clipinfo.track);
+                    Mlt::Producer *prod = clip->getProducer(clipinfo.track);
                     if (m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod) == false) {
                         // problem updating clip
                         emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage);
@@ -2619,10 +2616,7 @@ void CustomTrackView::removeTrack(int ix)
             ItemInfo clipinfo = clip->info();
             // We add a move clip command so that we get the correct producer for new track number
             if (clip->clipType() == AV || clip->clipType() == AUDIO) {
-                Mlt::Producer *prod;
-                if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track);
-                else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
-                else prod = clip->baseClip()->producer(clipinfo.track);
+                Mlt::Producer *prod = clip->getProducer(clipinfo.track);
                 if (!m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod)) {
                     emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage);
                 }
@@ -3143,10 +3137,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             // we are moving one clip, easy
             if (m_dragItem->type() == AVWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
                 ClipItem *item = static_cast <ClipItem *>(m_dragItem);
-                Mlt::Producer *prod;
-                if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(info.track);
-                else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer();
-                else prod = item->baseClip()->producer(info.track);
+                Mlt::Producer *prod = item->getProducer(info.track);
                 bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - info.track), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(info.startPos.frames(m_document->fps())), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
 
                 if (success) {
@@ -3347,15 +3338,8 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                     if (item->type() == AVWIDGET) {
                         ClipItem *clip = static_cast <ClipItem*>(item);
                         info.track = m_document->tracksCount() - info.track;
-                        Mlt::Producer *prod;
                         adjustTimelineClips(m_scene->editMode(), clip, ItemInfo(), moveGroup);
-                        if (clip->isAudioOnly())
-                            prod = clip->baseClip()->audioProducer(info.track);
-                        else if (clip->isVideoOnly())
-                            prod = clip->baseClip()->videoProducer();
-                        else
-                            prod = clip->baseClip()->producer(info.track);
-                        m_document->renderer()->mltInsertClip(info, clip->xml(), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
+                        m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(info.track), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
                         for (int i = 0; i < clip->effectsCount(); i++) {
                             m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false);
                         }
@@ -3732,7 +3716,9 @@ void CustomTrackView::changeClipSpeed()
 
 void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id)
 {
-    DocClipBase *baseclip = m_document->clipManager()->getClipById(id);
+    Q_UNUSED(id);
+    //DocClipBase *baseclip = m_document->clipManager()->getClipById(id);
+
     ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
     if (!item) {
         kDebug() << "ERROR: Cannot find clip for speed change";
@@ -3740,22 +3726,17 @@ void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependant
         return;
     }
     info.track = m_document->tracksCount() - item->track();
-    int endPos;
-    if (item->isVideoOnly())
-        endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->videoProducer());
-    else if (item->isAudioOnly())
-        endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->audioProducer(item->track()));
-    else
-        endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->producer());
+    int endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, item->getProducer(item->track(), false));
     if (endPos >= 0) {
         item->setSpeed(speed, strobe);
         item->updateRectGeometry();
-        if (item->cropDuration().frames(m_document->fps()) != endPos) {
+        if (item->cropDuration().frames(m_document->fps()) != endPos)
             item->resizeEnd((int) info.startPos.frames(m_document->fps()) + endPos - 1);
-        }
         updatePositionEffects(item, info);
         setDocumentModified();
-    } else emit displayMessage(i18n("Invalid clip"), ErrorMessage);
+    } else {
+        emit displayMessage(i18n("Invalid clip"), ErrorMessage);
+    }
 }
 
 void CustomTrackView::cutSelectedClips()
@@ -3982,17 +3963,15 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i
     baseclip->addReference();
     m_document->updateClip(baseclip->getId());
     info.track = m_document->tracksCount() - info.track;
-    Mlt::Producer *prod;
-    if (item->isAudioOnly()) prod = baseclip->audioProducer(info.track);
-    else if (item->isVideoOnly()) prod = baseclip->videoProducer();
-    else prod = baseclip->producer(info.track);
-    m_document->renderer()->mltInsertClip(info, xml, prod, overwrite, push);
+    m_document->renderer()->mltInsertClip(info, xml, item->getProducer(info.track), overwrite, push);
     for (int i = 0; i < item->effectsCount(); i++) {
         m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(item->effectAt(i)), false);
     }
     setDocumentModified();
-    if (refresh) m_document->renderer()->doRefresh();
-    if (!baseclip->isPlaceHolder()) m_waitingThumbs.append(item);
+    if (refresh)
+        m_document->renderer()->doRefresh();
+    if (!baseclip->isPlaceHolder())
+        m_waitingThumbs.append(item);
     m_thumbsTimer.start();
 }
 
@@ -4129,10 +4108,7 @@ void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end, bool re
         kDebug() << "----------------  ERROR, CANNOT find clip to move at.. ";
         return;
     }
-    Mlt::Producer *prod;
-    if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(end.track);
-    else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer();
-    else prod = item->baseClip()->producer(end.track);
+    Mlt::Producer *prod = item->getProducer(end.track);
 
     bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - start.track), (int)(m_document->tracksCount() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()), prod);
     if (success) {
@@ -4256,14 +4232,7 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
             if (item->type() == AVWIDGET) {
                 ClipItem *clip = static_cast <ClipItem*>(item);
                 info.track = m_document->tracksCount() - info.track;
-                Mlt::Producer *prod;
-                if (clip->isAudioOnly())
-                    prod = clip->baseClip()->audioProducer(info.track);
-                else if (clip->isVideoOnly())
-                    prod = clip->baseClip()->videoProducer();
-                else
-                    prod = clip->baseClip()->producer(info.track);
-                m_document->renderer()->mltInsertClip(info, clip->xml(), prod);
+                m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(info.track));
                 for (int i = 0; i < clip->effectsCount(); i++) {
                     m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false);
                 }