MLTTrack.cpp 3.65 KB
Newer Older
luyikei's avatar
luyikei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************
 * MLTTrack.cpp:  Wrapper of Mlt::Track
 *****************************************************************************
 * Copyright (C) 2008-2016 VideoLAN
 *
 * Authors: Yikei Lu <luyikei.qmltu@gmail.com>
 *
 * 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.
 *****************************************************************************/

23 24 25 26
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

luyikei's avatar
luyikei committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include "MLTTrack.h"
#include "MLTProfile.h"
#include "MLTBackend.h"

#include <mlt++/MltPlaylist.h>

#include <cassert>
#include <cstring>

using namespace Backend::MLT;

MLTTrack::MLTTrack()
    : MLTTrack( Backend::instance()->profile() )
{
}

MLTTrack::MLTTrack( IProfile &profile )
luyikei's avatar
luyikei committed
44
    : MLTInput()
luyikei's avatar
luyikei committed
45 46 47 48 49 50 51 52 53 54
{
    MLTProfile& mltProfile = static_cast<MLTProfile&>( profile );
    m_playlist = new Mlt::Playlist( *mltProfile.m_profile );
}

MLTTrack::~MLTTrack()
{
    delete m_playlist;
}

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
Mlt::Playlist*
MLTTrack::playlist()
{
    return m_playlist;
}

Mlt::Playlist*
MLTTrack::playlist() const
{
    return m_playlist;
}

Mlt::Producer*
MLTTrack::producer()
{
    return playlist();
}

Mlt::Producer*
MLTTrack::producer() const
{
    return playlist();
}

luyikei's avatar
luyikei committed
79
bool
luyikei's avatar
luyikei committed
80
MLTTrack::insertAt( Backend::IInput& input, int64_t startFrame )
luyikei's avatar
luyikei committed
81
{
luyikei's avatar
luyikei committed
82 83
    auto mltInput = dynamic_cast<MLTInput*>( &input );
    assert( mltInput );
84
    return playlist()->insert_at( (int)startFrame, mltInput->producer(), 1 ) != -1;
luyikei's avatar
luyikei committed
85 86
}

87
void
88
MLTTrack::remove( int index )
89 90 91 92 93
{
    std::unique_ptr<Mlt::Producer> mltProducer( playlist()->replace_with_blank( index ) );
    playlist()->consolidate_blanks( 0 );
}

luyikei's avatar
luyikei committed
94
bool
luyikei's avatar
luyikei committed
95
MLTTrack::append( Backend::IInput& input )
luyikei's avatar
luyikei committed
96
{
luyikei's avatar
luyikei committed
97 98
    auto mltInput = dynamic_cast<MLTInput*>( &input );
    assert( mltInput );
99
    return !playlist()->append( *mltInput->producer() );
luyikei's avatar
luyikei committed
100 101 102
}

bool
103
MLTTrack::move( int64_t src, int64_t dist )
luyikei's avatar
luyikei committed
104
{
105 106 107 108 109
    std::unique_ptr<Mlt::Producer> prod(
                playlist()->replace_with_blank( playlist()->get_clip_index_at( src ) ) );
    if ( !prod )
        return false;
    playlist()->consolidate_blanks( 0 );
110
    return playlist()->insert_at( dist, prod.get(), 1 ) != -1;
luyikei's avatar
luyikei committed
111 112
}

luyikei's avatar
luyikei committed
113
Backend::IInput*
luyikei's avatar
luyikei committed
114 115
MLTTrack::clip( int index ) const
{
116
    return new MLTInput( playlist()->get_clip( index ) );
luyikei's avatar
luyikei committed
117 118
}

luyikei's avatar
luyikei committed
119
Backend::IInput*
luyikei's avatar
luyikei committed
120 121
MLTTrack::clipAt( int64_t position ) const
{
122
    return new MLTInput( playlist()->get_clip_at( (int)position ) );
luyikei's avatar
luyikei committed
123 124 125 126 127
}

bool
MLTTrack::resizeClip( int clip, int64_t begin, int64_t end )
{
128 129 130 131 132 133 134
    auto oldEnd = playlist()->get_clip( clip )->get_out();
    auto ret = playlist()->resize_clip( clip, (int)begin, (int)end );
    if ( !ret && (int)end < oldEnd )
    {
        playlist()->insert_blank( clip + 1, oldEnd - end - 1 );
    }
    return !ret;
luyikei's avatar
luyikei committed
135 136 137 138 139
}

int
MLTTrack::clipIndexAt( int64_t position )
{
140
    return playlist()->get_clip_index_at( (int)position );
luyikei's avatar
luyikei committed
141 142 143 144 145
}

int
MLTTrack::count() const
{
146
    return playlist()->count();
luyikei's avatar
luyikei committed
147 148 149 150 151
}

void
MLTTrack::clear()
{
152
    playlist()->clear();
luyikei's avatar
luyikei committed
153 154 155
}

void
156
MLTTrack::hide( Backend::HideType hydeType )
luyikei's avatar
luyikei committed
157
{
158
    playlist()->set( "hide", static_cast<int>( hydeType ) );
luyikei's avatar
luyikei committed
159
}