]> git.sesse.net Git - mlt/blob - src/mlt++/MltFilteredProducer.cpp
Fix doc error for mlt_playlist_is_blank().
[mlt] / src / mlt++ / MltFilteredProducer.cpp
1 /**
2  * MltFilteredProducer.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 "MltFilteredProducer.h"
22 #include "MltProfile.h"
23 using namespace Mlt;
24
25 FilteredProducer::FilteredProducer( Profile& profile, const char *id, const char *arg ) :
26         Producer( profile, id, arg )
27 {
28         // Create a reference to the last service
29         last = new Service( *this );
30 }
31
32 FilteredProducer::~FilteredProducer( )
33 {
34         // Delete the reference to the last service
35         delete last;
36 }
37
38 int FilteredProducer::attach( Filter &filter )
39 {
40         int error = 0;
41         if ( filter.is_valid( ) )
42         {
43                 Service *consumer = last->consumer( );
44                 filter.connect_producer( *last );
45                 if ( consumer->is_valid( ) )
46                         consumer->connect_producer( filter );
47                 delete consumer;
48                 delete last;
49                 last = new Service( filter );
50         }
51         else
52         {
53                 error = 1;
54         }
55         return error;
56 }
57
58 int FilteredProducer::detach( Filter &filter )
59 {
60         if ( filter.is_valid( ) )
61         {
62                 Service *it = new Service( *last );
63                 while ( it->is_valid( ) && it->get_service( ) != filter.get_service( ) )
64                 {
65                         Service *producer = it->producer( );
66                         delete it;
67                         it = producer;
68                 }
69                 if ( it->get_service( ) == filter.get_service( ) )
70                 {
71                         Service *producer = it->producer( );
72                         Service *consumer = it->consumer( );
73                         if ( consumer->is_valid( ) )
74                                 consumer->connect_producer( *producer );
75                         Profile p( get_profile() );
76                         Producer dummy( p, "colour" );
77                         dummy.connect_producer( *it );
78                         if ( last->get_service( ) == it->get_service( ) )
79                         {
80                                 delete last;
81                                 last = new Service( *producer );
82                         }
83                 }
84                 delete it;
85         }
86         return 0;
87 }
88