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