[vlmc-devel] commit: Clip: cleaning up the mess with CTORs (Hugo Beauzee-Luyssen )

git at videolan.org git at videolan.org
Wed Mar 10 14:52:53 CET 2010


vlmc | branch: master | Hugo Beauzee-Luyssen <beauze.h at gmail.com> | Mon Mar  8 20:05:59 2010 +0100| [48db69f0a315965c190f0abcce8b9e94d2f813ef] | committer: Hugo Beauzee-Luyssen 

Clip: cleaning up the mess with CTORs

Please : Do NOT add anyother contructor. There is enough right now.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=48db69f0a315965c190f0abcce8b9e94d2f813ef
---

 src/Media/Clip.cpp            |   65 +++++++++++------------------------------
 src/Media/Clip.h              |   32 +++++++++++++++++---
 src/Workflow/MainWorkflow.cpp |    9 +++--
 3 files changed, 49 insertions(+), 57 deletions(-)

diff --git a/src/Media/Clip.cpp b/src/Media/Clip.cpp
index a6e611d..ae53eb2 100644
--- a/src/Media/Clip.cpp
+++ b/src/Media/Clip.cpp
@@ -45,74 +45,43 @@ Clip::Clip( Media *parent, const QString& uuid ) :
     computeLength();
 }
 
-Clip::Clip( Clip *creator, qint64 begin, qint64 end ) :
-        m_parent( creator->getParent() ),
+Clip::Clip( Clip *clip, qint64 begin /*= 0*/, qint64 end /*= -1*/ ) :
+        m_parent( clip->m_parent ),
         m_begin( begin ),
         m_end( end ),
-        m_maxBegin( begin ),
-        m_maxEnd( end )
+        m_metaTags( clip->m_metaTags ),
+        m_notes( clip->m_notes ),
+        m_maxBegin( clip->m_begin ),
+        m_maxEnd( clip->m_end )
 {
+    if ( begin == -1 )
+        m_begin = clip->begin();
+    if ( end == -1 )
+        m_end = clip->end();
     m_uuid = QUuid::createUuid();
     computeLength();
 }
 
-Clip::Clip( Media *parent, qint64 begin, qint64 end /*= -1*/ ) :
+Clip::Clip( Media *parent, qint64 begin, qint64 end /*= -1*/,
+            const QString &uuid /*= QString()*/ ) :
         m_parent( parent ),
         m_begin( begin ),
         m_end( end ),
         m_maxBegin( begin ),
         m_maxEnd( end )
 {
-    //FIXME: WTF ?
-    Q_ASSERT( parent->inputType() == Media::File || ( begin == 0 && end == m_parent->nbFrames() ) );
-
-    if ( parent->inputType() == Media::File && end < 0 )
+    if ( end < 0 )
     {
         m_end = parent->nbFrames();
         m_maxEnd = m_end;
     }
-    m_uuid = QUuid::createUuid();
-    computeLength();
-}
-
-Clip::Clip( const Clip *clip ) :
-        m_parent( clip->m_parent ),
-        m_begin( clip->m_begin ),
-        m_end( clip->m_end ),
-        m_length( clip->m_length ),
-        m_lengthSeconds( clip->m_lengthSeconds ),
-        m_metaTags( clip->m_metaTags ),
-        m_notes( clip->m_notes ),
-        m_maxBegin( clip->m_begin ),
-        m_maxEnd( clip->m_end )
-{
-    m_uuid = QUuid::createUuid();
-}
-
-Clip::Clip( const QUuid &uuid, qint64 begin, qint64 end ) :
-        m_begin( begin),
-        m_end( end ),
-        m_maxBegin( begin ),
-        m_maxEnd( end )
-{
-    Q_UNUSED( end );
-    Media*  media = Library::getInstance()->media( uuid );
-    Q_ASSERT( media != NULL );
-    m_parent = media;
-    m_uuid = QUuid::createUuid();
-    computeLength();
-}
-
-Clip::Clip( Media *parent, qint64 begin, qint64 end, const QUuid &uuid )
-    : m_parent( parent ),
-    m_begin( begin ),
-    m_end( end ),
-    m_uuid( uuid )
-{
+    if ( uuid.isEmpty() == true )
+        m_uuid = QUuid::createUuid();
+    else
+        m_uuid = QUuid( uuid );
     computeLength();
 }
 
