Clip.cpp 4.45 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.0f ), m_end( 1.0f )
33
{
34
    m_Uuid = QUuid::createUuid();
35
    computeLength();
36
37
}

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

Clip::Clip( Media* parent, float begin, float end ) : m_parent( parent ), m_begin( begin ), m_end( end )
45
{
46
    Q_ASSERT( parent->getInputType() == Media::File || ( begin == .0f && end == .0f ) );
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
64
65
66
Clip::Clip( const QUuid& uuid, float begin, float end ) :
        m_begin( begin),
        m_end( 1.0f )
{
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
float       Clip::getBegin() const
80
81
82
83
{
    return m_begin;
}

84
float       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
97
98
{
    return m_length;
}

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

104
void        Clip::computeLength()
105
{
106
107
108
109
110
111
112
113
114
115
116
117
118
119
    if ( m_parent->getInputType() == Media::File )
    {
        unsigned int   fps = m_parent->getFps();
        if ( fps < 0.1f )
            fps = FPS;
        qint64 nbMs = (qint64)( ( m_end - m_begin ) * (float)m_parent->getLength() );
        m_lengthSeconds = nbMs / 1000;
        m_length = (nbMs / 1000) * fps;
    }
    else
    {
        m_length = 0;
        m_lengthSeconds = 0;
    }
120
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
121

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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
145
146
147
148
149
150
151
152
153
154

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

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

156
const QUuid&        Clip::getUuid() const
157
{
158
159
    Q_ASSERT( m_Uuid.isNull() == false );
    return m_Uuid;
160
161
}

162
163
164
void                Clip::setBegin( float begin )
{
    Q_ASSERT( begin >= .0f );
165
    if ( begin == m_begin ) return;
166
    m_begin = begin;
167
168
    computeLength();
    emit lengthUpdated();
169
170
171
172
173
}

void                Clip::setEnd( float end )
{
    Q_ASSERT( end <= 1.0f );
174
    if ( end == m_end ) return;
175
    m_end = end;
176
177
    computeLength();
    emit lengthUpdated();
178
}
179
180
181
182
183
184

Clip*               Clip::split( float newEnd )
{
    Clip*   newClip = new Clip( this, newEnd, m_end );
    m_end = newEnd;
    computeLength();
185
    emit lengthUpdated();
186
187
    return newClip;
}