get_frame and ruby listen fix
[melted] / mlt++ / swig / mltpp.i
1 /**
2  * mltpp.i - Swig Bindings for mlt++
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 %module mltpp
22 %include "carrays.i"
23 %array_class(unsigned char, unsignedCharArray);
24
25 %{
26 #include <mlt++/Mlt.h>
27 %}
28
29 /** These methods return objects which should be gc'd.
30  */
31
32 namespace Mlt {
33 %newobject Factory::producer( char *, char * );
34 %newobject Factory::filter( char *, char * );
35 %newobject Factory::transition( char *, char * );
36 %newobject Factory::consumer( char *, char * );
37 %newobject Properties::listen( char *, void *, mlt_listener );
38 %newobject Service::producer( );
39 %newobject Service::consumer( );
40 %newobject Service::get_frame( int );
41 %newobject Service::filter( int );
42 %newobject Producer::filter( int );
43 %newobject Playlist::current( );
44 %newobject Playlist::clip_info( int );
45 %newobject Multitrack::track( int );
46 %newobject Tractor::multitrack( );
47 %newobject Tractor::field( );
48 %newobject Tractor::track( int );
49 %newobject Miracle::execute( char * );
50 %newobject Miracle::push( char *, Service & );
51 }
52
53 /** Classes to wrap.
54  */
55
56 %include <framework/mlt_types.h>
57 %include <framework/mlt_factory.h>
58 %include <MltFactory.h>
59 %include <MltEvent.h>
60 %include <MltProperties.h>
61 %include <MltFrame.h>
62 %include <MltService.h>
63 %include <MltProducer.h>
64 %include <MltPlaylist.h>
65 %include <MltConsumer.h>
66 %include <MltFilter.h>
67 %include <MltTransition.h>
68 %include <MltMultitrack.h>
69 %include <MltField.h>
70 %include <MltTractor.h>
71 %include <MltFilteredConsumer.h>
72 %include <MltMiracle.h>
73 %include <MltResponse.h>
74
75 #if defined(SWIGRUBY)
76
77 %{
78
79 static void ruby_listener( mlt_properties owner, void *object );
80
81 class RubyListener
82 {
83         private:
84                 VALUE callback;
85                 Mlt::Event *event;
86
87         public:
88                 RubyListener( Mlt::Properties &properties, char *id, VALUE callback ) : 
89                         callback( callback ) 
90                 {
91                         event = properties.listen( id, this, ( mlt_listener )ruby_listener );
92                 }
93
94                 ~RubyListener( )
95                 {
96                         delete event;
97                 }
98
99         void mark( ) 
100                 { 
101                         ((void (*)(VALUE))(rb_gc_mark))( callback ); 
102                 }
103
104         void doit( ) 
105                 {
106                 ID method = rb_intern( "call" );
107                 rb_funcall( callback, method, 0 );
108         }
109 };
110
111 static void ruby_listener( mlt_properties owner, void *object )
112 {
113         RubyListener *o = static_cast< RubyListener * >( object );
114         o->doit( );
115 }
116
117 void markRubyListener( void* p ) 
118 {
119     RubyListener *o = static_cast<RubyListener*>( p );
120     o->mark( );
121 }
122
123 %}
124
125 // Ruby wrapper
126 %rename( Listener )  RubyListener;
127 %markfunc RubyListener "markRubyListener";
128
129 class RubyListener 
130 {
131         public:
132                 RubyListener( Mlt::Properties &properties, char *id, VALUE callback );
133 };
134
135 #endif
136