-
 Clip::~Clip()
 {
 }
diff --git a/src/Media/Clip.h b/src/Media/Clip.h
index 536ab15..d572f90 100644
--- a/src/Media/Clip.h
+++ b/src/Media/Clip.h
@@ -42,12 +42,34 @@ class   Clip : public QObject
 
     public:
         static const int DefaultFPS;
+        /**
+         *  \brief  Construct the base clip for a Media.
+         *
+         *  This clip will represent the whole media as a Clip.
+         *  \param  parent  The media to represent.
+         *  \param  uuid    A forced unique id. If not given, a new unique id will be generated.
+         */
         Clip( Media *parent, const QString& uuid = QString() );
-        Clip( Media *parent, qint64 begin, qint64 end = -1 );
-        Clip( Clip *creator, qint64 begin, qint64 end );
-        Clip( const Clip *clip );
-        Clip( const QUuid &uuid, qint64 begin = 0, qint64 end = -1 );
-        Clip( Media *parent, qint64 begin, qint64 end, const QUuid &uuid );
+        /**
+         *  \brief  Constructs a Clip that is a subpart of a Media.
+         *
+         *  \param  parent  The media to represent.
+         *  \param  begin   The clip beginning (in frames, from the parent's beginning)
+         *  \param  end     The end, in frames, from the parent's beginning. If not given,
+         *                  the end of the parent will be used.
+         *  \param  uuid    A unique identifier. If not given, one will be generated.
+         */
+        Clip( Media *parent, qint64 begin, qint64 end = -1, const QString &uuid = QString() );
+        /**
+         *  \brief  Clones a Clip, potentially with a new begin and end.
+         *
+         *  \param  creator The clip to clone.
+         *  \param  begin   The clip beginning (in frames, from the parent's beginning).
+         *                  If not given, 0 is assumed.
+         *  \param  end     The end, in frames, from the parent's beginning. If not given,
+         *                  the end of the parent will be used.
+         */
+        Clip( Clip *creator, qint64 begin = -1, qint64 end = -1 );
         virtual ~Clip();
 
         qint64              begin() const;
diff --git a/src/Workflow/MainWorkflow.cpp b/src/Workflow/MainWorkflow.cpp
index 031ded5..e4d607e 100644
--- a/src/Workflow/MainWorkflow.cpp
+++ b/src/Workflow/MainWorkflow.cpp
@@ -312,7 +312,7 @@ MainWorkflow::loadProject( const QDomElement &project )
         {
             //Iterate over clip fields:
             QDomElement clipProperty = clip.firstChild().toElement();
-            QUuid                       parent;
+            QUuid                       parentUuid;
             qint64                      begin;
             qint64                      end;
             qint64                      startPos;
@@ -324,7 +324,7 @@ MainWorkflow::loadProject( const QDomElement &project )
                 bool    ok;
 
                 if ( tagName == "parent" )
-                    parent = QUuid( clipProperty.text() );
+                    parentUuid = QUuid( clipProperty.text() );
                 else if ( tagName == "begin" )
                 {
                     begin = clipProperty.text().toLongLong( &ok );
@@ -368,9 +368,10 @@ MainWorkflow::loadProject( const QDomElement &project )
                 clipProperty = clipProperty.nextSibling().toElement();
             }
 
-            if ( Library::getInstance()->media( parent ) != NULL )
+            if ( Library::getInstance()->media( parentUuid ) != NULL )
             {
-                Clip        *c = new Clip( parent, begin, end );
+                Clip    *c = new Clip( Library::getInstance()->media( parentUuid ),
+                                       begin, end, parentUuid.toString() );
                 addClip( c, trackId, startPos, trackType );
             }
 



More information about the Vlmc-devel mailing list