fix errors in manual conflict resolution
[ardour.git] / libs / ardour / linux_vst_support.cc
index 9106d69009450bc5870a2aa5fa8c43322e00d12e..0d976d653b520d0bdc20b134873e2860402c2afd 100644 (file)
@@ -34,8 +34,6 @@
 #include <glibmm/fileutils.h>
 
 #include "ardour/linux_vst_support.h"
-#include "ardour/vst_plugin.h"
-
 #include "pbd/basename.h"
 #include "pbd/error.h"
 
@@ -114,7 +112,7 @@ vstfx_new ()
 void* vstfx_load_vst_library(const char* path)
 {
        void* dll;
-       char* full_path;
+       char* full_path = NULL;
        char* envdup;
        char* lxvst_path;
        size_t len1;
@@ -162,6 +160,7 @@ void* vstfx_load_vst_library(const char* path)
                vstfx_error ("\"%s\"", lxvst_path);
                len1 = strlen(lxvst_path);
                
+               if (full_path) free(full_path);
                full_path = (char*)malloc(len1 + 1 + len2 + 1);
                memcpy(full_path, lxvst_path, len1);
                full_path[len1] = '/';
@@ -182,7 +181,7 @@ void* vstfx_load_vst_library(const char* path)
        }
 
        /*Free the path*/
-
+       if (full_path) free(full_path);
        free(envdup);
 
        return dll;
@@ -211,8 +210,6 @@ vstfx_load (const char *path)
                buf = (char *)malloc(strlen(path) + 4); //The .so and a terminating zero
 
                sprintf (buf, "%s.so", path);
-               
-               fhandle->nameptr = strdup (path);
 
        }
        else
@@ -220,8 +217,6 @@ vstfx_load (const char *path)
                /*We already have .so appened to the filename*/
                
                buf = strdup(path);
-               
-               fhandle->nameptr = strdup (path);
        }
 
        /* get a name for the plugin based on the path: ye old VST problem where
@@ -229,7 +224,7 @@ vstfx_load (const char *path)
           which we don't want to do at this point
        */
        
-       fhandle->name = strdup (PBD::basename_nosuffix (fhandle->nameptr).c_str());
+       fhandle->name = strdup (PBD::basename_nosuffix (path).c_str());
 
        /*call load_vstfx_library to actually load the .so into memory*/
 
@@ -244,7 +239,15 @@ vstfx_load (const char *path)
 
        /*Find the main entry point into the plugin*/
 
-       if ((fhandle->main_entry = (main_entry_t) dlsym(fhandle->dll, "main")) == 0)
+       fhandle->main_entry = (main_entry_t) dlsym(fhandle->dll, "main");
+
+       if (fhandle->main_entry == 0) {
+               if ((fhandle->main_entry = (main_entry_t) dlsym(fhandle->dll, "VSTPluginMain")) != 0) {
+                       PBD::warning << path << _(": is a VST >= 2.4 - this plugin may or may not function correctly with this version of Ardour.") << endmsg;
+               }
+       }
+
+       if (fhandle->main_entry == 0)
        {
                /*If it can't be found, unload the plugin and return a 0 handle*/
                
@@ -283,9 +286,8 @@ vstfx_unload (VSTHandle* fhandle)
                fhandle->dll = 0;
        }
 
-       if (fhandle->nameptr)
+       if (fhandle->name)
        {
-               free (fhandle->nameptr);
                free (fhandle->name);
        }
        
@@ -295,43 +297,37 @@ vstfx_unload (VSTHandle* fhandle)
        return 0;
 }
 
-/**
-   Instantiates a VST plugin and also set _state of its plugin argument 
- */
+/*This instantiates a plugin*/
 
-VSTState*
-vstfx_instantiate (VSTHandle* fhandle, audioMasterCallback amc, void *ptr)
+VSTState *
+vstfx_instantiate (VSTHandle* fhandle, audioMasterCallback amc, void* userptr)
 {
        VSTState* vstfx = vstfx_new ();
-       ARDOUR::VSTPlugin* plugin = reinterpret_cast<ARDOUR::VSTPlugin*> (ptr);
 
-       if (fhandle == 0) {
-           vstfx_error( "** ERROR ** VSTFX : The handle was 0\n" );
-           return 0;
+       if(fhandle == 0)
+       {
+               vstfx_error( "** ERROR ** VSTFX : The handle was 0\n" );
+               free (vstfx);
+               return 0;
        }
 
-       if ((vstfx->plugin = fhandle->main_entry (amc)) == 0) {
+       if ((vstfx->plugin = fhandle->main_entry (amc)) == 0) 
+       {
                vstfx_error ("** ERROR ** VSTFX : %s could not be instantiated :(\n", fhandle->name);
                free (vstfx);
                return 0;
        }
        
        vstfx->handle = fhandle;
-       vstfx->plugin->user = plugin;
+       vstfx->plugin->user = userptr;
                
-       if (vstfx->plugin->magic != kEffectMagic) {
+       if (vstfx->plugin->magic != kEffectMagic)
+       {
                vstfx_error ("** ERROR ** VSTFX : %s is not a VST plugin\n", fhandle->name);
                free (vstfx);
                return 0;
        }
-
-       /* need to set this here because some plugins make audioMaster
-        * callbacks from within effOpen, and _state must be set for
-        * that to work.
-        */
        
-       plugin->set_state (vstfx);
-
        vstfx->plugin->dispatcher (vstfx->plugin, effOpen, 0, 0, 0, 0);
        
        /*May or May not need to 'switch the plugin on' here - unlikely
@@ -388,6 +384,7 @@ void vstfx_close (VSTState* vstfx)
                dlclose(vstfx->handle->dll); //dlclose keeps its own reference count
                vstfx->handle->dll = 0;
        }
+       free(vstfx);
 }