]> git.sesse.net Git - mlt/commitdiff
cleanup and reduce code in jackrack support code and add new jack-less filter_ladspa.
authorddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Fri, 22 Apr 2005 04:56:09 +0000 (04:56 +0000)
committerddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Fri, 22 Apr 2005 04:56:09 +0000 (04:56 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@716 d19143bc-622f-0410-bfdd-b5b2a6649095

20 files changed:
docs/services.txt
src/modules/configure
src/modules/jackrack/Makefile
src/modules/jackrack/configure
src/modules/jackrack/control_message.h [deleted file]
src/modules/jackrack/factory.c
src/modules/jackrack/filter_jackrack.c
src/modules/jackrack/filter_ladspa.c [new file with mode: 0644]
src/modules/jackrack/filter_ladspa.h [new file with mode: 0644]
src/modules/jackrack/jack_rack.c
src/modules/jackrack/jack_rack.h
src/modules/jackrack/plugin.c
src/modules/jackrack/plugin.h
src/modules/jackrack/plugin_desc.c
src/modules/jackrack/plugin_mgr.c
src/modules/jackrack/plugin_mgr.h
src/modules/jackrack/process.c
src/modules/jackrack/process.h
src/modules/jackrack/ui.c [deleted file]
src/modules/jackrack/ui.h [deleted file]

index 86a9ab6366be2e2caa36943eb99dc0e73374fa9a..acc6fab05df6027bf214bf3512443fa1f5256509 100644 (file)
@@ -1,9 +1,9 @@
 Service Documentation
 
-Copyright (C) 2004 Ushodaya Enterprises Limited
+Copyright (C) 2004-2005 Ushodaya Enterprises Limited
 Authors: Charles Yates <charles.yates@pandora.be>
          Dan Dennedy <dan@dennedy.org>
-Last Revision: 2004-11-07
+Last Revision: 2005-04-22
 
 
 SERVICES
@@ -377,6 +377,8 @@ Producers
 
                int in - in point
                int out - out point
+               int begin  - when using an image sequence, this sets the starting
+                            number.
 
            Mutable Properties
 
@@ -732,6 +734,48 @@ Filters
            
                Jack, LADSPA, glib-2.0, libxml2
                
+           Known Bugs
+           
+                       Currently, due to timing and synchronisation issues, the audio
+                       is distorted with repeated samples and latency clicks.
+               no encapsulated resampling and jack runs at a fixed frequency
+           
+       ladspa
+       
+           Description
+           
+               Runs a JackRack project to process audio through a stack of
+                       LADSPA filters without using Jack.
+               
+           Constructor Argument
+           
+               src - a JackRack file
+                       
+               Details
+
+                       Due to audio integrity issues with the jackrack filter, this
+                       filter is better for runtime, while jackrack is more suitable
+                       for prototyping a rack file using the Jack Rack GUI.
+               
+           Initialisation Properties
+           
+               int in - in point
+               int out - out point
+                       
+           Read Only Properties
+           
+               none
+               
+           Mutable Properties
+
+                       none
+               
+           Dependencies
+           
+               Jack, LADSPA, glib-2.0, libxml2
+                       Jack is still required because this coexists with the jackrack 
+                       filter.
+               
            Known Bugs
            
                no encapsulated resampling and jack runs at a fixed frequency
index 83b27c8fc16e74f6f03ff3d18894ae077629e1c0..ee654132529f53502ba844d8a080b86a6b6a8d54 100755 (executable)
@@ -4,7 +4,7 @@
 [ "$help" != "1" ] && rm -f disable-* producers.dat filters.dat transitions.dat consumers.dat
 
 # Create the make.inc file
-echo SUBDIRS = `find . -type d -maxdepth 1 | grep -v CVS | grep -v "^.$" | sed 's/\.\///'` > make.inc
+echo SUBDIRS = `find . -maxdepth 1 -type d | grep -v CVS | grep -v "^.$" | sed 's/\.\///'` > make.inc
 
 # Iterate through arguments
 for i in "$@"
index 160eb64cde433bfbc40bbd6b92a8b0ee8a160745..70efa83c26ea40c1becd8319f00fb6bdcf9b9c06 100644 (file)
@@ -10,8 +10,8 @@ OBJS = factory.o \
           plugin_mgr.o \
           plugin_settings.o \
           process.o \
-          ui.o \
-          filter_jackrack.o 
+          filter_jackrack.o \
+          filter_ladspa.o
 
 CFLAGS += -I../.. `pkg-config --cflags jack`
 CFLAGS += `xml2-config --cflags`
index 4a6132d8bf97233bf1d6ce2c5a8ded00b009ad65..870d351a00602d23e1727b1c27de5476d05832ff 100755 (executable)
@@ -12,6 +12,7 @@ then
        if [ "$disable_jack" == "0" -a "$disable_xml2" == "0" ]
        then
                echo "jackrack          libmltjackrack$LIBSUF" >> ../filters.dat
+               echo "ladspa            libmltjackrack$LIBSUF" >> ../filters.dat
        else
                [ "$disable_jack" == "1" ] && echo "- jackrack not found: disabling"
                [ "$disable_xml2" == "1" ] && echo "- xml2 not found: disabling jackrack"
diff --git a/src/modules/jackrack/control_message.h b/src/modules/jackrack/control_message.h
deleted file mode 100644 (file)
index 80071f6..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- *   JACK Rack
- *    
- *   Copyright (C) Robert Ham 2002, 2003 (node@users.sourceforge.net)
- *    
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __JR_CONTROL_MESSAGE_H__
-#define __JR_CONTROL_MESSAGE_H__
-
-#include <glib.h>
-#include <ladspa.h>
-
-/** These are for messages between the gui and the process() callback */
-typedef enum _ctrlmsg_type
-{
-  CTRLMSG_ADD,
-  CTRLMSG_REMOVE,
-  CTRLMSG_QUIT,
-
-} ctrlmsg_type_t;
-
-typedef struct _ctrlmsg ctrlmsg_t;
-
-struct _plugin;
-struct _plugin_desc;
-
-struct _ctrlmsg
-{
-  ctrlmsg_type_t type;
-  union
-  {
-    struct
-    {
-      struct _plugin      * plugin;
-    } add;
-    
-    struct
-    {
-      struct _plugin      * plugin;
-    } remove;
-    
-  } data;
-};
-
-#endif /* __JR_CONTROL_MESSAGE_H__ */
index c5c9a964d06514d4a8eebb21ea5516fbbe570f3d..a5fb16e952c1bd321855182fef146bf23dae30c1 100644 (file)
@@ -21,6 +21,7 @@
 #include <string.h>
 
 #include "filter_jackrack.h"
+#include "filter_ladspa.h"
 
 void *mlt_create_producer( char *id, void *arg )
 {
@@ -31,6 +32,8 @@ void *mlt_create_filter( char *id, void *arg )
 {
        if ( !strcmp( id, "jackrack" ) )
                return filter_jackrack_init( arg );
+       else if ( !strcmp( id, "ladspa" ) )
+               return filter_ladspa_init( arg );
        return NULL;
 }
 
index 101bab0c3da6d3285dad8dcd517a458730ff7749..0715ec153b64eaebbc47ce19b17b96f9a09409b4 100644 (file)
 #include <pthread.h>
 #include <string.h>
 
-#include "ui.h"
+#include "jack_rack.h"
 
 #define BUFFER_LEN 204800 * 3
 
-static void *jackrack_thread( void *arg )
-{
-       mlt_properties properties = arg;
-       ui_t *jackrack = mlt_properties_get_data( properties, "jackrack", NULL );
-               
-       while ( mlt_properties_get_int( properties, "_done" ) == 0 )
-               if ( ui_loop_iterate( jackrack ) )
-                       break;
-               
-       ui_quit( jackrack );
-       ui_destroy( jackrack );
-       
-       return NULL;
-}
-
 static void initialise_jack_ports( mlt_properties properties )
 {
        int i;
@@ -65,18 +50,12 @@ static void initialise_jack_ports( mlt_properties properties )
        // Start JackRack
        if ( mlt_properties_get( properties, "src" ) )
        {
-               pthread_t *jackrack_pthread = mlt_pool_alloc( sizeof( pthread_t ) );
-
                snprintf( rack_name, sizeof( rack_name ), "jackrack%d", getpid() );
-               ui_t *jackrack = ui_new( rack_name, mlt_properties_get_int( properties, "channels" ), 0, 0 );
+               jack_rack_t *jackrack = jack_rack_new( rack_name, mlt_properties_get_int( properties, "channels" ) );
                jack_rack_open_file( jackrack, mlt_properties_get( properties, "src" ) );               
                
                mlt_properties_set_data( properties, "jackrack", jackrack, 0, NULL, NULL );
                mlt_properties_set( properties, "_rack_client_name", rack_name );
-               mlt_properties_set_int( properties, "_done", 0 );
-               mlt_properties_set_data( properties, "jackrack_pthread", jackrack_pthread, 0, NULL, NULL );
-               
-               pthread_create( jackrack_pthread, NULL, jackrack_thread, properties );
        }
                
        // Allocate buffers and ports
@@ -253,14 +232,14 @@ static int jackrack_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
        // Get the filter-specific properties
        jack_ringbuffer_t **output_buffers = mlt_properties_get_data( filter_properties, "output_buffers", NULL );
        jack_ringbuffer_t **input_buffers = mlt_properties_get_data( filter_properties, "input_buffers", NULL );
-       pthread_mutex_t *output_lock = mlt_properties_get_data( filter_properties, "output_lock", NULL );
-       pthread_cond_t *output_ready = mlt_properties_get_data( filter_properties, "output_ready", NULL );
+//     pthread_mutex_t *output_lock = mlt_properties_get_data( filter_properties, "output_lock", NULL );
+//     pthread_cond_t *output_ready = mlt_properties_get_data( filter_properties, "output_ready", NULL );
        
        // Process the audio
        int16_t *q = *buffer;
        float sample[ 2 ][ 10000 ];
        int i, j;
-       struct timespec tm = { 0, 0 };
+//     struct timespec tm = { 0, 0 };
 
        // Convert to floats and write into output ringbuffer
        if ( jack_ringbuffer_write_space( output_buffers[0] ) >= ( *samples * sizeof(float) ) )
@@ -323,7 +302,7 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
 }
 
 
-void filter_close( mlt_filter this )
+static void filter_close( mlt_filter this )
 {
        int i;
        char mlt_name[20];
@@ -347,14 +326,9 @@ void filter_close( mlt_filter this )
        mlt_pool_release( mlt_properties_get_data( properties, "jack_input_buffers", NULL ) );
        mlt_pool_release( mlt_properties_get_data( properties, "output_lock", NULL ) );
        mlt_pool_release( mlt_properties_get_data( properties, "output_ready", NULL ) );
-       
-       pthread_t *jackrack_pthread = mlt_properties_get_data( properties, "jackrack_thread", NULL );
-       if ( jackrack_pthread != NULL )
-       {
-               mlt_properties_set_int( properties, "_done", 1 );
-               pthread_join( *jackrack_pthread, NULL );
-               mlt_pool_release( jackrack_pthread );
-       }
+
+       jack_rack_t *jackrack = mlt_properties_get_data( properties, "jackrack", NULL );
+       jack_rack_destroy( jackrack );
        
        this->parent.close = NULL;
        mlt_service_close( &this->parent );
diff --git a/src/modules/jackrack/filter_ladspa.c b/src/modules/jackrack/filter_ladspa.c
new file mode 100644 (file)
index 0000000..bb71307
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+ * filter_ladspa.c -- filter audio through LADSPA plugins
+ * Copyright (C) 2004-2005 Ushodaya Enterprises Limited
+ * Author: Dan Dennedy <dan@dennedy.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 "filter_ladspa.h"
+
+#include <framework/mlt_frame.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <pthread.h>
+#include <string.h>
+
+#include "jack_rack.h"
+
+#define BUFFER_LEN 10000
+
+static void initialise_jack_rack( mlt_properties properties, int channels )
+{
+       int i;
+       char mlt_name[20];
+       
+       // Propogate these for the Jack processing callback
+       mlt_properties_set_int( properties, "channels", channels );
+
+       // Start JackRack
+       if ( mlt_properties_get( properties, "src" ) )
+       {
+               // Create JackRack without Jack client name so that it only uses LADSPA
+               jack_rack_t *jackrack = jack_rack_new( NULL, channels );
+               mlt_properties_set_data( properties, "jackrack", jackrack, 0, NULL, NULL );
+               jack_rack_open_file( jackrack, mlt_properties_get( properties, "src" ) );
+       }
+               
+       // Allocate buffers
+       LADSPA_Data **input_buffers = mlt_pool_alloc( sizeof( LADSPA_Data ) * channels );
+       LADSPA_Data **output_buffers = mlt_pool_alloc( sizeof( LADSPA_Data ) * channels );
+
+       // Set properties - released inside filter_close
+       mlt_properties_set_data( properties, "input_buffers", input_buffers, sizeof( LADSPA_Data *) * channels, NULL, NULL );
+       mlt_properties_set_data( properties, "output_buffers", output_buffers, sizeof( LADSPA_Data *) * channels, NULL, NULL );
+
+       // Register Jack ports
+       for ( i = 0; i < channels; i++ )
+       {
+               input_buffers[i] = mlt_pool_alloc( BUFFER_LEN * sizeof( LADSPA_Data ) );
+               snprintf( mlt_name, sizeof( mlt_name ), "ibuf%d", i );
+               mlt_properties_set_data( properties, mlt_name, input_buffers[i], BUFFER_LEN * sizeof( LADSPA_Data ), NULL, NULL );
+
+               output_buffers[i] = mlt_pool_alloc( BUFFER_LEN * sizeof( LADSPA_Data ) );
+               snprintf( mlt_name, sizeof( mlt_name ), "obuf%d", i );
+               mlt_properties_set_data( properties, mlt_name, output_buffers[i], BUFFER_LEN * sizeof( LADSPA_Data ), NULL, NULL );
+       }
+}
+
+
+/** Get the audio.
+*/
+
+static int ladspa_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
+{
+       // Get the filter service
+       mlt_filter filter = mlt_frame_pop_audio( frame );
+
+       // Get the filter properties
+       mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter );
+
+       // Get the producer's audio
+       mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
+       
+       // Initialise LADSPA if needed
+       jack_rack_t *jackrack = mlt_properties_get_data( filter_properties, "jackrack", NULL );
+       if ( jackrack == NULL )
+       {
+               sample_rate = *frequency;
+               initialise_jack_rack( filter_properties, *channels );
+               jackrack = mlt_properties_get_data( filter_properties, "jackrack", NULL );
+       }
+               
+       // Get the filter-specific properties
+       LADSPA_Data **input_buffers = mlt_properties_get_data( filter_properties, "input_buffers", NULL );
+       LADSPA_Data **output_buffers = mlt_properties_get_data( filter_properties, "output_buffers", NULL );
+       
+       // Process the audio
+       int16_t *q = *buffer;
+       int i, j;
+
+       // Convert to floats and write into output ringbuffer
+       for ( i = 0; i < *samples; i++ )
+               for ( j = 0; j < *channels; j++ )
+                       input_buffers[ j ][ i ] = ( float )( *q ++ ) / 32768.0;
+
+       // Do LADSPA processing
+       if ( jackrack && process_ladspa( jackrack->procinfo, *samples, input_buffers, output_buffers) == 0 )
+       {
+               // Read from output buffer and convert from floats
+               q = *buffer;
+               for ( i = 0; i < *samples; i++ )
+                       for ( j = 0; j < *channels; j++ )
+                       {
+                               if ( output_buffers[ j ][ i ] > 1.0 )
+                                       output_buffers[ j ][ i ] = 1.0;
+                               else if ( output_buffers[ j ][ i ] < -1.0 )
+                                       output_buffers[ j ][ i ] = -1.0;
+                       
+                               if ( output_buffers[ j ][ i ] > 0 )
+                                       *q ++ = 32767 * output_buffers[ j ][ i ];
+                               else
+                                       *q ++ = 32768 * output_buffers[ j ][ i ];
+                       }
+       }
+
+       return 0;
+}
+
+
+/** Filter processing.
+*/
+
+static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
+{
+       {
+               mlt_frame_push_audio( frame, this );
+               mlt_frame_push_audio( frame, ladspa_get_audio );
+       }
+
+       return frame;
+}
+
+
+static void filter_close( mlt_filter this )
+{
+       int i;
+       char mlt_name[20];
+       mlt_properties properties = MLT_FILTER_PROPERTIES( this );
+       
+       for ( i = 0; i < mlt_properties_get_int( properties, "channels" ); i++ )
+       {
+               snprintf( mlt_name, sizeof( mlt_name ), "obuf%d", i );
+               mlt_pool_release( mlt_properties_get_data( properties, mlt_name, NULL ) );
+               snprintf( mlt_name, sizeof( mlt_name ), "ibuf%d", i );
+               mlt_pool_release( mlt_properties_get_data( properties, mlt_name, NULL ) );
+       }
+       mlt_pool_release( mlt_properties_get_data( properties, "output_buffers", NULL ) );
+       mlt_pool_release( mlt_properties_get_data( properties, "input_buffers", NULL ) );
+
+       jack_rack_t *jackrack = mlt_properties_get_data( properties, "jackrack", NULL );
+       jack_rack_destroy( jackrack );
+       
+       this->parent.close = NULL;
+       mlt_service_close( &this->parent );
+}
+
+/** Constructor for the filter.
+*/
+
+mlt_filter filter_ladspa_init( char *arg )
+{
+       mlt_filter this = mlt_filter_new( );
+       if ( this != NULL )
+       {
+               mlt_properties properties = MLT_FILTER_PROPERTIES( this );
+               
+               this->process = filter_process;
+               this->close = filter_close;
+               
+               mlt_properties_set( properties, "src", arg );
+       }
+       return this;
+}
diff --git a/src/modules/jackrack/filter_ladspa.h b/src/modules/jackrack/filter_ladspa.h
new file mode 100644 (file)
index 0000000..04fc9ed
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * filter_ladspa.h -- filter audio through LADSPA plugins
+ * Copyright (C) 2004-2005 Ushodaya Enterprises Limited
+ * Author: Dan Dennedy <dan@dennedy.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 _FILTER_LADSPA_H_
+#define _FILTER_LADSPA_H_
+
+#include <framework/mlt_filter.h>
+
+extern mlt_filter filter_ladspa_init( char *arg );
+
+#endif
index 577694c6b7b545564ab5c0ebe6469349a5ea7231..f7b8a858260bb4fcc03761b4ba0f4a0c7016bba3 100644 (file)
@@ -29,8 +29,6 @@
 
 #include "jack_rack.h"
 #include "lock_free_fifo.h"
-#include "control_message.h"
-#include "ui.h"
 #include "plugin_settings.h"
 
 #ifndef _
 #endif
 
 jack_rack_t *
-jack_rack_new (ui_t * ui, unsigned long channels)
+jack_rack_new (const char * client_name, unsigned long channels)
 {
   jack_rack_t *rack;
 
   rack = g_malloc (sizeof (jack_rack_t));
   rack->saved_plugins  = NULL;
-  rack->ui             = ui;
   rack->channels       = channels;
+  rack->procinfo = process_info_new (client_name, channels, FALSE, FALSE);
+  if (!rack->procinfo) {
+    g_free (rack);
+    return NULL;
+  }
+  rack->plugin_mgr = plugin_mgr_new ();
+  plugin_mgr_set_plugins (rack->plugin_mgr, channels);
 
   return rack;
 }
@@ -54,6 +58,10 @@ jack_rack_new (ui_t * ui, unsigned long channels)
 void
 jack_rack_destroy (jack_rack_t * jack_rack)
 {
+  process_quit (jack_rack->procinfo);
+  plugin_mgr_destroy (jack_rack->plugin_mgr);
+  process_info_destroy (jack_rack->procinfo);
+  g_slist_free (jack_rack->saved_plugins);
   g_free (jack_rack);
 }
 
@@ -79,29 +87,16 @@ jack_rack_instantiate_plugin (jack_rack_t * jack_rack, plugin_desc_t * desc)
   return plugin;
 }
 
-void
-jack_rack_send_add_plugin (jack_rack_t * jack_rack, plugin_desc_t * desc)
-{
-  plugin_t * plugin;
-  ctrlmsg_t ctrlmsg;
-  
-  plugin = jack_rack_instantiate_plugin (jack_rack, desc);
-  
-  if (!plugin)
-    return;
-  
-  /* send the chain link off to the process() callback */
-  ctrlmsg.type = CTRLMSG_ADD;
-  ctrlmsg.data.add.plugin = plugin;
-  lff_write (jack_rack->ui->ui_to_process, &ctrlmsg);
-}
 
 void
 jack_rack_add_saved_plugin (jack_rack_t * jack_rack, saved_plugin_t * saved_plugin)
 {
+  plugin_t * plugin = jack_rack_instantiate_plugin (jack_rack, saved_plugin->settings->desc);
+  if (!plugin)
+    return;
   jack_rack->saved_plugins = g_slist_append (jack_rack->saved_plugins, saved_plugin);
-  
-  jack_rack_send_add_plugin (jack_rack, saved_plugin->settings->desc);
+  process_add_plugin (jack_rack->procinfo, plugin);
+  jack_rack_add_plugin (jack_rack, plugin);
 }
 
 
@@ -152,8 +147,8 @@ jack_rack_add_plugin (jack_rack_t * jack_rack, plugin_t * plugin)
 
 
 static void
-saved_rack_parse_plugin (saved_rack_t * saved_rack, saved_plugin_t * saved_plugin,
-                         ui_t * ui, const char * filename, xmlNodePtr plugin)
+saved_rack_parse_plugin (jack_rack_t * jack_rack, saved_rack_t * saved_rack, saved_plugin_t * saved_plugin,
+                         const char * filename, xmlNodePtr plugin)
 {
   plugin_desc_t * desc;
   settings_t * settings = NULL;
@@ -171,7 +166,7 @@ saved_rack_parse_plugin (saved_rack_t * saved_rack, saved_plugin_t * saved_plugi
           num = strtoul (content, NULL, 10);
           xmlFree (content);
 
-          desc = plugin_mgr_get_any_desc (ui->plugin_mgr, num);
+          desc = plugin_mgr_get_any_desc (jack_rack->plugin_mgr, num);
           if (!desc)
             {
               fprintf (stderr, _("The file '%s' contains an unknown plugin with ID '%ld'; skipping\n"), filename, num);
@@ -250,7 +245,7 @@ saved_rack_parse_plugin (saved_rack_t * saved_rack, saved_plugin_t * saved_plugi
 }
 
 static void
-saved_rack_parse_jackrack (saved_rack_t * saved_rack, ui_t * ui, const char * filename, xmlNodePtr jackrack)
+saved_rack_parse_jackrack (jack_rack_t * jack_rack, saved_rack_t * saved_rack, const char * filename, xmlNodePtr jackrack)
 {
   xmlNodePtr node;
   xmlChar *content;
@@ -274,13 +269,13 @@ saved_rack_parse_jackrack (saved_rack_t * saved_rack, ui_t * ui, const char * fi
         {
           saved_plugin = g_malloc0 (sizeof (saved_plugin_t));
           saved_rack->plugins = g_slist_append (saved_rack->plugins, saved_plugin);
-          saved_rack_parse_plugin (saved_rack, saved_plugin, ui, filename, node);
+          saved_rack_parse_plugin (jack_rack, saved_rack, saved_plugin, filename, node);
         }
     }
 }
 
 static saved_rack_t *
-saved_rack_new (ui_t * ui, const char * filename, xmlDocPtr doc)
+saved_rack_new (jack_rack_t * jack_rack, const char * filename, xmlDocPtr doc)
 {
   xmlNodePtr node;
   saved_rack_t *saved_rack;
@@ -294,7 +289,7 @@ saved_rack_new (ui_t * ui, const char * filename, xmlDocPtr doc)
   for (node = doc->children; node; node = node->next)
     {
       if (strcmp (node->name, "jackrack") == 0)
-        saved_rack_parse_jackrack (saved_rack, ui, filename, node);
+        saved_rack_parse_jackrack (jack_rack, saved_rack, filename, node);
     }
   
   return saved_rack;
@@ -303,18 +298,17 @@ saved_rack_new (ui_t * ui, const char * filename, xmlDocPtr doc)
 static void
 saved_rack_destroy (saved_rack_t * saved_rack)
 {
-/*  GSList * list;*/
-  
-/*  for (list = saved_rack->settings; list; list = g_slist_next (list))
-    settings_destroy ((settings_t *) list->data); */
-/*  g_slist_free (saved_rack->settings); */
+  GSList * list;
   
+  for (list = saved_rack->plugins; list; list = g_slist_next (list))
+    settings_destroy (((saved_plugin_t *) list->data)->settings);
+  g_slist_free (saved_rack->plugins);
   g_free (saved_rack);
 }
 
 
 int
-jack_rack_open_file (ui_t * ui, const char * filename)
+jack_rack_open_file (jack_rack_t * jack_rack, const char * filename)
 {
   xmlDocPtr doc;
   saved_rack_t * saved_rack;
@@ -334,7 +328,7 @@ jack_rack_open_file (ui_t * ui, const char * filename)
       return 1;
     }
   
-  saved_rack = saved_rack_new (ui, filename, doc);
+  saved_rack = saved_rack_new (jack_rack, filename, doc);
   xmlFreeDoc (doc);
   
   if (!saved_rack)
@@ -346,11 +340,10 @@ jack_rack_open_file (ui_t * ui, const char * filename)
       
       settings_set_sample_rate (saved_plugin->settings, sample_rate);
       
-      jack_rack_add_saved_plugin (ui->jack_rack, saved_plugin);
+      jack_rack_add_saved_plugin (jack_rack, saved_plugin);
     }
   
-  g_slist_free (saved_rack->plugins);  
-  g_free (saved_rack);
+  saved_rack_destroy (saved_rack);
   
   return 0;
 }
index e500e0ef2d7951d6b01e0c5d5e3a2251128bb0aa..06c3439e6686184ab74d8216679453d3aab5c8fd 100644 (file)
@@ -27,7 +27,7 @@
 #include "plugin.h"
 #include "plugin_mgr.h"
 #include "plugin_settings.h"
-#include "ui.h"
+#include "process.h"
 
 typedef struct _saved_plugin saved_plugin_t;
 
@@ -49,18 +49,16 @@ typedef struct _jack_rack jack_rack_t;
 
 struct _jack_rack
 {
-  struct _ui *      ui;
-  
+  plugin_mgr_t *    plugin_mgr;
+  process_info_t *  procinfo;
   unsigned long     channels;
-  
   GSList *          saved_plugins;
 };
 
-jack_rack_t * jack_rack_new     (struct _ui * ui, unsigned long channels);
+jack_rack_t * jack_rack_new     (const char * client_name, unsigned long channels);
 void          jack_rack_destroy (jack_rack_t * jack_rack);
 
-int jack_rack_open_file (struct _ui * ui, const char * filename);
-void jack_rack_send_add_plugin (jack_rack_t * jack_rack, plugin_desc_t * plugin);
+int jack_rack_open_file (jack_rack_t * jack_rack, const char * filename);
 void jack_rack_add_plugin (jack_rack_t * jack_rack, plugin_t * plugin);
 void jack_rack_add_saved_plugin (jack_rack_t * jack_rack, struct _saved_plugin * saved_plugin);
 
index 753910b8fd7968c832921bb05be8f48a3d309e48..c5b80784d6207c9d9c15df426bf28572378c2963 100644 (file)
@@ -29,7 +29,6 @@
 #include "plugin.h"
 #include "jack_rack.h"
 #include "process.h"
-#include "ui.h"
 
 #define CONTROL_FIFO_SIZE   128
 
@@ -138,7 +137,7 @@ process_remove_plugin (process_info_t * procinfo, plugin_t *plugin)
     procinfo->chain_end = plugin->prev;
     
   /* sort out the aux ports */
-  if (plugin->desc->aux_channels > 0)
+  if (procinfo->jack_client && plugin->desc->aux_channels > 0)
     {
       plugin_t * other;
       
@@ -227,7 +226,7 @@ process_move_plugin (process_info_t * procinfo, plugin_t *plugin, gint up)
        procinfo->chain_end = plugin;
     }
   
-  if (plugin->desc->aux_channels > 0)
+  if (procinfo->jack_client && plugin->desc->aux_channels > 0)
     {
       plugin_t * other;
       other = up ? plugin->next : plugin->prev;
@@ -257,7 +256,7 @@ process_change_plugin (process_info_t * procinfo,
     procinfo->chain_end = new_plugin;
 
   /* sort out the aux ports */
-  if (plugin->desc->aux_channels > 0)
+  if (procinfo->jack_client && plugin->desc->aux_channels > 0)
     {
       plugin_t * other;
       
@@ -392,7 +391,7 @@ plugin_create_aux_ports (plugin_t * plugin, guint copy, jack_rack_t * jack_rack)
                aux_channel);
       
       holder->aux_ports[i] =
-        jack_port_register (jack_rack->ui->procinfo->jack_client,
+        jack_port_register (jack_rack->procinfo->jack_client,
                             port_name,
                             JACK_DEFAULT_AUDIO_TYPE,
                             desc->aux_are_input ? JackPortIsInput : JackPortIsOutput,
@@ -455,7 +454,7 @@ plugin_init_holder (plugin_t * plugin,
         plugin->descriptor-> connect_port (instance, i, &unused_control_port_output);
     }
   
-  if (plugin->desc->aux_channels > 0)
+  if (jack_rack->procinfo->jack_client && plugin->desc->aux_channels > 0)
     plugin_create_aux_ports (plugin, copy, jack_rack);
   
   if (plugin->descriptor->activate)
@@ -502,6 +501,7 @@ plugin_new (plugin_desc_t * desc, jack_rack_t * jack_rack)
   plugin->next = NULL;
   plugin->prev = NULL;
   plugin->wet_dry_enabled = FALSE;
+  plugin->jack_rack = jack_rack;
   
   /* create audio memory and wet/dry stuff */
   plugin->audio_output_memory   = g_malloc (sizeof (LADSPA_Data *) * jack_rack->channels);
@@ -525,7 +525,7 @@ plugin_new (plugin_desc_t * desc, jack_rack_t * jack_rack)
 
 
 void
-plugin_destroy (plugin_t * plugin, ui_t *ui)
+plugin_destroy (plugin_t * plugin)
 {
   unsigned long i, j;
   int err;
@@ -550,11 +550,11 @@ plugin_destroy (plugin_t * plugin, ui_t *ui)
         }
       
       /* aux ports */
-      if (plugin->desc->aux_channels > 0)
+      if (plugin->jack_rack->procinfo->jack_client && plugin->desc->aux_channels > 0)
         {
           for (j = 0; j < plugin->desc->aux_channels; j++)
             {
-              err = jack_port_unregister (ui->procinfo->jack_client,
+              err = jack_port_unregister (plugin->jack_rack->procinfo->jack_client,
                                           plugin->holders[i].aux_ports[j]);
           
               if (err)
@@ -567,7 +567,7 @@ plugin_destroy (plugin_t * plugin, ui_t *ui)
     
   g_free (plugin->holders);
   
-  for (i = 0; i < ui->jack_rack->channels; i++)
+  for (i = 0; i < plugin->jack_rack->channels; i++)
     {
       g_free (plugin->audio_output_memory[i]);
       lff_free (plugin->wet_dry_fifos + i);
index ddead6e734fd5f65af1eab1e8ff9000655d7147d..4b37a709bfa97a8ee17c3ff06aca6d33ca781aef 100644 (file)
@@ -60,6 +60,7 @@ struct _plugin
 
   const LADSPA_Descriptor *  descriptor;
   void *                     dl_handle;
+  struct _jack_rack *        jack_rack;
   
 };
 
@@ -74,7 +75,7 @@ struct _jack_rack;
 struct _ui;
 
 plugin_t * plugin_new (plugin_desc_t * plugin_desc, struct _jack_rack * jack_rack);
-void       plugin_destroy (plugin_t * plugin, struct _ui *ui);
+void       plugin_destroy (plugin_t * plugin);
 
 void plugin_connect_input_ports (plugin_t * plugin, LADSPA_Data ** inputs);
 void plugin_connect_output_ports (plugin_t * plugin);
index 1dfea31a4b2def7092c1860728a9d4774d0cb153..d77f09fa6718d597a241b42322d329d901e2d79b 100644 (file)
@@ -163,7 +163,7 @@ plugin_desc_add_audio_port_index (unsigned long ** indicies,
 {
   (*current_port_count)++;
   
-  if (*current_port_count == 1)
+  if (*current_port_count == 0)
     *indicies = g_malloc (sizeof (unsigned long) * *current_port_count);
   else
     *indicies = g_realloc (*indicies, sizeof (unsigned long) * *current_port_count);
@@ -193,7 +193,7 @@ plugin_desc_set_port_counts (plugin_desc_t * pd)
             continue;
             
           pd->control_port_count++;
-          if (pd->control_port_count == 1)
+          if (pd->control_port_count == 0)
             pd->control_port_indicies = g_malloc (sizeof (unsigned long) * pd->control_port_count);
           else
             pd->control_port_indicies = g_realloc (pd->control_port_indicies,
@@ -210,7 +210,7 @@ plugin_desc_set_port_counts (plugin_desc_t * pd)
       unsigned long ** port_indicies;
       unsigned long port_count;
       unsigned long i, j;
-      
+     
       if (icount > ocount)
         {
           pd->channels = ocount;
index b666e354031821f0b47513d0cce780293b77d0f8..c2861cfd7dc96c383ae7a6df2e39740be51c6a59 100644 (file)
@@ -32,7 +32,6 @@
 
 #include "plugin_mgr.h"
 #include "plugin_desc.h"
-#include "ui.h"
 
 
 static gboolean
@@ -60,7 +59,7 @@ plugin_is_valid (const LADSPA_Descriptor * descriptor)
 }
 
 static void
-plugin_mgr_get_object_file_plugins (ui_t * ui, plugin_mgr_t * plugin_mgr, const char * filename)
+plugin_mgr_get_object_file_plugins (plugin_mgr_t * plugin_mgr, const char * filename)
 {
   const char * dlerr;
   void * dl_handle;
@@ -146,7 +145,7 @@ plugin_mgr_get_object_file_plugins (ui_t * ui, plugin_mgr_t * plugin_mgr, const
 }
 
 static void
-plugin_mgr_get_dir_plugins (ui_t * ui, plugin_mgr_t * plugin_mgr, const char * dir)
+plugin_mgr_get_dir_plugins (plugin_mgr_t * plugin_mgr, const char * dir)
 {
   DIR * dir_stream;
   struct dirent * dir_entry;
@@ -181,7 +180,7 @@ plugin_mgr_get_dir_plugins (ui_t * ui, plugin_mgr_t * plugin_mgr, const char * d
           strcpy (file_name + dirlen + 1, dir_entry->d_name);
         }
     
-      plugin_mgr_get_object_file_plugins (ui, plugin_mgr, file_name);
+      plugin_mgr_get_object_file_plugins (plugin_mgr, file_name);
       
       g_free (file_name);
     }
@@ -193,7 +192,7 @@ plugin_mgr_get_dir_plugins (ui_t * ui, plugin_mgr_t * plugin_mgr, const char * d
 }
 
 static void
-plugin_mgr_get_path_plugins (ui_t * ui, plugin_mgr_t * plugin_mgr)
+plugin_mgr_get_path_plugins (plugin_mgr_t * plugin_mgr)
 {
   char * ladspa_path, * dir;
   
@@ -203,7 +202,7 @@ plugin_mgr_get_path_plugins (ui_t * ui, plugin_mgr_t * plugin_mgr)
   
   dir = strtok (ladspa_path, ":");
   do
-    plugin_mgr_get_dir_plugins (ui, plugin_mgr, dir);
+    plugin_mgr_get_dir_plugins (plugin_mgr, dir);
   while ((dir = strtok (NULL, ":")));
 
   g_free (ladspa_path);
@@ -221,7 +220,7 @@ plugin_mgr_sort (gconstpointer a, gconstpointer b)
 }
 
 plugin_mgr_t *
-plugin_mgr_new (ui_t * ui)
+plugin_mgr_new ()
 {
   plugin_mgr_t * pm;
   
@@ -230,7 +229,7 @@ plugin_mgr_new (ui_t * ui)
   pm->plugins = NULL;
   pm->plugin_count = 0;
   
-  plugin_mgr_get_path_plugins (ui, pm);
+  plugin_mgr_get_path_plugins (pm);
   
   if (!pm->all_plugins)
     {
index 9a3f8dcf0783a776475587e2dd31bbfa55bc741d..9d196a741331fc497817152f73f476c2b23487b0 100644 (file)
@@ -37,7 +37,7 @@ struct _plugin_mgr
 
 struct _ui;
 
-plugin_mgr_t * plugin_mgr_new (struct _ui * ui);
+plugin_mgr_t * plugin_mgr_new ();
 void           plugin_mgr_destroy (plugin_mgr_t * plugin_mgr);
 
 void plugin_mgr_set_plugins (plugin_mgr_t * plugin_mgr, unsigned long rack_channels);
index e2006422e670f0aaf51de062acb1ef21a077a5c9..636bfd4cb478c87799f4713121a431bdc3df95f3 100644 (file)
 #include <ctype.h>
 
 #include "process.h"
-#include "control_message.h"
 #include "lock_free_fifo.h"
 #include "plugin.h"
 #include "jack_rack.h"
-#include "ui.h"
 
 #ifndef _
 #define _(x) x
 #define USEC_PER_SEC         1000000
 #define MSEC_PER_SEC         1000
 #define TIME_RUN_SKIP_COUNT  5
+#define MAX_BUFFER_SIZE      4096
 
 jack_nframes_t sample_rate;
 jack_nframes_t buffer_size;
 
-static char * jack_client_name;
-
-int process_control_messages (process_info_t * procinfo) {
-  static int quitting = 0;
-  ctrlmsg_t ctrlmsg;
-  int err = 0;
-  
-  if (quitting) return quitting;
+static void
+jack_shutdown_cb (void * data)
+{
+  process_info_t * procinfo = data;
   
-  while (lff_read (procinfo->ui_to_process, &ctrlmsg) == 0)
-    {
-    switch (ctrlmsg.type)
-      {
-    
-      /* add a link to the end of the plugin chain */
-      case CTRLMSG_ADD:
-        process_add_plugin (procinfo, ctrlmsg.data.add.plugin);
-        err = lff_write (procinfo->process_to_ui, &ctrlmsg);
-        break;
-        
-      /* remove a link (plugin will be sent back) */
-      case CTRLMSG_REMOVE:
-        ctrlmsg.data.remove.plugin =
-          process_remove_plugin (procinfo, ctrlmsg.data.remove.plugin);
-        err = lff_write (procinfo->process_to_ui, &ctrlmsg);
-        break;
-        
-      case CTRLMSG_QUIT:
-        quitting = 1;
-        err = lff_write (procinfo->process_to_ui, &ctrlmsg);
-        return 1;
-      }
-    
-    if (err)
-      {
-        fprintf (stderr, "%s: gui fifo is out of space\n", __FUNCTION__);
-        return err;
-      }
-      
-    }
-    
-  return 0;
+  procinfo->quit = TRUE;
 }
 
 /** process messages for plugins' control ports */
@@ -191,17 +154,30 @@ connect_chain (process_info_t * procinfo, jack_nframes_t frames)
   plugin = first_enabled;
   do
     {
-      if (plugin->desc->aux_channels > 0)
+      if (plugin->desc->aux_channels > 0 && plugin->enabled)
         {
-          if (plugin->enabled)
-            for (copy = 0; copy < plugin->copies; copy++)
-              for (channel = 0; channel < plugin->desc->aux_channels; channel++)
-                plugin->descriptor->
-                  connect_port (plugin->holders[copy].instance,
-                                plugin->desc->audio_aux_port_indicies[channel],
-                                jack_port_get_buffer (plugin->holders[copy].aux_ports[channel], frames));
+          if (procinfo->jack_client)
+            {
+              for (copy = 0; copy < plugin->copies; copy++)
+                for (channel = 0; channel < plugin->desc->aux_channels; channel++)
+                  plugin->descriptor->
+                    connect_port (plugin->holders[copy].instance,
+                                  plugin->desc->audio_aux_port_indicies[channel],
+                                  jack_port_get_buffer (plugin->holders[copy].aux_ports[channel], frames));
+            }
+          else
+            {
+              for (copy = 0; copy < frames; copy++)
+                procinfo->silent_buffer[copy] = 0.0;
+
+              for (copy = 0; copy < plugin->copies; copy++)
+                for (channel = 0; channel < plugin->desc->aux_channels; channel++)
+                  plugin->descriptor->
+                    connect_port (plugin->holders[copy].instance,
+                                  plugin->desc->audio_aux_port_indicies[channel],
+                                  procinfo->silent_buffer);
+            }
         }
-      
     }
   while ( (plugin != last_enabled) && (plugin = plugin->next) );
 
@@ -210,10 +186,7 @@ connect_chain (process_info_t * procinfo, jack_nframes_t frames)
   if (first_enabled != last_enabled)
     {
       plugin_connect_input_ports (last_enabled, last_enabled->prev->audio_output_memory);
-      
-      for (plugin = first_enabled->next;
-           plugin;
-           plugin = plugin->next)
+      for (plugin = first_enabled->next; plugin; plugin = plugin->next)
         {
           if (plugin->enabled)
             {
@@ -230,27 +203,31 @@ connect_chain (process_info_t * procinfo, jack_nframes_t frames)
 void
 process_chain (process_info_t * procinfo, jack_nframes_t frames)
 {
-  LADSPA_Data zero_signal[frames];
   plugin_t * first_enabled;
   plugin_t * last_enabled = NULL;
   plugin_t * plugin;
   unsigned long channel;
   unsigned long i;
-  guint copy;
 
-  /* set the zero signal to zero */
-  for (channel = 0; channel < frames; channel++)
-    zero_signal[channel] = 0.0;
+  if (procinfo->jack_client)
+    {
+      LADSPA_Data zero_signal[frames];
+      guint copy;
+
+      /* set the zero signal to zero */
+      for (channel = 0; channel < frames; channel++)
+        zero_signal[channel] = 0.0;
     
-  /* possibly set aux output channels to zero if they're not enabled */
-  for (plugin = procinfo->chain; plugin; plugin = plugin->next)
-    if (!plugin->enabled &&
-        plugin->desc->aux_channels > 0 &&
-        !plugin->desc->aux_are_input)
-      for (copy = 0; copy < plugin->copies; copy++)
-        for (channel = 0; channel < plugin->desc->aux_channels; channel++)
-          memcpy (jack_port_get_buffer (plugin->holders[copy].aux_ports[channel], frames),
-                  zero_signal, sizeof (LADSPA_Data) * frames);
+      /* possibly set aux output channels to zero if they're not enabled */
+      for (plugin = procinfo->chain; plugin; plugin = plugin->next)
+        if (!plugin->enabled &&
+            plugin->desc->aux_channels > 0 &&
+            !plugin->desc->aux_are_input)
+          for (copy = 0; copy < plugin->copies; copy++)
+            for (channel = 0; channel < plugin->desc->aux_channels; channel++)
+              memcpy (jack_port_get_buffer (plugin->holders[copy].aux_ports[channel], frames),
+                      zero_signal, sizeof (LADSPA_Data) * frames);
+    }
 
   first_enabled = get_first_enabled_plugin (procinfo);
   
@@ -310,8 +287,47 @@ process_chain (process_info_t * procinfo, jack_nframes_t frames)
   
 }
 
-int process (jack_nframes_t frames, void * data) {
-  int err, quitting;
+int process_ladspa (process_info_t * procinfo, jack_nframes_t frames,
+                    LADSPA_Data ** inputs, LADSPA_Data ** outputs) {
+  unsigned long channel;
+  
+  if (!procinfo)
+    {
+      fprintf (stderr, "%s: no process_info from jack!\n", __FUNCTION__);
+      return 1;
+    }
+  
+  if (procinfo->quit == TRUE)
+    return 1;
+  
+  process_control_port_messages (procinfo);
+  
+  for (channel = 0; channel < procinfo->channels; channel++)
+    {
+      procinfo->jack_input_buffers[channel] = inputs[channel];
+      if (!procinfo->jack_input_buffers[channel])
+        {
+          fprintf (stderr, "%s: no jack buffer for input port %ld\n", __FUNCTION__, channel);
+          return 1;
+        }
+
+      procinfo->jack_output_buffers[channel] = outputs[channel];
+      if (!procinfo->jack_output_buffers[channel])
+        {
+          fprintf (stderr, "%s: no jack buffer for output port %ld\n", __FUNCTION__, channel);
+          return 1;
+        }
+    }
+  
+  connect_chain (procinfo, frames);
+  
+  process_chain (procinfo, frames);
+  
+  return 0;
+}
+
+int process_jack (jack_nframes_t frames, void * data) {
+  int err;
   process_info_t * procinfo;
   
   procinfo = (process_info_t *) data;
@@ -325,9 +341,7 @@ int process (jack_nframes_t frames, void * data) {
   if (procinfo->port_count == 0)
     return 0;
   
-  quitting = process_control_messages (procinfo);
-  
-  if (quitting)
+  if (procinfo->quit == TRUE)
     return 1;
   
   process_control_port_messages (procinfo);
@@ -353,11 +367,11 @@ int process (jack_nframes_t frames, void * data) {
  *******************************************/
  
 static int
-process_info_connect_jack (process_info_t * procinfo, ui_t * ui)
+process_info_connect_jack (process_info_t * procinfo)
 {
-  printf (_("Connecting to JACK server with client name '%s'\n"), jack_client_name);
+  printf (_("Connecting to JACK server with client name '%s'\n"), procinfo->jack_client_name);
 
-  procinfo->jack_client = jack_client_new (jack_client_name);
+  procinfo->jack_client = jack_client_new (procinfo->jack_client_name);
 
   if (!procinfo->jack_client)
     {
@@ -367,15 +381,14 @@ process_info_connect_jack (process_info_t * procinfo, ui_t * ui)
 
   printf (_("Connected to JACK server\n"));
 
-  jack_set_process_callback (procinfo->jack_client, process, procinfo);
-  jack_on_shutdown (procinfo->jack_client, jack_shutdown_cb, ui);
+  jack_set_process_callback (procinfo->jack_client, process_jack, procinfo);
+  jack_on_shutdown (procinfo->jack_client, jack_shutdown_cb, procinfo);
                                             
   return 0;
 }
 
 static void
 process_info_connect_port (process_info_t * procinfo,
-                           ui_t * ui,
                            gshort in,
                            unsigned long port_index,
                            const char * port_name)
@@ -398,7 +411,7 @@ process_info_connect_port (process_info_t * procinfo,
       if (jack_port_index != port_index)
         continue;
         
-      full_port_name = g_strdup_printf ("%s:%s", jack_client_name, port_name);
+      full_port_name = g_strdup_printf ("%s:%s", procinfo->jack_client_name, port_name);
 
       printf (_("Connecting ports '%s' and '%s'\n"), full_port_name, jack_ports[jack_port_index]);
 
@@ -419,7 +432,7 @@ process_info_connect_port (process_info_t * procinfo,
 }
 
 int
-process_info_set_port_count (process_info_t * procinfo, ui_t * ui, 
+process_info_set_port_count (process_info_t * procinfo,
        unsigned long port_count, gboolean connect_inputs, gboolean connect_outputs)
 {
   unsigned long i;
@@ -428,7 +441,7 @@ process_info_set_port_count (process_info_t * procinfo, ui_t * ui,
   gshort in;
   
   if (procinfo->port_count >= port_count)
-      return;
+      return -1;
   
   if (procinfo->port_count == 0)
     {
@@ -474,7 +487,7 @@ process_info_set_port_count (process_info_t * procinfo, ui_t * ui,
         //printf (_("Created %s port %s\n"), in ? "input" : "output", port_name);
         
         if ((in && connect_inputs) || (!in && connect_outputs))
-          process_info_connect_port (procinfo, ui, in, i, port_name);
+          process_info_connect_port (procinfo, in, i, port_name);
         
         g_free (port_name);
       }
@@ -486,18 +499,19 @@ process_info_set_port_count (process_info_t * procinfo, ui_t * ui,
 }
 
 void
-process_info_set_channels (process_info_t * procinfo, ui_t * ui, 
+process_info_set_channels (process_info_t * procinfo,
        unsigned long channels, gboolean connect_inputs, gboolean connect_outputs)
 {
-  process_info_set_port_count (procinfo, ui, channels, connect_inputs, connect_outputs);
+  process_info_set_port_count (procinfo, channels, connect_inputs, connect_outputs);
   procinfo->channels = channels; 
 }
 
 process_info_t *
-process_info_new (ui_t * ui, const char * client_name, unsigned long rack_channels, 
+process_info_new (const char * client_name, unsigned long rack_channels, 
        gboolean connect_inputs, gboolean connect_outputs)
 {
   process_info_t * procinfo;
+  char * jack_client_name;
   int err;
 
   procinfo = g_malloc (sizeof (process_info_t));
@@ -509,9 +523,21 @@ process_info_new (ui_t * ui, const char * client_name, unsigned long rack_channe
   procinfo->jack_input_ports = NULL;
   procinfo->jack_output_ports = NULL;
   procinfo->channels = rack_channels;
+  procinfo->quit = FALSE;
        
+  if ( client_name == NULL )
+    {
+      sample_rate = 48000; // should be set externally before calling process_ladspa
+      buffer_size = MAX_BUFFER_SIZE;
+      procinfo->silent_buffer = g_malloc (sizeof (LADSPA_Data) * buffer_size );
+      procinfo->jack_input_buffers = g_malloc (sizeof (LADSPA_Data *) * rack_channels);
+      procinfo->jack_output_buffers = g_malloc (sizeof (LADSPA_Data *) * rack_channels);
+
+      return procinfo;
+    }
+
   /* sort out the client name */
-  jack_client_name = strdup (client_name);
+  procinfo->jack_client_name = jack_client_name = strdup (client_name);
   for (err = 0; jack_client_name[err] != '\0'; err++)
     {
       if (jack_client_name[err] == ' ')
@@ -526,7 +552,7 @@ process_info_new (ui_t * ui, const char * client_name, unsigned long rack_channe
         jack_client_name[err] = tolower (jack_client_name[err]);
     }
   
-  err = process_info_connect_jack (procinfo, ui);
+  err = process_info_connect_jack (procinfo);
   if (err)
     {
 /*      g_free (procinfo); */
@@ -537,15 +563,12 @@ process_info_new (ui_t * ui, const char * client_name, unsigned long rack_channe
   sample_rate = jack_get_sample_rate (procinfo->jack_client);
   buffer_size = jack_get_sample_rate (procinfo->jack_client);
   
-  jack_set_process_callback (procinfo->jack_client, process, procinfo);
-  jack_on_shutdown (procinfo->jack_client, jack_shutdown_cb, ui);
-  
-  procinfo->ui_to_process = ui->ui_to_process; 
-  procinfo->process_to_ui = ui->process_to_ui; 
+  jack_set_process_callback (procinfo->jack_client, process_jack, procinfo);
+  jack_on_shutdown (procinfo->jack_client, jack_shutdown_cb, procinfo);
   
   jack_activate (procinfo->jack_client);
 
-  err = process_info_set_port_count (procinfo, ui, rack_channels, connect_inputs, connect_outputs);
+  err = process_info_set_port_count (procinfo, rack_channels, connect_inputs, connect_outputs);
   if (err)
     return NULL;
 
@@ -554,7 +577,19 @@ process_info_new (ui_t * ui, const char * client_name, unsigned long rack_channe
 
 void
 process_info_destroy (process_info_t * procinfo) {
-  jack_deactivate (procinfo->jack_client);
-  jack_client_close (procinfo->jack_client);
+  if (procinfo->jack_client)
+    {
+      jack_deactivate (procinfo->jack_client);
+      jack_client_close (procinfo->jack_client);
+    }
+  g_free (procinfo->silent_buffer);
+  g_free (procinfo->jack_input_ports);
+  g_free (procinfo->jack_output_ports);
+  g_free (procinfo->jack_input_buffers);
+  g_free (procinfo->jack_output_buffers);
   g_free (procinfo);
 }
+
+void process_quit (process_info_t * procinfo) {
+  procinfo->quit = TRUE;
+}
index 1d218f3cce07195cdf802e298831794ccef35cb9..7fe29b8137c7e49f42f0f5359fcf006f69f5d751 100644 (file)
@@ -45,25 +45,27 @@ struct _process_info {
   unsigned long channels;
   LADSPA_Data ** jack_input_buffers;
   LADSPA_Data ** jack_output_buffers;
+  LADSPA_Data *  silent_buffer;
   
-  lff_t * ui_to_process;
-  lff_t * process_to_ui;
+  char * jack_client_name;
+  int quit;
 };
 
 extern jack_nframes_t sample_rate;
 extern jack_nframes_t buffer_size;
 
-struct _ui;
-
-process_info_t * process_info_new (struct _ui * ui, const char * client_name, 
+process_info_t * process_info_new (const char * client_name,
        unsigned long rack_channels, gboolean connect_inputs, gboolean connect_outputs);
 void process_info_destroy (process_info_t * procinfo);
 
-void process_info_set_channels (process_info_t * procinfo, struct _ui * ui, 
+void process_info_set_channels (process_info_t * procinfo,
        unsigned long channels, gboolean connect_inputs, gboolean connect_outputs);
 
+int process_ladspa (process_info_t * procinfo, jack_nframes_t frames,
+                    LADSPA_Data ** inputs, LADSPA_Data ** outputs);
 
-int process (jack_nframes_t frames, void * data);
+int process_jack (jack_nframes_t frames, void * data);
 
+void process_quit (process_info_t * procinfo);
 
 #endif /* __JLH_PROCESS_H__ */
diff --git a/src/modules/jackrack/ui.c b/src/modules/jackrack/ui.c
deleted file mode 100644 (file)
index d839f08..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- *   JACK Rack
- *    
- *   Copyright (C) Robert Ham 2002, 2003 (node@users.sourceforge.net)
- *    
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <strings.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <unistd.h>
-
-#include <glib.h>
-#include <ladspa.h>
-
-#include "ui.h"
-#include "control_message.h"
-
-
-#define PROCESS_FIFO_SIZE 64
-#define MIDI_FIFO_SIZE 256
-
-ui_t *
-ui_new (const char * client_name, unsigned long channels, 
-       gboolean connect_inputs, gboolean connect_outputs)
-{
-  ui_t * ui;
-
-  ui = g_malloc (sizeof (ui_t));
-  ui->filename = NULL;
-  ui->shutdown = FALSE;
-  ui->state = STATE_NORMAL;
-
-  ui->ui_to_process = lff_new (PROCESS_FIFO_SIZE, sizeof (ctrlmsg_t));
-  ui->process_to_ui = lff_new (PROCESS_FIFO_SIZE, sizeof (ctrlmsg_t));
-
-  ui->procinfo = process_info_new (ui, client_name, channels, connect_inputs, connect_outputs);
-  if (!ui->procinfo)
-    return NULL;
-
-  ui->plugin_mgr = plugin_mgr_new (ui);
-  plugin_mgr_set_plugins (ui->plugin_mgr, channels);
-  ui->jack_rack = jack_rack_new (ui, channels);
-  
-  return ui;
-}
-
-
-void
-ui_quit (ui_t * ui)
-{
-  ctrlmsg_t ctrlmsg;
-
-  ui_set_state (ui, STATE_QUITTING);
-  ctrlmsg.type = CTRLMSG_QUIT;
-  lff_write (ui->ui_to_process, &ctrlmsg);
-}
-
-void
-ui_destroy (ui_t * ui)
-{
-  if (!ui->shutdown)
-    ui_quit (ui);
-  jack_rack_destroy (ui->jack_rack);  
-  
-  g_free (ui);
-}
-
-void
-ui_set_state    (ui_t * ui, ui_state_t state)
-{
-  ui->state = state;
-}
-
-ui_state_t
-ui_get_state (ui_t * ui)
-{
-  return ui->state;
-}
-
-void
-jack_shutdown_cb (void * data)
-{
-  ui_t * ui = data;
-  
-  ui->shutdown = TRUE;
-}
-
-/* do the process->gui message processing */
-gboolean
-ui_loop_iterate (ui_t * ui)
-{
-  ctrlmsg_t ctrlmsg;
-  jack_rack_t * jack_rack = ui->jack_rack;
-
-  while (lff_read (ui->process_to_ui, &ctrlmsg) == 0)
-    {
-    switch (ctrlmsg.type)
-      {
-      case CTRLMSG_ADD:
-        jack_rack_add_plugin (jack_rack, ctrlmsg.data.add.plugin);
-        break;
-
-      case CTRLMSG_REMOVE:
-        plugin_destroy (ctrlmsg.data.remove.plugin, ui);
-        break;
-
-      case CTRLMSG_QUIT:
-        return TRUE;
-        break;
-        
-      }
-    }
-  usleep (100000);
-  
-  return FALSE;
-}
-
-/* EOF */
diff --git a/src/modules/jackrack/ui.h b/src/modules/jackrack/ui.h
deleted file mode 100644 (file)
index db616fd..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- *   JACK Rack
- *    
- *   Copyright (C) Robert Ham 2002, 2003 (node@users.sourceforge.net)
- *    
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __JR_UI_H__
-#define __JR_UI_H__
-
-#include <glib.h>
-
-#include "jack_rack.h"
-#include "plugin_mgr.h"
-#include "process.h"
-#include "lock_free_fifo.h"
-
-typedef struct _ui ui_t;
-
-enum _ui_state
-{
-  /* nothing's happening */
-  STATE_NORMAL,
-  
-  /* the gui is waiting for the process callback to do something */
-  STATE_RACK_CHANGE,
-  
-  /* we're closing down */
-  STATE_QUITTING
-};
-typedef enum _ui_state ui_state_t;
-
-
-struct _jack_rack;
-       
-struct _ui
-{
-  plugin_mgr_t *    plugin_mgr;
-  process_info_t *  procinfo;
-  struct _jack_rack *     jack_rack;
-
-  lff_t *           ui_to_process;
-  lff_t *           process_to_ui;
-  
-  lff_t             *ui_to_midi;
-  lff_t             *midi_to_ui;
-
-  char *            filename;
-  
-  gboolean          shutdown;
-  ui_state_t        state;
-
-};
-
-ui_t * ui_new     (const char * client_name, unsigned long channels, 
-       gboolean connect_inputs, gboolean connect_outputs);
-void   ui_quit    (ui_t * ui);
-void   ui_destroy (ui_t * ui);
-
-void ui_set_state    (ui_t * ui, ui_state_t state);
-ui_state_t ui_get_state (ui_t * ui);
-
-void jack_shutdown_cb (void * data);
-gboolean ui_loop_iterate (ui_t * ui);
-
-#endif /* __JR_UI_H__ */