]> git.sesse.net Git - mlt/blob - src/framework/mlt_field.c
05a41e5503e64cde9c673e3cea0c8543ed905b56
[mlt] / src / framework / mlt_field.c
1 /*
2  * mlt_field.c -- A field for planting multiple transitions and filters
3  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
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 General Public License as published by
8  * 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 "mlt_field.h"
22 #include "mlt_service.h"
23 #include "mlt_filter.h"
24 #include "mlt_transition.h"
25 #include "mlt_multitrack.h"
26 #include "mlt_tractor.h"
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 /** Private structures.
32 */
33
34 struct mlt_field_s
35 {
36         // This is the producer we're connected to
37         mlt_service producer;
38
39         // Multitrack
40         mlt_multitrack multitrack;
41
42         // Tractor
43         mlt_tractor tractor;
44 };
45
46 /** Constructor.
47         
48         We construct a multitrack and a tractor here.
49 */
50
51 mlt_field mlt_field_init( )
52 {
53         // Initialise the field
54         mlt_field this = calloc( sizeof( struct mlt_field_s ), 1 );
55
56         // Initialise it
57         if ( this != NULL )
58         {
59                 // Construct a multitrack
60                 this->multitrack = mlt_multitrack_init( );
61
62                 // Construct a tractor
63                 this->tractor = mlt_tractor_init( );
64
65                 // The first plant will be connected to the mulitrack
66                 this->producer = mlt_multitrack_service( this->multitrack );
67
68                 // Connect the tractor to the multitrack
69                 mlt_tractor_connect( this->tractor, this->producer );
70         }
71
72         // Return this
73         return this;
74 }
75
76 /** Get the service associated to this field.
77 */
78
79 mlt_service mlt_field_service( mlt_field this )
80 {
81         return this != NULL ? mlt_tractor_service( this->tractor ) : NULL;
82 }
83
84 /** Get the multi track.
85 */
86
87 mlt_multitrack mlt_field_multitrack( mlt_field this )
88 {
89         return this != NULL ? this->multitrack : NULL;
90 }
91
92 /** Get the tractor.
93 */
94
95 mlt_tractor mlt_field_tractor( mlt_field this )
96 {
97         return this != NULL ? this->tractor : NULL;
98 }
99
100 /** Get the properties associated to this field.
101 */
102
103 mlt_properties mlt_field_properties( mlt_field this )
104 {
105         return mlt_service_properties( mlt_field_service( this ) );
106 }
107
108 /** Plant a filter.
109 */
110
111 int mlt_field_plant_filter( mlt_field this, mlt_filter that, int track )
112 {
113         // Connect the filter to the last producer
114         int result = mlt_filter_connect( that, this->producer, track );
115
116         // If sucessful, then we'll use this for connecting in the future
117         if ( result == 0 )
118         {
119                 // This is now the new producer
120                 this->producer = mlt_filter_service( that );
121
122                 // Reconnect tractor to new producer
123                 mlt_tractor_connect( this->tractor, this->producer );
124         }
125
126         return result;
127 }
128
129 /** Plant a transition.
130 */
131
132 int mlt_field_plant_transition( mlt_field this, mlt_transition that, int a_track, int b_track )
133 {
134         // Connect the transition to the last producer
135         int result = mlt_transition_connect( that, this->producer, a_track, b_track );
136
137         // If sucessful, then we'll use this for connecting in the future
138         if ( result == 0 )
139         {
140                 // This is now the new producer
141                 this->producer = mlt_transition_service( that );
142
143                 // Reconnect tractor to new producer
144                 mlt_tractor_connect( this->tractor, this->producer );
145         }
146
147         return 0;
148 }
149
150 /** Close the field.
151 */
152
153 void mlt_field_close( mlt_field this )
154 {
155         if ( this != NULL && mlt_properties_dec_ref( mlt_field_properties( this ) ) <= 0 )
156         {
157                 //mlt_tractor_close( this->tractor );
158                 //mlt_multitrack_close( this->multitrack );
159                 free( this );
160         }
161 }
162