2 * MltProducer.cpp - MLT Wrapper
3 * Copyright (C) 2004-2005 Charles Yates
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "MltProducer.h"
22 #include "MltFilter.h"
23 #include "MltProfile.h"
25 #include "MltConsumer.h"
28 Producer::Producer( ) :
34 Producer::Producer( Profile& profile, const char *id, const char *service ) :
38 if ( id != NULL && service != NULL )
39 instance = mlt_factory_producer( profile.get_profile(), id, service );
41 instance = mlt_factory_producer( profile.get_profile(), NULL, id != NULL ? id : service );
44 Producer::Producer( Service &producer ) :
48 mlt_service_type type = producer.type( );
49 if ( type == producer_type || type == playlist_type ||
50 type == tractor_type || type == multitrack_type )
52 instance = ( mlt_producer )producer.get_service( );
57 Producer::Producer( mlt_producer producer ) :
64 Producer::Producer( Producer &producer ) :
65 Mlt::Service( producer ),
66 instance( producer.get_producer( ) ),
72 Producer::Producer( Producer *producer ) :
73 instance( producer != NULL ? producer->get_producer( ) : NULL ),
80 Producer::~Producer( )
83 mlt_producer_close( instance );
87 mlt_producer Producer::get_producer( )
92 mlt_producer Producer::get_parent( )
94 return get_producer( ) != NULL && mlt_producer_cut_parent( get_producer( ) ) != NULL ? mlt_producer_cut_parent( get_producer( ) ) : get_producer( );
97 Producer &Producer::parent( )
99 if ( is_cut( ) && parent_ == NULL )
100 parent_ = new Producer( get_parent( ) );
101 return parent_ == NULL ? *this : *parent_;
104 mlt_service Producer::get_service( )
106 return mlt_producer_service( get_producer( ) );
109 int Producer::seek( int position )
111 return mlt_producer_seek( get_producer( ), position );
114 int Producer::position( )
116 return mlt_producer_position( get_producer( ) );
119 int Producer::frame( )
121 return mlt_producer_frame( get_producer( ) );
124 int Producer::set_speed( double speed )
126 return mlt_producer_set_speed( get_producer( ), speed );
129 int Producer::pause()
133 if ( get_speed() != 0 )
135 Consumer consumer( ( mlt_consumer ) mlt_service_consumer( get_service( ) ) );
136 Event *event = consumer.setup_wait_for( "consumer-sdl-paused" );
138 result = mlt_producer_set_speed( get_producer( ), 0 );
139 if ( result == 0 && consumer.is_valid() && !consumer.is_stopped() )
140 consumer.wait_for( event );
147 double Producer::get_speed( )
149 return mlt_producer_get_speed( get_producer( ) );
152 double Producer::get_fps( )
154 return mlt_producer_get_fps( get_producer( ) );
157 int Producer::set_in_and_out( int in, int out )
159 return mlt_producer_set_in_and_out( get_producer( ), in, out );
162 int Producer::get_in( )
164 return mlt_producer_get_in( get_producer( ) );
167 int Producer::get_out( )
169 return mlt_producer_get_out( get_producer( ) );
172 int Producer::get_length( )
174 return mlt_producer_get_length( get_producer( ) );
177 int Producer::get_playtime( )
179 return mlt_producer_get_playtime( get_producer( ) );
182 Producer *Producer::cut( int in, int out )
184 mlt_producer producer = mlt_producer_cut( get_producer( ), in, out );
185 Producer *result = new Producer( producer );
186 mlt_producer_close( producer );
190 bool Producer::is_cut( )
192 return mlt_producer_is_cut( get_producer( ) ) != 0;
195 bool Producer::is_blank( )
197 return mlt_producer_is_blank( get_producer( ) ) != 0;
200 bool Producer::same_clip( Producer &that )
202 return mlt_producer_cut_parent( get_producer( ) ) == mlt_producer_cut_parent( that.get_producer( ) );
205 bool Producer::runs_into( Producer &that )
207 return same_clip( that ) && get_out( ) == ( that.get_in( ) - 1 );
210 void Producer::optimise( )
212 mlt_producer_optimise( get_producer( ) );
215 int Producer::clear( )
217 return mlt_producer_clear( get_producer( ) );