3a588195041eefe6fb399146cd79ae381e3b251e
[melted] / mlt++ / src / 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 program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program 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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #include "MltProducer.h"
22 #include "MltFilter.h"
23 using namespace Mlt;
24
25 Producer::Producer( ) :
26 instance( NULL ),
27 parent_( NULL )
28 {
29 }
30
31 Producer::Producer( char *id, char *service ) :
32 instance( NULL ),
33 parent_( NULL )
34 {
35 if ( id != NULL && service != NULL )
36 instance = mlt_factory_producer( id, service );
37 else
38 instance = mlt_factory_producer( "fezzik", id != NULL ? id : service );
39 }
40
41 Producer::Producer( Service &producer ) :
42 instance( NULL ),
43 parent_( NULL )
44 {
45 mlt_service_type type = producer.type( );
46 if ( type == producer_type || type == playlist_type ||
47 type == tractor_type || type == multitrack_type )
48 {
49 instance = ( mlt_producer )producer.get_service( );
50 inc_ref( );
51 }
52 }
53
54 Producer::Producer( mlt_producer producer ) :
55 instance( producer ),
56 parent_( NULL )
57 {
58 inc_ref( );
59 }
60
61 Producer::Producer( Producer &producer ) :
62 instance( producer.get_producer( ) ),
63 parent_( NULL )
64 {
65 inc_ref( );
66 }
67
68 Producer::Producer( Producer *producer ) :
69 instance( producer != NULL ? producer->get_producer( ) : NULL ),
70 parent_( NULL )
71 {
72 if ( is_valid( ) )
73 inc_ref( );
74 }
75
76 Producer::~Producer( )
77 {
78 delete parent_;
79 mlt_producer_close( instance );
80 instance = NULL;
81 }
82
83 mlt_producer Producer::get_producer( )
84 {
85 return instance;
86 }
87
88 mlt_producer Producer::get_parent( )
89 {
90 return get_producer( ) != NULL && mlt_producer_cut_parent( get_producer( ) ) != NULL ? mlt_producer_cut_parent( get_producer( ) ) : get_producer( );
91 }
92
93 Producer &Producer::parent( )
94 {
95 if ( is_cut( ) && parent_ == NULL )
96 parent_ = new Producer( get_parent( ) );
97 return parent_ == NULL ? *this : *parent_;
98 }
99
100 mlt_service Producer::get_service( )
101 {
102 return mlt_producer_service( get_producer( ) );
103 }
104
105 int Producer::seek( int position )
106 {
107 return mlt_producer_seek( get_producer( ), position );
108 }
109
110 int Producer::position( )
111 {
112 return mlt_producer_position( get_producer( ) );
113 }
114
115 int Producer::frame( )
116 {
117 return mlt_producer_frame( get_producer( ) );
118 }
119
120 int Producer::set_speed( double speed )
121 {
122 return mlt_producer_set_speed( get_producer( ), speed );
123 }
124
125 double Producer::get_speed( )
126 {
127 return mlt_producer_get_speed( get_producer( ) );
128 }
129
130 double Producer::get_fps( )
131 {
132 return mlt_producer_get_fps( get_producer( ) );
133 }
134
135 int Producer::set_in_and_out( int in, int out )
136 {
137 return mlt_producer_set_in_and_out( get_producer( ), in, out );
138 }
139
140 int Producer::get_in( )
141 {
142 return mlt_producer_get_in( get_producer( ) );
143 }
144
145 int Producer::get_out( )
146 {
147 return mlt_producer_get_out( get_producer( ) );
148 }
149
150 int Producer::get_length( )
151 {
152 return mlt_producer_get_length( get_producer( ) );
153 }
154
155 int Producer::get_playtime( )
156 {
157 return mlt_producer_get_playtime( get_producer( ) );
158 }
159
160 Producer *Producer::cut( int in, int out )
161 {
162 mlt_producer producer = mlt_producer_cut( get_producer( ), in, out );
163 Producer *result = new Producer( producer );
164 mlt_producer_close( producer );
165 return result;
166 }
167
168 bool Producer::is_cut( )
169 {
170 return mlt_producer_is_cut( get_producer( ) );
171 }
172
173 bool Producer::is_blank( )
174 {
175 return mlt_producer_is_blank( get_producer( ) );
176 }
177
178 bool Producer::same_clip( Producer &that )
179 {
180 return mlt_producer_cut_parent( get_producer( ) ) == mlt_producer_cut_parent( that.get_producer( ) );
181 }
182
183 bool Producer::runs_into( Producer &that )
184 {
185 return same_clip( that ) && get_out( ) == ( that.get_in( ) - 1 );
186 }
187
188 void Producer::optimise( )
189 {
190 mlt_producer_optimise( get_producer( ) );
191 }