olaf neophyte and de.po updates, valgrind tweaks, delete green lady, inkscape dpi=96
[goodguy/history.git] / cinelerra-5.1 / cinelerra / pluginserver.C
index 0c72a3582d145d324ce94784001807911ace3bef..6e42e947a4a10b3d51e5acc34ab54f4ed78e52b6 100644 (file)
@@ -79,6 +79,7 @@ void PluginServer::init()
        plugin_obj = new PluginObj();
        modules = new ArrayList<Module*>;
        nodes = new ArrayList<VirtualNode*>;
+       tip = 0;
 }
 
 PluginServer::PluginServer()
@@ -86,7 +87,7 @@ PluginServer::PluginServer()
        init();
 }
 
-PluginServer::PluginServer(MWindow *mwindow, char *path, int type)
+PluginServer::PluginServer(MWindow *mwindow, const char *path, int type)
 {
        char fpath[BCTEXTLEN];
        init();
@@ -97,7 +98,7 @@ PluginServer::PluginServer(MWindow *mwindow, char *path, int type)
                sprintf(fpath, "ff_%s", path);
                path = fpath;
        }
-        set_path(path);
+       set_path(path);
 }
 
 PluginServer::PluginServer(PluginServer &that)
@@ -107,6 +108,7 @@ PluginServer::PluginServer(PluginServer &that)
        plugin_obj = that.plugin_obj;
        plugin_obj->add_user();
        title = !that.title ? 0 : cstrdup(that.title);
+       tip = !that.tip ? 0 : cstrdup(that.tip);
        path = !that.path ? 0 : cstrdup(that.path);
        ff_name = !that.ff_name ? 0 : cstrdup(that.ff_name);
        modules = new ArrayList<Module*>;
@@ -137,6 +139,7 @@ PluginServer::~PluginServer()
        delete [] path;
        delete [] ff_name;
        delete [] title;
+       delete [] tip;
        delete modules;
        delete nodes;
        delete picon;
@@ -151,18 +154,14 @@ int PluginServer::reset_parameters()
        prompt = 0;
        cleanup_plugin();
 
-       lad_index = -1;
-       lad_descriptor_function = 0;
-       lad_descriptor = 0;
-
        plugin_obj = 0;
        client = 0; 
        new_plugin = 0;
        lad_index = -1;
        lad_descriptor_function = 0;
        lad_descriptor = 0;
-       use_opengl = 0;
        ff_name = 0;
+       use_opengl = 0;
        vdevice = 0;
        plugin_type = 0;
        start_auto = end_auto = 0;
@@ -175,6 +174,7 @@ int PluginServer::reset_parameters()
        uses_gui = 0;
        transition = 0;
        title = 0;
+       tip = 0;
        path = 0;
        data_text = 0;
        for( int i=sizeof(args)/sizeof(args[0]); --i>=0; ) args[i] = 0;
@@ -238,6 +238,21 @@ int PluginServer::get_lad_index()
        return this->lad_index;
 }
 
+int PluginServer::is_unknown()
+{
+       return plugin_type == PLUGIN_TYPE_UNKNOWN ? 1 : 0;
+}
+
+int PluginServer::is_executable()
+{
+       return  plugin_type == PLUGIN_TYPE_EXECUTABLE ? 1 : 0;
+}
+
+int PluginServer::is_builtin()
+{
+       return plugin_type == PLUGIN_TYPE_BUILTIN ? 1 : 0;
+}
+
 int PluginServer::is_ladspa()
 {
        return plugin_type == PLUGIN_TYPE_LADSPA ? 1 : 0;
@@ -248,6 +263,11 @@ int PluginServer::is_ffmpeg()
        return plugin_type == PLUGIN_TYPE_FFMPEG ? 1 : 0;
 }
 
