Event modifications
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 2 Sep 2004 16:04:15 +0000 (16:04 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 2 Sep 2004 16:04:15 +0000 (16:04 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt++@405 d19143bc-622f-0410-bfdd-b5b2a6649095

mlt++/src/Makefile
mlt++/src/Mlt.h
mlt++/src/MltEvent.cpp [new file with mode: 0644]
mlt++/src/MltEvent.h [new file with mode: 0644]
mlt++/src/MltProperties.cpp
mlt++/src/MltProperties.h
mlt++/swig/mltpp.i
mlt++/swig/ruby/play.rb
mlt++/test/play.cpp

index 38d26a7..719fdaf 100644 (file)
@@ -6,6 +6,7 @@ INSTALL = install
 TARGET = libmlt++.so
 
 OBJS = MltConsumer.o \
+          MltEvent.o \
           MltFactory.o \
           MltField.o \
           MltFilter.o \
index ad73aa5..327d740 100644 (file)
@@ -22,6 +22,7 @@
 #define _MLTPP_H_
 
 #include "MltConsumer.h"
+#include "MltEvent.h"
 #include "MltFactory.h"
 #include "MltField.h"
 #include "MltFilter.h"
diff --git a/mlt++/src/MltEvent.cpp b/mlt++/src/MltEvent.cpp
new file mode 100644 (file)
index 0000000..d1e6c5e
--- /dev/null
@@ -0,0 +1,61 @@
+/**
+ * MltEvent.cpp - MLT Wrapper
+ * Copyright (C) 2004-2005 Charles Yates
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "MltEvent.h"
+using namespace Mlt;
+
+
+Event::Event( mlt_event event ) :
+       instance( event )
+{
+       mlt_event_inc_ref( instance );
+}
+
+Event::Event( Event &event ) :
+       instance( event.get_event( ) )
+{
+       mlt_event_inc_ref( instance );
+}
+
+Event::~Event( )
+{
+       mlt_event_close( instance );
+}
+
+mlt_event Event::get_event( )
+{
+       return instance;
+}
+
+bool Event::is_valid( )
+{
+       return instance != NULL;
+}
+
+void Event::block( )
+{
+       mlt_event_block( get_event( ) );
+}
+
+void Event::unblock( )
+{
+       mlt_event_unblock( get_event( ) );
+}
+
diff --git a/mlt++/src/MltEvent.h b/mlt++/src/MltEvent.h
new file mode 100644 (file)
index 0000000..66b189f
--- /dev/null
@@ -0,0 +1,44 @@
+/**
+ * MltEvent.h - MLT Wrapper
+ * Copyright (C) 2004-2005 Charles Yates
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _MLTPP_EVENT_H_
+#define _MLTPP_EVENT_H_
+
+#include <framework/mlt.h>
+
+namespace Mlt 
+{
+       class Event 
+       {
+               private:
+                       mlt_event instance;
+               public:
+                       Event( mlt_event );
+                       Event( Event & );
+                       ~Event( );
+                       mlt_event get_event( );
+                       bool is_valid( );
+                       void block( );
+                       void unblock( );
+       };
+}
+
+#endif
+
index 121ca15..f6e39da 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include "MltProperties.h"
+#include "MltEvent.h"
 using namespace Mlt;
 
 Properties::Properties( ) :
@@ -187,3 +188,30 @@ int Properties::save( char *file )
        }
        return error;
 }
+
+void Properties::listen( char *id, void *object, mlt_listener listener )
+{
+       char key[ 128 ];
+       mlt_event event = mlt_events_listen( get_properties( ), object, id, listener );
+       if ( event != NULL )
+       {
+               sprintf( key, "_%p", event );
+               mlt_properties_set_data( get_properties( ), key, event, 0, ( mlt_destructor )mlt_event_close, NULL );
+       }
+}
+
+Event *Properties::setup_wait_for( char *id )
+{
+       return new Event( mlt_events_setup_wait_for( get_properties( ), id ) );
+}
+
+void Properties::wait_for( Event *event, bool destroy )
+{
+       mlt_events_wait_for( get_properties( ), event->get_event( ) );
+       if ( destroy )
+       {
+               mlt_events_close_wait_for( get_properties( ), event->get_event( ) );
+               delete event;
+       }
+}
+
index 82eda22..04343ff 100644 (file)
@@ -26,6 +26,8 @@
 
 namespace Mlt 
 {
+       class Event;
+
        /** Abstract Properties class.
         */
 
@@ -65,6 +67,9 @@ namespace Mlt
                        void dump( FILE *output = stderr );
                        void debug( char *title = "Object", FILE *output = stderr );
                        int save( char *file );
+                       void listen( char *id, void *object, mlt_listener listener );
+                       Event *setup_wait_for( char *id );
+                       void wait_for( Event *, bool destroy = false );
        };
 }
 
index c4369f0..40d58c0 100644 (file)
@@ -52,6 +52,7 @@ namespace Mlt {
 %include <framework/mlt_types.h>
 %include <framework/mlt_factory.h>
 %include <MltFactory.h>
+%include <MltEvent.h>
 %include <MltProperties.h>
 %include <MltFrame.h>
 %include <MltService.h>
index 09f900b..9577e4e 100755 (executable)
@@ -21,6 +21,9 @@ raise "Unable to open sdl consumer" if !consumer.is_valid
 # Turn off the default rescaling
 consumer.set( "rescale", "none" )
 
+# Set up a 'wait for' event
+event = consumer.setup_wait_for( "consumer-stopped" )
+
 # Start the consumer
 consumer.start
 
@@ -28,9 +31,7 @@ consumer.start
 consumer.connect( producer )
 
 # Wait until the user stops the consumer
-while !consumer.is_stopped
-       sleep( 1 )
-end
+consumer.wait_for( event )
 
 # Clean up consumer
 consumer.stop
index 6c1341e..1654e8e 100644 (file)
@@ -11,25 +11,12 @@ using namespace Mlt;
 int main( int argc, char **argv )
 {
        Factory::init( NULL );
-       Producer *producer = new Producer( argv[ 1 ] );
-       if ( !producer->is_valid( ) )
-       {
-               cerr << "Can't construct producer for " << argv[ 1 ] << endl;
-               return 0;
-       }
-       Consumer *consumer = new Consumer( "sdl" );
-       consumer->set( "rescale", "none" );
-       Filter *filter = new Filter( "greyscale" );
-       filter->connect( *producer );
-       consumer->connect( *filter );
-       consumer->start( );
-       struct timespec tm = { 1, 0 };
-       while ( !consumer->is_stopped( ) )
-               nanosleep( &tm, NULL );
-       consumer->stop( );
-       delete consumer;
-       delete producer;
-       delete filter;
-       Factory::close( );
+       Producer producer( argv[ 1 ] );
+       Consumer consumer( "sdl" );
+       consumer.set( "rescale", "none" );
+       consumer.connect( producer );
+       Event *event = consumer.setup_wait_for( "consumer-stopped" );
+       consumer.start( );
+       consumer.wait_for( event, false );
        return 0;
 }