2 * MltFilteredProducer.cpp - MLT Wrapper
3 * Copyright (C) 2004-2005 Charles Yates
4 * Author: Charles Yates <charles.yates@pandora.be>
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.
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.
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
21 #include "MltFilteredProducer.h"
22 #include "MltProfile.h"
25 FilteredProducer::FilteredProducer( Profile& profile, const char *id, const char *arg ) :
26 Producer( profile, id, arg )
28 // Create a reference to the last service
29 last = new Service( *this );
32 FilteredProducer::~FilteredProducer( )
34 // Delete the reference to the last service
38 int FilteredProducer::attach( Filter &filter )
41 if ( filter.is_valid( ) )
43 Service *consumer = last->consumer( );
44 filter.connect_producer( *last );
45 if ( consumer->is_valid( ) )
46 consumer->connect_producer( filter );
49 last = new Service( filter );
58 int FilteredProducer::detach( Filter &filter )
60 if ( filter.is_valid( ) )
62 Service *it = new Service( *last );
63 while ( it->is_valid( ) && it->get_service( ) != filter.get_service( ) )
65 Service *producer = it->producer( );
69 if ( it->get_service( ) == filter.get_service( ) )
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( ) )
81 last = new Service( *producer );