Adding miracle
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Sun, 19 Sep 2004 09:32:27 +0000 (09:32 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Sun, 19 Sep 2004 09:32:27 +0000 (09:32 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt++@429 d19143bc-622f-0410-bfdd-b5b2a6649095

mlt++/HOWTO
mlt++/src/Makefile
mlt++/src/Mlt.h
mlt++/src/MltMiracle.cpp [new file with mode: 0644]
mlt++/src/MltMiracle.h [new file with mode: 0644]
mlt++/swig/mltpp.i
mlt++/swig/ruby/miracle.rb [new file with mode: 0755]
mlt++/test/Makefile
mlt++/test/play.cpp
mlt++/test/server.cpp [new file with mode: 0644]

index b16dbef..cc9d31e 100644 (file)
@@ -13,7 +13,6 @@ Hello World
 
        An example of use is as follows:
 
-       #include <time.h>
        #include <mlt++/Mlt.h>
        using namespace Mlt;
 
@@ -23,7 +22,7 @@ Hello World
                Producer p( "pango:" );
                p.set( "text", "Hello World" );
                Consumer c( "sdl" );
-               Event *e = Consumer.setup_wait_for( "consumer-stopped" );
+               Event *e = c.setup_wait_for( "consumer-stopped" );
                c.connect( p );
                c.start( );
                c.wait_for( e );
@@ -63,7 +62,6 @@ Playlists
        As a simple example of the Playlist in action, we'll convert the example
        above into an application which plays multiple video or audio files.
 
-       #include <time.h>
        #include <mlt++/Mlt.h>
        using namespace Mlt;
 
@@ -79,7 +77,7 @@ Playlists
                }
                Consumer c( "sdl" );
                c.connect( list );
-               Event *e = Consumer.setup_wait_for( "consumer-stopped" );
+               Event *e = c.setup_wait_for( "consumer-stopped" );
                c.start( );
                c.wait_for( e );
                delete e;
@@ -111,7 +109,6 @@ Filters
        logo of some sort. We'll just use some black text on a partially 
        transparent red background.
 
-       #include <time.h>
        #include <mlt++/Mlt.h>
        using namespace Mlt;
 
@@ -132,7 +129,7 @@ Filters
                list.attach( f );
                Consumer c( "sdl" );
                c.connect( list );
-               Event *e = Consumer.setup_wait_for( "consumer-stopped" );
+               Event *e = c.setup_wait_for( "consumer-stopped" );
                c.start( );
                c.wait_for( e );
                delete e;
@@ -197,6 +194,43 @@ Transition
        The tractor returned will now mix the audio from the original video and the audio.
 
 
+Events
+------
+
+       Typically, applications need to be informed when changes occur in an mlt++ object.
+       This facilitates application services such as undo/redo management, or project
+       rendering in a timeline type widget and many other types of operations which an
+       application needs.
+
+       As an example, consider the following:
+
+       class Westley
+       {
+               private:
+                       Consumer consumer;
+                       Tractor &tractor;
+               public:
+                       Westley( MltTractor &tractor ) :
+                               tractor( tractor ),
+                               consumer( "westley" )
+                       {
+                               consumer.connect( tractor );
+                               tractor.listen( tractor, "producer-changed", ( mlt_listener )Westley::listener );
+                       }
+                       
+                       static void listener( Properties *tractor, Westley *object )
+                       {
+                               object->activate( );
+                       }
+
+                       void activate( )
+                       {
+                               consumer.start( );
+                       }
+       };
+
+       
+
 That's All Folks...
 -------------------
 
index 719fdaf..5f3df88 100644 (file)
@@ -1,6 +1,6 @@
 include ../config.mak
 CXXFLAGS = -Wall -fPIC -DPIC -pthread `mlt-config --cflags`
-LDFLAGS = `mlt-config --libs`
+LDFLAGS = `mlt-config --libs` `mlt-config miracle --libs`
 INSTALL = install
 
 TARGET = libmlt++.so
@@ -18,7 +18,8 @@ OBJS = MltConsumer.o \
           MltProperties.o \
           MltService.o \
           MltTractor.o \
-          MltTransition.o 
+          MltTransition.o \
+          MltMiracle.o
 
 SRCS = $(OBJS:.o=.cpp)
 
index 327d740..7cb85af 100644 (file)
@@ -35,5 +35,6 @@
 #include "MltService.h"
 #include "MltTractor.h"
 #include "MltTransition.h"
+#include "MltMiracle.h"
 
 #endif
diff --git a/mlt++/src/MltMiracle.cpp b/mlt++/src/MltMiracle.cpp
new file mode 100644 (file)
index 0000000..ef88449
--- /dev/null
@@ -0,0 +1,103 @@
+/**
+ * MltMiracle.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 "MltMiracle.h"
+#include "MltService.h"
+using namespace Mlt;
+
+#include <time.h>
+
+static valerie_response mlt_miracle_execute( void *arg, char *command )
+{
+       Miracle *miracle = ( Miracle * )arg;
+       if ( miracle != NULL )
+       {
+               return miracle->execute( command );
+       }
+       else
+       {
+               valerie_response response = valerie_response_init( );
+               valerie_response_set_error( response, 500, "Invalid server" );
+               return response;
+       }
+}
+
+static valerie_response mlt_miracle_push( void *arg, char *command, mlt_service service )
+{
+       Miracle *miracle = ( Miracle * )arg;
+       if ( miracle != NULL )
+       {
+               Service input( service );
+               return miracle->push( command, &input );
+       }
+       else
+       {
+               valerie_response response = valerie_response_init( );
+               valerie_response_set_error( response, 500, "Invalid server" );
+               return response;
+       }
+}
+
+Miracle::Miracle( char *name, int port, char *config )
+{
+       server = miracle_server_init( name );
+       miracle_server_set_port( server, port );
+       miracle_server_set_config( server, config );
+}
+
+Miracle::~Miracle( )
+{
+       miracle_server_shutdown( server );
+}
+
+bool Miracle::start( )
+{
+       miracle_server_execute( server );
+       _real = server->parser->real;
+       _execute = server->parser->execute;
+       _push = server->parser->push;
+       server->parser->real = this;
+       server->parser->execute = mlt_miracle_execute;
+       server->parser->push = mlt_miracle_push;
+       return server->shutdown == 0;
+}
+
+bool Miracle::is_running( )
+{
+       return server->shutdown == 0;
+}
+
+valerie_response Miracle::execute( char *command )
+{
+       return _execute( _real, command );
+}
+
+valerie_response Miracle::push( char *command, Service *service )
+{
+       return _push( _real, command, service->get_service( ) );
+}
+
+void Miracle::wait_for_shutdown( )
+{
+       struct timespec tm = { 1, 0 };
+       while ( !server->shutdown )
+               nanosleep( &tm, NULL );
+}
+
diff --git a/mlt++/src/MltMiracle.h b/mlt++/src/MltMiracle.h
new file mode 100644 (file)
index 0000000..6016159
--- /dev/null
@@ -0,0 +1,50 @@
+/**
+ * MltMiracle.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_MIRACLE_H_
+#define _MLTPP_MIRACLE_H_
+
+#include <miracle/miracle_server.h>
+#include "MltService.h"
+
+namespace Mlt
+{
+       class Service;
+
+       class Miracle
+       {
+               private:
+                       miracle_server server;
+                       void *_real;
+                       parser_execute _execute;
+                       parser_push _push;
+               public:
+                       Miracle( char *name, int port = 5250, char *config = NULL );
+                       virtual ~Miracle( );
+                       bool start( );
+                       bool is_running( );
+                       virtual valerie_response execute( char *command );
+                       virtual valerie_response push( char *command, Service *service );
+                       void wait_for_shutdown( );
+       };
+}
+
+#endif
+
index bdb0f39..29499b2 100644 (file)
@@ -66,6 +66,7 @@ namespace Mlt {
 %include <MltField.h>
 %include <MltTractor.h>
 %include <MltFilteredConsumer.h>
+%include <MltMiracle.h>
 
 #if defined(SWIGRUBY)
 
diff --git a/mlt++/swig/ruby/miracle.rb b/mlt++/swig/ruby/miracle.rb
new file mode 100755 (executable)
index 0000000..fec8ec7
--- /dev/null
@@ -0,0 +1,5 @@
+require 'mltpp'
+miracle = Mltpp::Miracle.new( "miracle-ruby" )
+miracle.start
+miracle.wait_for_shutdown
+
index 2b27a93..c70c476 100644 (file)
@@ -1,14 +1,19 @@
 CXXFLAGS=-Wall `mlt-config --cflags` -I ../src
-LDFLAGS=--L../src -lmlt++
+LDFLAGS=-L../src -lmlt++
 CC=c++
 
-all:   play
+all:           play server
 
-play:  play.o
+play:          play.o
 
-play.o:        play.cpp
+play.o:                play.cpp
+
+server:                server.o
+
+server.o:      server.cpp
 
 clean:
        $(RM) play play.o
+       $(RM) server server.o
 
 install:
index 1654e8e..6dfeb38 100644 (file)
@@ -1,13 +1,7 @@
 
-#include <iostream>
-#include <string>
-using namespace std;
-
 #include <Mlt.h>
 using namespace Mlt;
 
-#include <time.h>
-
 int main( int argc, char **argv )
 {
        Factory::init( NULL );
diff --git a/mlt++/test/server.cpp b/mlt++/test/server.cpp
new file mode 100644 (file)
index 0000000..b613302
--- /dev/null
@@ -0,0 +1,11 @@
+#include <MltMiracle.h>
+using namespace Mlt;
+
+int main( int argc, char **argv )
+{
+       Miracle server( "miracle++" );
+       server.start( );
+       server.wait_for_shutdown( );
+       return 0;
+}
+