]> git.sesse.net Git - mlt/blob - src/mlt++/MltProducer.cpp
Add mlt_transition_get_progress().
[mlt] / src / mlt++ / MltProducer.cpp
1 /**
2  * MltProducer.cpp - MLT Wrapper
3  * Copyright (C) 2004-2005 Charles Yates
4  * Author: Charles Yates <charles.yates@pandora.be>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "MltProducer.h"
22 #include "MltFilter.h"
23 #include "MltProfile.h"
24 #include "MltEvent.h"
25 #include "MltConsumer.h"
26 using namespace Mlt;
27
28 Producer::Producer( ) :
29         instance( NULL ),
30         parent_( NULL )
31 {
32 }
33
34 Producer::Producer( Profile& profile, const char *id, const char *service ) :
35         instance( NULL ),
36         parent_( NULL )
37 {
38         if ( id != NULL && service != NULL )
39                 instance = mlt_factory_producer( profile.get_profile(), id, service );
40         else
41                 instance = mlt_factory_producer( profile.get_profile(), NULL, id != NULL ? id : service );
42 }
43
44 Producer::Producer( Service &producer ) :
45         instance( NULL ),
46         parent_( NULL )
47 {
48         mlt_service_type type = producer.type( );
49         if ( type == producer_type || type == playlist_type || 
50                  type == tractor_type || type == multitrack_type )
51         {
52                 instance = ( mlt_producer )producer.get_service( );
53                 inc_ref( );
54         }
55 }
56
57 Producer::Producer( mlt_producer producer ) :
58         instance( producer ),
59         parent_( NULL )
60 {
61         inc_ref( );
62 }
63
64 Producer::Producer( Producer &producer ) :
65         Mlt::Service( producer ),
66         instance( producer.get_producer( ) ),
67         parent_( NULL )
68 {
69         inc_ref( );
70 }
71
72 Producer::Producer( Producer *producer ) :
73         instance( producer != NULL ? producer->get_producer( ) : NULL ),
74         parent_( NULL )
75 {
76         if ( is_valid( ) )
77                 inc_ref( );
78 }
79
80 Producer::~Producer( )
81 {
82         delete parent_;
83         mlt_producer_close( instance );
84         instance = NULL;
85 }
86
87 mlt_producer Producer::get_producer( )
88 {
89         return instance;
90 }
91
92 mlt_producer Producer::get_parent( )
93 {
94         return get_producer( ) != NULL && mlt_producer_cut_parent( get_producer( ) ) != NULL ? mlt_producer_cut_parent( get_producer( ) ) : get_producer( );
95 }
96
97 Producer &Producer::parent( )
98 {
99         if ( is_cut( ) && parent_ == NULL )
100                 parent_ = new Producer( get_parent( ) );
101         return parent_ == NULL ? *this : *parent_;
102 }
103
104 mlt_service Producer::get_service( )
105 {
106         return mlt_producer_service( get_producer( ) );
107 }
108         
109 int Producer::seek( int position )
110 {
111         return mlt_producer_seek( get_producer( ), position );
112 }
113
114 int Producer::position( )
115 {
116         return mlt_producer_position( get_producer( ) );
117 }
118
119 int Producer::frame( )
120 {
121         return mlt_producer_frame( get_producer( ) );
122 }
123
124 int Producer::set_speed( double speed )
125 {
126         return mlt_producer_set_speed( get_producer( ), speed );
127 }
128
129 int Producer::pause()
130 {
131         int result = 0;
132
133         if ( get_speed() != 0 )
134         {
135                 Consumer consumer( ( mlt_consumer ) mlt_service_consumer( get_service( ) ) );
136                 Event *event = consumer.setup_wait_for( "consumer-sdl-paused" );
137                 
138                 result = mlt_producer_set_speed( get_producer( ), 0 );
139                 if ( result == 0 && consumer.is_valid() && !consumer.is_stopped() )
140                         consumer.wait_for( event );
141                 delete event;
142         }
143         
144         return result;
145 }
146
147 double Producer::get_speed( )
148 {
149         return mlt_producer_get_speed( get_producer( ) );
150 }
151
152 double Producer::get_fps( )
153 {
154         return mlt_producer_get_fps( get_producer( ) );
155 }
156
157 int Producer::set_in_and_out( int in, int out )
158 {
159         return mlt_producer_set_in_and_out( get_producer( ), in, out );
160 }
161
162 int Producer::get_in( )
163 {
164         return mlt_producer_get_in( get_producer( ) );
165 }
166
167 int Producer::get_out( )
168 {
169         return mlt_producer_get_out( get_producer( ) );
170 }
171
172 int Producer::get_length( )
173 {
174         return mlt_producer_get_length( get_producer( ) );
175 }
176
177 int Producer::get_playtime( )
178 {
179         return mlt_producer_get_playtime( get_producer( ) );
180 }
181
182 Producer *Producer::cut( int in, int out )
183 {
184         mlt_producer producer = mlt_producer_cut( get_producer( ), in, out );
185         Producer *result = new Producer( producer );
186         mlt_producer_close( producer );
187         return result;
188 }
189
190 bool Producer::is_cut( )
191 {
192         return mlt_producer_is_cut( get_producer( ) ) != 0;
193 }
194
195 bool Producer::is_blank( )
196 {
197         return mlt_producer_is_blank( get_producer( ) ) != 0;
198 }
199
200 bool Producer::same_clip( Producer &that )
201 {
202         return mlt_producer_cut_parent( get_producer( ) ) == mlt_producer_cut_parent( that.get_producer( ) );
203 }
204
205 bool Producer::runs_into( Producer &that )
206 {
207         return same_clip( that ) && get_out( ) == ( that.get_in( ) - 1 );
208 }
209
210 void Producer::optimise( )
211 {
212         mlt_producer_optimise( get_producer( ) );
213 }
214
215 int Producer::clear( )
216 {
217         return mlt_producer_clear( get_producer( ) );
218 }