Clip.cpp 4.97 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
Clip::Clip( Media* parent ) : m_parent( parent ), m_begin( 0 ), m_end( -1 )
33
{
34
    m_Uuid = QUuid::createUuid();
35
    computeLength();
36
37
}

38
Clip::Clip( Clip* creator, qint64 begin, qint64 end ) : m_parent( creator->getParent() ), m_begin( begin ), m_end( end )
39
{
40
    m_Uuid = QUuid::createUuid();
41
    computeLength();
42
43
}

44
Clip::Clip( Media* parent, qint64 begin, qint64 end ) : m_parent( parent ), m_begin( begin ), m_end( end )
45
{
46
    Q_ASSERT( parent->getInputType() == Media::File || ( begin == 0 && end == -1 ) );
47
    m_Uuid = QUuid::createUuid();
48
    computeLength();
49
50
}

51
Clip::Clip( Clip* clip ) :
52
53
54
55
56
57
58
59
        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 )
{
60
    m_Uuid = QUuid::createUuid();
61
62
}

63
Clip::Clip( const QUuid& uuid, qint64 begin, qint64 end ) :
64
        m_begin( begin),
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
65
        m_end( end )
66
{
Ludovic Fauvet's avatar
Ludovic Fauvet committed
67
    Q_UNUSED( end );
68
69
70
71
72
73
74
    Media*  media = Library::getInstance()->getMedia( uuid );
    Q_ASSERT( media != NULL );
    m_parent = media;
    m_Uuid = QUuid::createUuid();
    computeLength();
}

75
Clip::~Clip()
76
77
78
{
}

79
qint64      Clip::getBegin() const
80
81
82
83
{
    return m_begin;
}

84
qint64      Clip::getEnd() const
85
86
87
88
{
    return m_end;
}

89
Media*      Clip::getParent()
90
91
92
93
94
{
    return m_parent;
}

qint64      Clip::getLength() const
95
{
96
    return m_length;
97
98
}

99
100
101
102
103
qint64      Clip::getLengthSecond() const
{
    return m_lengthSeconds;
}

104
void        Clip::computeLength()
105
{
106
107
    if ( m_parent->getInputType() == Media::File )
    {
108
109
110
111
112
113
114
115
116
117
118
119
120
        if ( m_end == -1 )
        {
            m_lengthSeconds = m_parent->getLength() / 1000;
            m_length = m_parent->getnbFrames();
        }
        else
        {
            unsigned int   fps = m_parent->getFps();
            if ( fps < 0.1f )
                fps = FPS;
            m_lengthSeconds = ( m_end - m_begin ) / 1000;
            m_length = m_lengthSeconds * fps;
        }
121
        emit lengthUpdated();
122
123
124
125
126
127
    }
    else
    {
        m_length = 0;
        m_lengthSeconds = 0;
    }
128
    qDebug() << "Length ==" << m_length << "and in seconds:" << m_lengthSeconds;
129
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
130

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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;
    QString metaTag;
    foreach ( metaTag, m_metaTags )
    {
        if ( metaTag.startsWith( tag, Qt::CaseInsensitive ) == true )
            return true;
    }
    return false;
//    m_metaTags.contains( tag, Qt::CaseInsensitive );
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
154
155
156
157
158
159
160
161
162
163

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

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

165
const QUuid&        Clip::getUuid() const
166
{
167
168
    Q_ASSERT( m_Uuid.isNull() == false );
    return m_Uuid;
169
170
}

171
void                Clip::setBegin( qint64 begin )
172
173
{
    Q_ASSERT( begin >= .0f );
174
    if ( begin == m_begin ) return;
175
    m_begin = begin;
176
177
    computeLength();
    emit lengthUpdated();
178
179
}

180
void                Clip::setEnd( qint64 end )
181
182
{
    Q_ASSERT( end <= 1.0f );
183
    if ( end == m_end ) return;
184
    m_end = end;
185
186
    computeLength();
    emit lengthUpdated();
187
}
188
189
190

Clip*               Clip::split( float newEnd )
{
191
    Q_ASSERT( newEnd != m_end );
192
193
194
195
196
    Clip*   newClip = new Clip( this, newEnd, m_end );
    m_end = newEnd;
    computeLength();
    return newClip;
}
197
198
199
200
201

Clip*               Clip::split( qint64 endFrame )
{
    //FIXME the conversion *breaks* clip spliting
    //But we don't have any other choice for now, VLC only support float positions!
202
    float newEnd = (float) endFrame / m_parent->getnbFrames();
203
204
    return split( newEnd );
}