dynamic keyframes, textbox rework, andrea ffmpeg.opts, perpetual chkpt undo, lv2...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / pluginaclientlad.C
index eb1ceb28a50fe1dd1f6b282b59e54afaa5685095..15ff05ed0e6ab8b3d542511c1dd45b3c5a2bfc93 100644 (file)
@@ -2,27 +2,29 @@
 /*
  * CINELERRA
  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- * 
+ *
  */
 
 #include "clip.h"
 #include "bchash.h"
+#include "filesystem.h"
 #include "filexml.h"
 #include "language.h"
+#include "mwindow.h"
 #include "pluginaclientlad.h"
 #include "pluginserver.h"
 #include "samples.h"
@@ -69,28 +71,20 @@ int PluginAClientConfig::equivalent(PluginAClientConfig &that)
 // Need PluginServer to do this.
 void PluginAClientConfig::copy_from(PluginAClientConfig &that)
 {
-       if(total_ports != that.total_ports)
-       {
+       if( total_ports != that.total_ports ) {
                delete_objects();
                total_ports = that.total_ports;
                port_data = new LADSPA_Data[total_ports];
                port_type = new int[total_ports];
        }
-
-       for(int i = 0; i < total_ports; i++)
-       {
+       for( int i=0; i<total_ports; ++i ) {
                port_type[i] = that.port_type[i];
                port_data[i] = that.port_data[i];
-//printf("PluginAClientConfig::copy_from 1 %f %f\n", port_data[i], that.port_data[i]);
        }
-
 }
 
-void PluginAClientConfig::interpolate(PluginAClientConfig &prev, 
-       PluginAClientConfig &next, 
-       int64_t prev_frame, 
-       int64_t next_frame, 
-       int64_t current_frame)
+void PluginAClientConfig::interpolate(PluginAClientConfig &prev, PluginAClientConfig &next,
+       int64_t prev_frame, int64_t next_frame, int64_t current_frame)
 {
        copy_from(prev);
 }
@@ -101,7 +95,6 @@ void PluginAClientConfig::initialize(PluginServer *server)
 
        const LADSPA_Descriptor *lad_desc = server->lad_descriptor;
        const LADSPA_PortDescriptor *port_desc = lad_desc->PortDescriptors;
-       const LADSPA_PortRangeHint *lad_hint = lad_desc->PortRangeHints;
        int port_count = lad_desc->PortCount;
        for(int i = 0; i < port_count; i++) {
                if( !LADSPA_IS_PORT_INPUT(port_desc[i]) ) continue;
@@ -115,15 +108,14 @@ void PluginAClientConfig::initialize(PluginServer *server)
        for(int port = 0, i = 0; i < port_count; i++) {
                if( !LADSPA_IS_PORT_INPUT(port_desc[i]) ) continue;
                if( !LADSPA_IS_PORT_CONTROL(port_desc[i]) ) continue;
+               const LADSPA_PortRangeHint *lad_hint = &lad_desc->PortRangeHints[i];
+               LADSPA_PortRangeHintDescriptor hint_desc = lad_hint->HintDescriptor;
 // Convert LAD default to default value
                float value = 0.0;
-               LADSPA_PortRangeHintDescriptor hint_desc = lad_hint->HintDescriptor;
 
 // Store type of port for GUI use
                port_type[port] = PORT_NORMAL;
-               if( LADSPA_IS_HINT_SAMPLE_RATE(hint_desc) /* &&
-                   LADSPA_IS_HINT_BOUNDED_ABOVE(hint_desc) &&
-                   LADSPA_IS_HINT_BOUNDED_BELOW(hint_desc) */ ) // LAD frequency table
+               if( LADSPA_IS_HINT_SAMPLE_RATE(hint_desc) )
                        port_type[port] = PORT_FREQ_INDEX;
                else if(LADSPA_IS_HINT_TOGGLED(hint_desc))
                        port_type[port] = PORT_TOGGLE;
@@ -138,8 +130,7 @@ void PluginAClientConfig::initialize(PluginServer *server)
                else if( LADSPA_IS_HINT_DEFAULT_100(hint_desc) )
                        value = 100.0;
                else if( LADSPA_IS_HINT_DEFAULT_440(hint_desc) )
-                       value = port_type[port] == PORT_FREQ_INDEX ?
-                                440.0 / 44100 : 440.0;
+                       value = 440.0;
                else if( LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint_desc) )
                        value = lad_hint->UpperBound;
                else if( LADSPA_IS_HINT_DEFAULT_MINIMUM(hint_desc) )
@@ -293,7 +284,7 @@ void PluginAClientWindow::create_objects()
                int use_min = LADSPA_IS_HINT_BOUNDED_BELOW(hint_desc);
                int use_max = LADSPA_IS_HINT_BOUNDED_ABOVE(hint_desc);
                sprintf(string, "%s:", lad_desc->PortNames[i]);
-// printf("PluginAClientWindow::create_objects 1 %s type=%d lower: %d %f upper: %d %f\n", 
+// printf("PluginAClientWindow::create_objects 1 %s type=%d lower: %d %f upper: %d %f\n",
 // string, plugin->config.port_type[current_port],
 // use_min, lad_hint->LowerBound,  use_max, lad_hint->UpperBound);
 
@@ -315,7 +306,7 @@ void PluginAClientWindow::create_objects()
                        add_subwindow(freq = new PluginACLientFreq(plugin,
                                        (current_port % 2) ? x2 : x3, y,
                                                &plugin->config.port_data[current_port], 0
-                                       /*      (plugin->config.port_type[current_port] == 
+                                       /*      (plugin->config.port_type[current_port] ==
                                                        PluginAClientConfig::PORT_FREQ_INDEX */));
                        freqs.append(freq);
                        break; }
@@ -364,6 +355,7 @@ PluginAClientLAD::PluginAClientLAD(PluginServer *server)
        total_outbuffers = 0;
        buffer_allocation = 0;
        lad_instance = 0;
+       snprintf(title, sizeof(title), "L_%s", server->lad_descriptor->Name);
 }
 
 PluginAClientLAD::~PluginAClientLAD()
@@ -416,7 +408,7 @@ int PluginAClientLAD::get_outchannels()
 
 const char* PluginAClientLAD::plugin_title()
 {
-       return (char*)server->lad_descriptor->Name;
+       return title;
 }
 
 int PluginAClientLAD::uses_gui()
@@ -460,12 +452,11 @@ char* PluginAClientLAD::lad_to_upper(char *string, const char *input)
 
 void PluginAClientLAD::save_data(KeyFrame *keyframe)
 {
-       FileXML output;
-       char string[BCTEXTLEN];
        if( !config.port_data ) config.initialize(server);
-
+       FileXML output;
 // cause data to be stored directly in text
-       output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
+       output.set_shared_output(keyframe->xbuf);
+       char string[BCTEXTLEN];
        output.tag.set_title(lad_to_upper(string, plugin_title()));
 
        const LADSPA_Descriptor *lad_desc = server->lad_descriptor;
@@ -476,7 +467,7 @@ void PluginAClientLAD::save_data(KeyFrame *keyframe)
                if( !LADSPA_IS_PORT_INPUT(port_desc[i]) ) continue;
                if( !LADSPA_IS_PORT_CONTROL(port_desc[i]) ) continue;
 // Convert LAD port name to default title
-               PluginAClientLAD::lad_to_upper(string, 
+               PluginAClientLAD::lad_to_upper(string,
                        (char*)lad_desc->PortNames[i]);
                output.tag.set_property(string, config.port_data[port]);
 //printf("PluginAClientLAD::save_data %d %f\n", port, config.port_data[port]);
@@ -489,14 +480,13 @@ void PluginAClientLAD::save_data(KeyFrame *keyframe)
 
 void PluginAClientLAD::read_data(KeyFrame *keyframe)
 {
+       if( !config.port_data ) config.initialize(server);
        FileXML input;
-       char string[BCTEXTLEN];
-
-       input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
-       config.initialize(server);
+       input.set_shared_input(keyframe->xbuf);
 
        while(! input.read_tag() ) {
 //printf("PluginAClientLAD::read_data %s\n", input.tag.get_title());
+               char string[BCTEXTLEN];
                if(! input.tag.title_is(lad_to_upper(string, plugin_title())) ) continue;
                const LADSPA_Descriptor *lad_desc = server->lad_descriptor;
                const LADSPA_PortDescriptor *port_desc = lad_desc->PortDescriptors;
@@ -505,7 +495,7 @@ void PluginAClientLAD::read_data(KeyFrame *keyframe)
                        if( !LADSPA_IS_PORT_INPUT(port_desc[i]) ) continue;
                        if( !LADSPA_IS_PORT_CONTROL(port_desc[i]) ) continue;
                        PluginAClientLAD::lad_to_upper(string, (char*)lad_desc->PortNames[i]);
-                       config.port_data[port] = 
+                       config.port_data[port] =
                                input.tag.get_property(string, config.port_data[port]);
 //printf("PluginAClientLAD::read_data %d %f\n", port, config.port_data[port]);
                        port++;
@@ -515,12 +505,14 @@ void PluginAClientLAD::read_data(KeyFrame *keyframe)
 
 void PluginAClientLAD::delete_buffers()
 {
-       if(in_buffers)
-               for(int i = 0; i < total_inbuffers; i++) delete [] in_buffers[i];
-       if(out_buffers)
-               for(int i = 0; i < total_outbuffers; i++) delete [] out_buffers[i];
-       in_buffers = 0;
-       out_buffers = 0;
+       if( in_buffers ) {
+               for( int i=0; i<total_inbuffers; ++i ) delete [] in_buffers[i];
+               delete [] in_buffers;  in_buffers = 0;
+       }
+       if( out_buffers ) {
+               for( int i=0; i<total_outbuffers; ++i ) delete [] out_buffers[i];
+               delete [] out_buffers;  out_buffers = 0;
+       }
        total_inbuffers = 0;
        total_outbuffers = 0;
        buffer_allocation = 0;
@@ -539,6 +531,10 @@ void PluginAClientLAD::delete_plugin()
 void PluginAClientLAD::init_plugin(int total_in, int total_out, int size)
 {
        int need_reconfigure = !lad_instance ? 1 : 0;
+       if( !config.port_data ) {
+               config.initialize(server);
+               need_reconfigure = 1;
+       }
        if(buffer_allocation && buffer_allocation < size) {
                delete_buffers();
                need_reconfigure = 1;
@@ -548,7 +544,7 @@ void PluginAClientLAD::init_plugin(int total_in, int total_out, int size)
        if(!in_buffers) {
                total_inbuffers = total_in;
                in_buffers = new LADSPA_Data*[total_inbuffers];
-               for(int i = 0; i < total_inbuffers; i++) 
+               for(int i = 0; i < total_inbuffers; i++)
                        in_buffers[i] = new LADSPA_Data[buffer_allocation];
                need_reconfigure = 1;
        }
@@ -556,7 +552,7 @@ void PluginAClientLAD::init_plugin(int total_in, int total_out, int size)
        if(!out_buffers) {
                total_outbuffers = total_out;
                out_buffers = new LADSPA_Data*[total_outbuffers];
-               for(int i = 0; i < total_outbuffers; i++) 
+               for(int i = 0; i < total_outbuffers; i++)
                        out_buffers[i] = new LADSPA_Data[buffer_allocation];
                need_reconfigure = 1;
        }
@@ -572,7 +568,7 @@ void PluginAClientLAD::init_plugin(int total_in, int total_out, int size)
                                lad_desc,PluginAClient::project_sample_rate);
                const LADSPA_PortDescriptor *port_desc = lad_desc->PortDescriptors;
                int port_count = lad_desc->PortCount;
-       
+
                for(int port = 0, i = 0; i < port_count; i++) {
                        if( LADSPA_IS_PORT_INPUT(port_desc[i]) &&
                            LADSPA_IS_PORT_CONTROL(port_desc[i]) ) {
@@ -604,8 +600,8 @@ void PluginAClientLAD::init_plugin(int total_in, int total_out, int size)
        }
 }
 
-int PluginAClientLAD::process_realtime(int64_t size, 
-       Samples *input_ptr, 
+int PluginAClientLAD::process_realtime(int64_t size,
+       Samples *input_ptr,
        Samples *output_ptr)
 {
        int in_channels = get_inchannels();
@@ -628,7 +624,7 @@ int PluginAClientLAD::process_realtime(int64_t size,
        return size;
 }
 
-int PluginAClientLAD::process_realtime(int64_t size, 
+int PluginAClientLAD::process_realtime(int64_t size,
        Samples **input_ptr, Samples **output_ptr)
 {
        int in_channels = get_inchannels();
@@ -656,5 +652,15 @@ int PluginAClientLAD::process_realtime(int64_t size,
        return size;
 }
 
+int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
+       FILE *fp, const char *plugin_dir)
+{
+       char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
+       strcpy(plugin_path, path);  delete [] path;
+       printf("init ladspa index: %s\n", plugin_dir);
+       fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
+       fprintf(fp, "%s\n", plugin_dir);
+       init_plugin_index(mwindow, preferences, fp, plugin_path);
+       return 0;
+}