More event stuff
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Fri, 3 Sep 2004 11:16:35 +0000 (11:16 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Fri, 3 Sep 2004 11:16:35 +0000 (11:16 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt++@408 d19143bc-622f-0410-bfdd-b5b2a6649095

mlt++/HOWTO
mlt++/src/MltProperties.cpp
mlt++/src/MltProperties.h
mlt++/swig/mltpp.i
mlt++/swig/perl/play.pl

index 830ab29..b16dbef 100644 (file)
@@ -23,11 +23,11 @@ Hello World
                Producer p( "pango:" );
                p.set( "text", "Hello World" );
                Consumer c( "sdl" );
+               Event *e = Consumer.setup_wait_for( "consumer-stopped" );
                c.connect( p );
                c.start( );
-               struct timespec tm = { 1, 0 };
-               while ( !c.is_stopped( ) )
-                       nanosleep( &tm, NULL );
+               c.wait_for( e );
+               delete e;
                return 0;
        }
 
@@ -49,8 +49,6 @@ Hello World
        typically, applications don't wait around for the consumer to be stopped in
        the manner shown.
 
-       TODO: Replace wait loop with an event.
-
        So far, we've introduced the Producer and Consumer mlt classes. We'll cover
        each of these in more detail later in the tutorial, but for now, we'll 
        briefly cover the remaining classes.
@@ -81,10 +79,10 @@ Playlists
                }
                Consumer c( "sdl" );
                c.connect( list );
+               Event *e = Consumer.setup_wait_for( "consumer-stopped" );
                c.start( );
-               struct timespec tm = { 1, 0 };
-               while ( !c.is_stopped( ) )
-                       nanosleep( &tm, NULL );
+               c.wait_for( e );
+               delete e;
                return 0;
        }
 
@@ -134,10 +132,10 @@ Filters
                list.attach( f );
                Consumer c( "sdl" );
                c.connect( list );
+               Event *e = Consumer.setup_wait_for( "consumer-stopped" );
                c.start( );
-               struct timespec tm = { 1, 0 };
-               while ( !c.is_stopped( ) )
-                       nanosleep( &tm, NULL );
+               c.wait_for( e );
+               delete e;
                return 0;
        }
 
@@ -284,4 +282,6 @@ Services
                return producer.is_valid( );
        }
 
-       
+
+Events
+------
index f6e39da..13b8198 100644 (file)
@@ -209,9 +209,6 @@ 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 04343ff..6dae382 100644 (file)
@@ -69,7 +69,7 @@ namespace Mlt
                        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 );
+                       void wait_for( Event *, bool destroy = true );
        };
 }
 
index 40d58c0..d388aa6 100644 (file)
@@ -66,3 +66,59 @@ namespace Mlt {
 %include <MltTractor.h>
 %include <MltFilteredConsumer.h>
 
+#if defined(SWIGRUBY)
+
+%{
+
+static void ruby_listener( mlt_properties owner, void *object );
+
+class RubyListener
+{
+       public:
+               RubyListener( Mlt::Properties &properties, char *id, VALUE callback ) : 
+                       callback( callback ) 
+               {
+                       properties.listen( id, this, ( mlt_listener )ruby_listener );
+               }
+
+       void mark( ) 
+               { 
+                       ((void (*)(VALUE))(rb_gc_mark))( callback ); 
+               }
+
+       void doit( ) 
+               {
+               ID method = rb_intern( "call" );
+               rb_funcall( callback, method, 0 );
+       }
+
+       private:
+               VALUE callback;
+};
+
+static void ruby_listener( mlt_properties owner, void *object )
+{
+       RubyListener *o = static_cast< RubyListener * >( object );
+       o->doit( );
+}
+
+void markRubyListener( void* p ) 
+{
+    RubyListener *o = static_cast<RubyListener*>( p );
+    o->mark( );
+}
+
+%}
+
+// Ruby wrapper
+%rename( Listener )  RubyListener;
+%markfunc RubyListener "markRubyListener";
+
+class RubyListener 
+{
+       public:
+               RubyListener( Mlt::Properties &properties, char *id, VALUE callback );
+};
+
+#endif
+
index b7c2469..aae79e3 100755 (executable)
@@ -16,7 +16,6 @@ if ( $p->is_valid( ) )
 
        # Create the consumer
        $c = new mltpp::FilteredConsumer( "sdl" );
-       $c->attach( new mltpp::Filter( "greyscale" ) );
 
        # Turn of the default rescaling
        $c->set( "rescale", "none" );
@@ -24,15 +23,15 @@ if ( $p->is_valid( ) )
        # Connect the producer to the consumer
        $c->connect( $p );
        
+       $e = $c->setup_wait_for( "consumer-stopped" );
+
        # Start the consumer
        $c->start;
 
        # Wait until the user stops the consumer
-       while ( !$c->is_stopped ) {
-               sleep( 1 );
-       }
+       $c->wait_for( $e );
 
-       $c->stop( );
+       $e = undef;
        $c = undef;
        $p = undef;
 }