1 /**
2 * MltTractor.cpp - Tractor wrapper
3 * Copyright (C) 2004-2019 Meltytech, LLC
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "MltTractor.h"
21 #include "MltMultitrack.h"
22 #include "MltField.h"
23 #include "MltTransition.h"
24 #include "MltFilter.h"
25 #include "MltPlaylist.h"
26 #include "MltProfile.h"
27 using namespace Mlt;
28
Tractor()29 Tractor::Tractor( ) :
30 instance( mlt_tractor_new( ) )
31 {
32 }
33
Tractor(Profile & profile)34 Tractor::Tractor( Profile& profile ) :
35 instance( mlt_tractor_new( ) )
36 {
37 set_profile( profile );
38 }
39
Tractor(Service & tractor)40 Tractor::Tractor( Service &tractor ) :
41 instance( NULL )
42 {
43 if ( tractor.type( ) == mlt_service_tractor_type )
44 {
45 instance = ( mlt_tractor )tractor.get_service( );
46 inc_ref( );
47 }
48 }
49
Tractor(mlt_tractor tractor)50 Tractor::Tractor( mlt_tractor tractor ) :
51 instance( tractor )
52 {
53 inc_ref( );
54 }
55
Tractor(Tractor & tractor)56 Tractor::Tractor( Tractor &tractor ) :
57 Mlt::Producer( tractor ),
58 instance( tractor.get_tractor( ) )
59 {
60 inc_ref( );
61 }
62
Tractor(Profile & profile,char * id,char * resource)63 Tractor::Tractor( Profile& profile, char *id, char *resource ) :
64 Tractor( profile.get_profile(), id, resource )
65 {
66 }
67
Tractor(mlt_profile profile,char * id,char * resource)68 Tractor::Tractor( mlt_profile profile, char *id, char *resource ) :
69 instance( NULL )
70 {
71 Producer producer( profile, id, resource );
72 if ( producer.is_valid( ) && producer.type( ) == mlt_service_tractor_type )
73 {
74 instance = ( mlt_tractor )producer.get_producer( );
75 inc_ref( );
76 }
77 else if ( producer.is_valid( ) )
78 {
79 instance = mlt_tractor_new( );
80 set_profile( profile );
81 set_track( producer, 0 );
82 }
83 }
84
~Tractor()85 Tractor::~Tractor( )
86 {
87 mlt_tractor_close( instance );
88 }
89
get_tractor()90 mlt_tractor Tractor::get_tractor( )
91 {
92 return instance;
93 }
94
get_producer()95 mlt_producer Tractor::get_producer( )
96 {
97 return mlt_tractor_producer( get_tractor( ) );
98 }
99
multitrack()100 Multitrack *Tractor::multitrack( )
101 {
102 return new Multitrack( mlt_tractor_multitrack( get_tractor( ) ) );
103 }
104
field()105 Field *Tractor::field( )
106 {
107 return new Field( mlt_tractor_field( get_tractor( ) ) );
108 }
109
refresh()110 void Tractor::refresh( )
111 {
112 return mlt_tractor_refresh( get_tractor( ) );
113 }
114
set_track(Producer & producer,int index)115 int Tractor::set_track( Producer &producer, int index )
116 {
117 return mlt_tractor_set_track( get_tractor( ), producer.get_producer( ), index );
118 }
119
insert_track(Producer & producer,int index)120 int Tractor::insert_track( Producer &producer, int index )
121 {
122 return mlt_tractor_insert_track( get_tractor( ), producer.get_producer( ), index );
123 }
124
remove_track(int index)125 int Tractor::remove_track( int index )
126 {
127 return mlt_tractor_remove_track( get_tractor(), index );
128 }
129
track(int index)130 Producer *Tractor::track( int index )
131 {
132 mlt_producer producer = mlt_tractor_get_track( get_tractor( ), index );
133 return producer != NULL ? new Producer( producer ) : NULL;
134 }
135
count()136 int Tractor::count( )
137 {
138 return mlt_multitrack_count( mlt_tractor_multitrack( get_tractor( ) ) );
139 }
140
plant_transition(Transition & transition,int a_track,int b_track)141 void Tractor::plant_transition( Transition &transition, int a_track, int b_track )
142 {
143 mlt_field_plant_transition( mlt_tractor_field( get_tractor( ) ), transition.get_transition( ), a_track, b_track );
144 }
145
plant_transition(Transition * transition,int a_track,int b_track)146 void Tractor::plant_transition( Transition *transition, int a_track, int b_track )
147 {
148 if ( transition != NULL )
149 mlt_field_plant_transition( mlt_tractor_field( get_tractor( ) ), transition->get_transition( ), a_track, b_track );
150 }
151
plant_filter(Filter & filter,int track)152 void Tractor::plant_filter( Filter &filter, int track )
153 {
154 mlt_field_plant_filter( mlt_tractor_field( get_tractor( ) ), filter.get_filter( ), track );
155 }
156
plant_filter(Filter * filter,int track)157 void Tractor::plant_filter( Filter *filter, int track )
158 {
159 mlt_field_plant_filter( mlt_tractor_field( get_tractor( ) ), filter->get_filter( ), track );
160 }
161
locate_cut(Producer * producer,int & track,int & cut)162 bool Tractor::locate_cut( Producer *producer, int &track, int &cut )
163 {
164 bool found = false;
165
166 for ( track = 0; producer != NULL && !found && track < count( ); track ++ )
167 {
168 Playlist playlist( ( mlt_playlist )mlt_tractor_get_track( get_tractor( ), track ) );
169 for ( cut = 0; !found && cut < playlist.count( ); cut ++ )
170 {
171 Producer *clip = playlist.get_clip( cut );
172 found = producer->get_producer( ) == clip->get_producer( );
173 delete clip;
174 }
175 }
176
177 track --;
178 cut --;
179
180 return found;
181 }
182
connect(Producer & producer)183 int Tractor::connect( Producer &producer )
184 {
185 return mlt_tractor_connect( get_tractor( ), producer.get_service( ) );
186 }
187