Clip.cpp 5.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*****************************************************************************
 * Clip.cpp : Represents a basic container for media informations.
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/** \file
  * This file contains the Clip class implementation.
  */

27
#include <QtDebug>
28
#include "Library.h"
29

30
#include "Clip.h"
31

32 33
const int   Clip::DefaultFPS = 30;

34 35 36 37 38 39
Clip::Clip( Media* parent ) :
        m_parent( parent ),
        m_begin( 0 ),
        m_end( parent->getNbFrames() ),
        m_maxBegin( 0 ),
        m_maxEnd( parent->getNbFrames() )
40
{
41
    m_Uuid = QUuid::createUuid();
42
    computeLength();
43 44
}

45 46 47 48 49 50
Clip::Clip( Clip* creator, qint64 begin, qint64 end ) :
        m_parent( creator->getParent() ),
        m_begin( begin ),
        m_end( end ),
        m_maxBegin( begin ),
        m_maxEnd( end )
51
{
52
    m_Uuid = QUuid::createUuid();
53
    computeLength();
54 55
}

56 57 58 59 60 61
Clip::Clip( Media* parent, qint64 begin, qint64 end /*= -1*/ ) :
        m_parent( parent ),
        m_begin( begin ),
        m_end( end ),
        m_maxBegin( begin ),
        m_maxEnd( end )
62
{
63
    //FIXME: WTF ?
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
64
    Q_ASSERT( parent->getInputType() == Media::File || ( begin == 0 && end == m_parent->getNbFrames() ) );
65 66

    if ( parent->getInputType() == Media::File && end < 0 )
67
    {
68
        m_end = parent->getNbFrames();
69 70
        m_maxEnd = m_end;
    }
71
    m_Uuid = QUuid::createUuid();
72
    computeLength();
73 74
}

75
Clip::Clip( const Clip* clip ) :
76 77 78 79 80 81
        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 ),
82 83 84
        m_notes( clip->m_notes ),
        m_maxBegin( clip->m_begin ),
        m_maxEnd( clip->m_end )
85
{
86
    m_Uuid = QUuid::createUuid();
87 88
}

89
Clip::Clip( const QUuid& uuid, qint64 begin, qint64 end ) :
90
        m_begin( begin),
91 92 93
        m_end( end ),
        m_maxBegin( begin ),
        m_maxEnd( end )
94
{
Ludovic Fauvet's avatar
Ludovic Fauvet committed
95
    Q_UNUSED( end );
96
    Media*  media = Library::getInstance()->media( uuid );
97 98 99 100 101 102
    Q_ASSERT( media != NULL );
    m_parent = media;
    m_Uuid = QUuid::createUuid();
    computeLength();
}

103 104 105 106 107 108 109 110 111 112
Clip::Clip( Media* parent, qint64 begin, qint64 end, const QUuid& uuid )
    : m_parent( parent ),
    m_begin( begin ),
    m_end( end ),
    m_Uuid( uuid )
{
    computeLength();
}


113
Clip::~Clip()
114 115 116
{
}

117
qint64      Clip::getBegin() const
118 119 120 121
{
    return m_begin;
}

122
qint64      Clip::getEnd() const
123 124 125 126
{
    return m_end;
}

127
Media*      Clip::getParent()
128 129 130 131 132
{
    return m_parent;
}

qint64      Clip::getLength() const
133
{
134
    return m_length;
135 136
}

137 138 139 140 141
qint64      Clip::getLengthSecond() const
{
    return m_lengthSeconds;
}

142
void        Clip::computeLength()
143
{
144 145
    if ( m_parent->getInputType() == Media::File )
    {
146
        float   fps = m_parent->getFps();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
147
        if ( fps < 0.1f )
148
            fps = Clip::DefaultFPS;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
149
        m_length = m_end - m_begin;
150
        m_lengthSeconds = qRound64( (float)m_length / fps );
151
        emit lengthUpdated();
152 153 154 155 156 157
    }
    else
    {
        m_length = 0;
        m_lengthSeconds = 0;
    }
158
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
159

160 161 162 163 164 165 166 167 168 169 170 171 172 173
const QStringList&      Clip::getMetaTags() const
{
    return m_metaTags;
}

void            Clip::setMetaTags( const QStringList& tags )
{
    m_metaTags = tags;
}

bool            Clip::matchMetaTag( const QString& tag ) const
{
    if ( tag.length() == 0 )
        return true;
174 175
    if ( m_parent->matchMetaTag( tag ) == true )
        return true;
176 177 178 179 180 181 182 183
    QString metaTag;
    foreach ( metaTag, m_metaTags )
    {
        if ( metaTag.startsWith( tag, Qt::CaseInsensitive ) == true )
            return true;
    }
    return false;
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
184 185 186 187 188 189 190 191 192 193

const   QString&    Clip::getNotes() const
{
    return m_notes;
}

void                Clip::setNotes( const QString& notes )
{
    m_notes = notes;
}
194

195
const QUuid&        Clip::getUuid() const
196
{
197 198
    Q_ASSERT( m_Uuid.isNull() == false );
    return m_Uuid;
199 200
}

201
void                Clip::setBegin( qint64 begin, bool updateMax /*= false*/ )
202 203
{
    Q_ASSERT( begin >= .0f );
204
    if ( begin == m_begin ) return;
205
    m_begin = begin;
206 207
    if ( updateMax == true )
        m_maxBegin = begin;
208
    computeLength();
209 210
}

211
void                Clip::setEnd( qint64 end, bool updateMax /*= false*/ )
212
{
213
    if ( end == m_end ) return;
214
    m_end = end;
215 216
    if ( updateMax == true )
        m_maxEnd = end;
217
    computeLength();
218
}
219

220
void                Clip::setBoundaries( qint64 newBegin, qint64 newEnd, bool updateMax /*= false*/ )
221
{
222
    Q_ASSERT( newBegin < newEnd );
223 224
    if ( newBegin == m_begin && m_end == newEnd )
        return ;
225 226
    m_begin = newBegin;
    m_end = newEnd;
227 228 229 230 231
    if ( updateMax == true )
    {
        m_maxBegin = newBegin;
        m_maxEnd = newEnd;
    }
232 233
    computeLength();
}
234 235 236 237 238 239 240 241 242 243

qint64              Clip::getMaxBegin() const
{
    return m_maxBegin;
}

qint64              Clip::getMaxEnd() const
{
    return m_maxEnd;
}