+int PluginServer::is_lv2()
+{
+       return plugin_type == PLUGIN_TYPE_LV2 ? 1 : 0;
+}
+
 void PluginServer::set_path(const char *path)
 {
        delete [] this->path;
@@ -267,7 +287,7 @@ int PluginServer::get_synthesis()
 
 void PluginServer::set_title(const char *string)
 {
-       if(title) delete [] title;
+       delete [] title;
        title = cstrdup(string);
 }
 
@@ -328,20 +348,20 @@ int PluginServer::open_plugin(int master,
        this->preferences = preferences;
        this->plugin = plugin;
        this->edl = edl;
-       if( plugin_type != PLUGIN_TYPE_FFMPEG && plugin_type != PLUGIN_TYPE_EXECUTABLE && !load_obj() ) {
-// If the load failed, can't use error to detect executable
-//  because locale and language selection change the load_error()
+       if( !is_ffmpeg() && !is_lv2() && !is_executable() && !load_obj() ) {
+// If the load failed, can't use error string to detect executable
+//  because locale and language selection changes the load_error() message
 //     if( !strstr(string, "executable") ) { set_title(path); plugin_type = PLUGIN_TYPE_EXECUTABLE; }
                eprintf("PluginServer::open_plugin: load_obj %s = %s\n", path, load_error());
                return PLUGINSERVER_NOT_RECOGNIZED;
        }
-       if( plugin_type == PLUGIN_TYPE_UNKNOWN || plugin_type == PLUGIN_TYPE_BUILTIN ) {
+       if( is_unknown() || is_builtin() ) {
                new_plugin =
                        (PluginClient* (*)(PluginServer*)) get_sym("new_plugin");
                if( new_plugin )
                        plugin_type = PLUGIN_TYPE_BUILTIN;
        }
-       if( plugin_type == PLUGIN_TYPE_UNKNOWN || plugin_type == PLUGIN_TYPE_LADSPA ) {
+       if( is_unknown() || is_ladspa() ) {
                lad_descriptor_function =
                        (LADSPA_Descriptor_Function) get_sym("ladspa_descriptor");
                if( lad_descriptor_function ) {
@@ -352,7 +372,7 @@ int PluginServer::open_plugin(int master,
                        plugin_type = PLUGIN_TYPE_LADSPA;
                }
        }
-       if( plugin_type == PLUGIN_TYPE_UNKNOWN ) {
+       if( is_unknown() ) {
                fprintf(stderr, "PluginServer::open_plugin "
                        " %d: plugin undefined in %s\n", __LINE__, path);
                return PLUGINSERVER_NOT_RECOGNIZED;
@@ -363,11 +383,14 @@ int PluginServer::open_plugin(int master,
        case PLUGIN_TYPE_BUILTIN:
                client = new_plugin(this);
                break;
+       case PLUGIN_TYPE_FFMPEG:
+               client = new_ffmpeg_plugin();
+               break;
        case PLUGIN_TYPE_LADSPA:
                client = new PluginAClientLAD(this);
                break;
-       case PLUGIN_TYPE_FFMPEG:
-               client = new_ffmpeg_plugin();
+       case PLUGIN_TYPE_LV2:
+               client = new_lv2_plugin();
                break;
        default:
                client = 0;
@@ -1218,48 +1241,43 @@ Theme* PluginServer::get_theme()
 }
 
 
-int PluginServer::get_theme_png_path(char *png_path, const char *theme_dir)
+void PluginServer::get_plugin_png_name(char *png_name)
 {
-       char *bp = strrchr(path, '/');
-       if( !bp ) bp = path; else ++bp;
-       char *sp = strrchr(bp,'.');
-       if( !sp ) sp = bp + strlen(bp);
-       char *cp = png_path, *dp = bp;
-       cp += sprintf(cp,"%s/%s/", mwindow->preferences->plugin_dir, theme_dir);
-       while( dp < sp ) *cp++ = *dp++;
-       strcpy(cp, ".png");
-       struct stat st;
-       if( stat(png_path, &st) ) return 0;
-       if( !S_ISREG(st.st_mode) ) return 0;
-       if( st.st_size == 0 ) return 0;
-       return st.st_size;
+       char *pp = png_name, *ep = pp + BCSTRLEN-1;
+       char *cp = strrchr(path, '/');
+       cp = !cp ? path : cp+1;
+       char *sp = strrchr(cp, '.');
+       if( !sp ) sp = cp+strlen(cp);
+       while( pp < ep && cp < sp ) *pp++ = *cp++;
+       snprintf(pp, ep-pp, ".png");
 }
 
-int PluginServer::get_theme_png_path(char *png_path, Theme *theme)
+int PluginServer::get_plugin_png_path(char *png_path, const char *plugin_icons)
 {
-       char *bp = strrchr(theme->path, '/');
-       if( !bp ) bp = theme->path; else ++bp;
-       char *sp = strrchr(bp,'.');
-       if( !sp || ( strcmp(sp, ".plugin") && strcmp(sp,".so") ) ) return 0;
-       char theme_dir[BCTEXTLEN], *cp = theme_dir;
-       while( bp < sp ) *cp++ = *bp++;
-       *cp = 0;
-       return get_theme_png_path(png_path, theme_dir);
+       char png_name[BCSTRLEN];
+       get_plugin_png_name(png_name);
+       char *pp = png_path, *ep = pp + BCTEXTLEN-1;
+       pp += snprintf(pp, ep-pp, "%s/picon/%s/%s",
+               File::get_plugin_path(), plugin_icons, png_name);
+       return access(png_path,R_OK) ? 1 : 0;
 }
 
 int PluginServer::get_plugin_png_path(char *png_path)
 {
-       int len = get_theme_png_path(png_path, mwindow->theme);
-       if( !len )
-               len = get_theme_png_path(png_path, "picon");
-       return len;
+       int ret = get_plugin_png_path(png_path, mwindow->preferences->plugin_icons);
+       if( ret ) ret = get_plugin_png_path(png_path, DEFAULT_PICON);
+       return ret;
 }
 
 VFrame *PluginServer::get_plugin_images()
 {
        char png_path[BCTEXTLEN];
-       if( !get_plugin_png_path(png_path) ) return 0;
-       return VFramePng::vframe_png(png_path,0,0);
+       if( !get_plugin_png_path(png_path) )
+               return VFramePng::vframe_png(png_path,0,0);
+       char png_name[BCSTRLEN];
+       get_plugin_png_name(png_name);
+       unsigned char *data = mwindow->theme->get_image_data(png_name, 0);
+       return data ? new VFramePng(data, 0.) : 0;
 }
 
 VFrame *PluginServer::get_picon()