Clip.cpp 5.1 KB
Newer Older
1 2 3
/*****************************************************************************
 * Clip.cpp : Represents a basic container for media informations.
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * 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
Clip::Clip( Media *parent, const QString& uuid ) :
35 36
        m_parent( parent ),
        m_begin( 0 ),
37
        m_end( parent->nbFrames() ),
38
        m_maxBegin( 0 ),
39 40
        m_maxEnd( parent->nbFrames() ),
        m_rootClip( NULL )
41
{
42
    Q_ASSERT( parent->baseClip() == NULL );
43
    if ( uuid.isEmpty() == true )
44
        m_uuid = QUuid::createUuid();
45
    else
46
        m_uuid = QUuid( uuid );
47
    computeLength();
48 49
}

50 51
Clip::Clip( Clip *clip, qint64 begin /*= 0*/, qint64 end /*= -1*/ ) :
        m_parent( clip->m_parent ),
52 53
        m_begin( begin ),
        m_end( end ),
54 55 56
        m_metaTags( clip->m_metaTags ),
        m_notes( clip->m_notes ),
        m_maxBegin( clip->m_begin ),
57 58
        m_maxEnd( clip->m_end ),
        m_rootClip( clip->getParent()->baseClip() )
59
{
60 61 62 63
    if ( begin == -1 )
        m_begin = clip->begin();
    if ( end == -1 )
        m_end = clip->end();
64
    m_uuid = QUuid::createUuid();
65
    computeLength();
66 67
}

68 69
Clip::Clip( Media *parent, qint64 begin, qint64 end /*= -1*/,
            const QString &uuid /*= QString()*/ ) :
70 71 72 73
        m_parent( parent ),
        m_begin( begin ),
        m_end( end ),
        m_maxBegin( begin ),
74 75
        m_maxEnd( end ),
        m_rootClip( parent->baseClip() )
76
{
77
    if ( end < 0 )
78
    {
79
        m_end = parent->nbFrames();
80 81
        m_maxEnd = m_end;
    }
82 83 84 85
    if ( uuid.isEmpty() == true )
        m_uuid = QUuid::createUuid();
    else
        m_uuid = QUuid( uuid );
86 87 88
    computeLength();
}

89
Clip::~Clip()
90 91 92
{
}

93 94
qint64
Clip::begin() const
95 96 97 98
{
    return m_begin;
}

99 100
qint64
Clip::end() const
101 102 103 104
{
    return m_end;
}

105 106
Media*
Clip::getParent()
107 108 109 110
{
    return m_parent;
}

111 112
qint64
Clip::length() const
113
{
114
    return m_length;
115 116
}

117 118
qint64
Clip::lengthSecond() const
119 120 121 122
{
    return m_lengthSeconds;
}

123 124
void
Clip::computeLength()
125
{
126
    if ( m_parent->inputType() == Media::File )
127
    {
128
        float   fps = m_parent->fps();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
129
        if ( fps < 0.1f )
130
            fps = Clip::DefaultFPS;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
131
        m_length = m_end - m_begin;
132
        m_lengthSeconds = qRound64( (float)m_length / fps );
133
        emit lengthUpdated();
134 135 136 137 138 139
    }
    else
    {
        m_length = 0;
        m_lengthSeconds = 0;
    }
140
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
141

142 143
const QStringList&
Clip::metaTags() const
144 145 146 147
{
    return m_metaTags;
}

148 149
void
Clip::setMetaTags( const QStringList &tags )
150 151 152 153
{
    m_metaTags = tags;
}

154 155
bool
Clip::matchMetaTag( const QString &tag ) const
156 157 158
{
    if ( tag.length() == 0 )
        return true;
159 160
    if ( m_parent->matchMetaTag( tag ) == true )
        return true;
161 162 163 164 165 166 167 168
    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
169

170 171
const QString&
Clip::notes() const
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
172 173 174 175
{
    return m_notes;
}

176 177
void
Clip::setNotes( const QString &notes )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
178 179 180
{
    m_notes = notes;
}
181

182 183
const QUuid&
Clip::uuid() const
184
{
185 186
    Q_ASSERT( m_uuid.isNull() == false );
    return m_uuid;
187 188
}

189 190 191
void
Clip::setUuid( const QUuid &uuid )
{
192
    m_uuid = uuid;
193 194
}

195 196
void
Clip::setBegin( qint64 begin, bool updateMax /*= false*/ )
197 198
{
    Q_ASSERT( begin >= .0f );
199
    if ( begin == m_begin ) return;
200
    m_begin = begin;
201 202
    if ( updateMax == true )
        m_maxBegin = begin;
203
    computeLength();
204 205
}

206 207
void
Clip::setEnd( qint64 end, bool updateMax /*= false*/ )
208
{
209
    if ( end == m_end ) return;
210
    m_end = end;
211 212
    if ( updateMax == true )
        m_maxEnd = end;
213
    computeLength();
214
}
215

216 217
void
Clip::setBoundaries( qint64 newBegin, qint64 newEnd, bool updateMax /*= false*/ )
218
{
219
    Q_ASSERT( newBegin < newEnd );
220 221
    if ( newBegin == m_begin && m_end == newEnd )
        return ;
222 223
    m_begin = newBegin;
    m_end = newEnd;
224 225 226 227 228
    if ( updateMax == true )
    {
        m_maxBegin = newBegin;
        m_maxEnd = newEnd;
    }
229 230
    computeLength();
}
231

232 233
qint64
Clip::maxBegin() const
234 235 236 237
{
    return m_maxBegin;
}

238 239
qint64
Clip::maxEnd() const
240 241 242
{
    return m_maxEnd;
}
243

244 245 246 247 248 249
Clip*
Clip::rootClip()
{
    return m_rootClip;
}

250
bool
251
Clip::isRootClip() const
252
{
253
    return ( m_rootClip == NULL );
254
}