Post-export hook tweaks
[ardour.git] / libs / ardour / plugin_manager.cc
index 97eb1bf1c98299ea5480b65313ed93186d8bdf38..7c3eae538f9531fa9e17b20a2a796c2ebb4b3c6b 100644 (file)
@@ -62,7 +62,7 @@
 #include "ardour/plugin_manager.h"
 #include "ardour/rc_configuration.h"
 
-#include "ardour/ladspa_search_path.h"
+#include "ardour/search_paths.h"
 
 #ifdef LV2_SUPPORT
 #include "ardour/lv2_plugin.h"
@@ -83,7 +83,6 @@
 
 #include "pbd/error.h"
 #include "pbd/stl_delete.h"
-#include "pbd/fallback_folders.h"
 
 #include "i18n.h"
 
@@ -111,15 +110,15 @@ PluginManager::PluginManager ()
        , _ladspa_plugin_info(0)
        , _lv2_plugin_info(0)
        , _au_plugin_info(0)
-       , cancel_scan(false)
+       , _cancel_scan(false)
+       , _cancel_timeout(false)
 {
        char* s;
        string lrdf_path;
 
-       if (!PBD::find_file_in_search_path (
-                               PBD::Searchpath(Glib::build_filename(ARDOUR::ardour_dll_directory(), "fst")),
-                               "ardour-vst-scanner", scanner_bin_path)) {
-               PBD::warning << "VST scanner app not found.'" << endmsg;
+       string  scan_p = Glib::build_filename(ARDOUR::ardour_dll_directory(), "fst");
+       if (!PBD::find_file_in_search_path ( PBD::Searchpath(scan_p), "ardour-vst-scanner", scanner_bin_path)) {
+               PBD::warning << "VST scanner app (ardour-vst-scanner) not found in path " << scan_p <<  endmsg;
        }
 
        load_statuses ();
@@ -153,11 +152,7 @@ PluginManager::PluginManager ()
        }
 
        if (windows_vst_path.length() == 0) {
-#ifdef PLATFORM_WINDOWS
-               windows_vst_path = PBD::get_platform_fallback_folder (PBD::FOLDER_VST);
-#else
-               windows_vst_path = "/usr/local/lib/vst:/usr/lib/vst";
-#endif
+               windows_vst_path = vst_search_path ();
        }
 
        if ((s = getenv ("LXVST_PATH"))) {
@@ -172,6 +167,14 @@ PluginManager::PluginManager ()
                        "/usr/lib/vst:/usr/local/lib/vst";
        }
 
+       /* first time setup, use 'default' path */
+       if (Config->get_plugin_path_lxvst() == X_("@default@")) {
+               Config->set_plugin_path_lxvst(get_default_lxvst_path());
+       }
+       if (Config->get_plugin_path_vst() == X_("@default@")) {
+               Config->set_plugin_path_vst(get_default_windows_vst_path());
+       }
+
        if (_instance == 0) {
                _instance = this;
        }
@@ -184,64 +187,53 @@ PluginManager::~PluginManager()
 {
 }
 
-const std::string
-PluginManager::lxvst_search_path() const
-{
-       std::string searchpath = lxvst_path;
-       if (!Config->get_plugin_path_lxvst().empty()) {
-               searchpath += G_SEARCHPATH_SEPARATOR;
-               searchpath += Config->get_plugin_path_lxvst();
-       }
-       return searchpath;
-}
-
-const std::string
-PluginManager::windows_vst_search_path() const
-{
-       std::string searchpath = windows_vst_path;
-       if (!Config->get_plugin_path_vst().empty()) {
-               searchpath += G_SEARCHPATH_SEPARATOR;
-               searchpath += Config->get_plugin_path_vst();
-       }
-       return searchpath;
-}
-
 void
 PluginManager::refresh (bool cache_only)
 {
        DEBUG_TRACE (DEBUG::PluginManager, "PluginManager::refresh\n");
-       BootMessage (_("Discovering Plugins"));
-       cancel_scan = false;
+       _cancel_scan = false;
 
+       BootMessage (_("Scanning LADSPA Plugins"));
        ladspa_refresh ();
 #ifdef LV2_SUPPORT
+       BootMessage (_("Scanning LV2 Plugins"));
        lv2_refresh ();
 #endif
 #ifdef WINDOWS_VST_SUPPORT
        if (Config->get_use_windows_vst()) {
+               BootMessage (_("Scanning Windows VST Plugins"));
                windows_vst_refresh (cache_only);
        }
 #endif // WINDOWS_VST_SUPPORT
 
 #ifdef LXVST_SUPPORT
        if(Config->get_use_lxvst()) {
+               BootMessage (_("Scanning Linux VST Plugins"));
                lxvst_refresh(cache_only);
        }
 #endif //Native linuxVST SUPPORT
 
 #ifdef AUDIOUNIT_SUPPORT
+       BootMessage (_("Scanning AU Plugins"));
        au_refresh ();
 #endif
 
+       BootMessage (_("Plugin Scan Complete..."));
        PluginListChanged (); /* EMIT SIGNAL */
        PluginScanMessage(X_("closeme"), "", false);
-       cancel_scan = false;
+       _cancel_scan = false;
 }
 
 void
 PluginManager::cancel_plugin_scan ()
 {
-       cancel_scan = true;
+       _cancel_scan = true;
+}
+
+void
+PluginManager::cancel_plugin_timeout ()
+{
+       _cancel_timeout = true;
 }
 
 void
@@ -253,7 +245,7 @@ PluginManager::clear_vst_cache ()
                PathScanner scanner;
                vector<string *> *fsi_files;
 
-               fsi_files = scanner (windows_vst_search_path(), "\\.fsi$", true, true, -1, false);
+               fsi_files = scanner (Config->get_plugin_path_vst(), "\\.fsi$", true, true, -1, false);
                if (fsi_files) {
                        for (vector<string *>::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) {
                                ::g_unlink((*i)->c_str());
@@ -267,7 +259,7 @@ PluginManager::clear_vst_cache ()
        {
                PathScanner scanner;
                vector<string *> *fsi_files;
-               fsi_files = scanner (lxvst_search_path(), "\\.fsi$", true, true, -1, false);
+               fsi_files = scanner (Config->get_plugin_path_lxvst(), "\\.fsi$", true, true, -1, false);
                if (fsi_files) {
                        for (vector<string *>::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) {
                                ::g_unlink((*i)->c_str());
@@ -301,7 +293,7 @@ PluginManager::clear_vst_blacklist ()
                PathScanner scanner;
                vector<string *> *fsi_files;
 
-               fsi_files = scanner (windows_vst_search_path(), "\\.fsb$", true, true, -1, false);
+               fsi_files = scanner (Config->get_plugin_path_vst(), "\\.fsb$", true, true, -1, false);
                if (fsi_files) {
                        for (vector<string *>::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) {
                                ::g_unlink((*i)->c_str());
@@ -315,7 +307,7 @@ PluginManager::clear_vst_blacklist ()
        {
                PathScanner scanner;
                vector<string *> *fsi_files;
-               fsi_files = scanner (lxvst_search_path(), "\\.fsb$", true, true, -1, false);
+               fsi_files = scanner (Config->get_plugin_path_lxvst(), "\\.fsb$", true, true, -1, false);
                if (fsi_files) {
                        for (vector<string *>::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) {
                                ::g_unlink((*i)->c_str());
@@ -648,7 +640,7 @@ PluginManager::windows_vst_refresh (bool cache_only)
                _windows_vst_plugin_info = new ARDOUR::PluginInfoList();
        }
 
-       windows_vst_discover_from_path (windows_vst_search_path(), cache_only);
+       windows_vst_discover_from_path (Config->get_plugin_path_vst(), cache_only);
 }
 
 static bool windows_vst_filter (const string& str, void * /*arg*/)
@@ -668,7 +660,7 @@ PluginManager::windows_vst_discover_from_path (string path, bool cache_only)
 
        DEBUG_TRACE (DEBUG::PluginManager, string_compose ("detecting Windows VST plugins along %1\n", path));
 
-       plugin_objects = scanner (windows_vst_search_path(), windows_vst_filter, 0, false, true);
+       plugin_objects = scanner (Config->get_plugin_path_vst(), windows_vst_filter, 0, false, true);
 
        if (plugin_objects) {
                for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
@@ -687,6 +679,7 @@ PluginManager::windows_vst_discover (string path, bool cache_only)
 {
        DEBUG_TRACE (DEBUG::PluginManager, string_compose ("windows_vst_discover '%1'\n", path));
 
+       _cancel_timeout = false;
        vector<VSTInfo*> * finfos = vstfx_get_info_fst (const_cast<char *> (path.c_str()),
                        cache_only ? VST_SCAN_CACHE_ONLY : VST_SCAN_USE_APP);
 
@@ -726,7 +719,8 @@ PluginManager::windows_vst_discover (string path, bool cache_only)
                info->index = 0;
                info->n_inputs.set_audio (finfo->numInputs);
                info->n_outputs.set_audio (finfo->numOutputs);
-               info->n_inputs.set_midi (finfo->wantMidi ? 1 : 0);
+               info->n_inputs.set_midi ((finfo->wantMidi&1) ? 1 : 0);
+               info->n_outputs.set_midi ((finfo->wantMidi&2) ? 1 : 0);
                info->type = ARDOUR::Windows_VST;
 
                // TODO: check dup-IDs (lxvst AND windows vst)
@@ -766,7 +760,7 @@ PluginManager::lxvst_refresh (bool cache_only)
                _lxvst_plugin_info = new ARDOUR::PluginInfoList();
        }
 
-       lxvst_discover_from_path (lxvst_search_path(), cache_only);
+       lxvst_discover_from_path (Config->get_plugin_path_lxvst(), cache_only);
 }
 
 static bool lxvst_filter (const string& str, void *)
@@ -790,7 +784,7 @@ PluginManager::lxvst_discover_from_path (string path, bool cache_only)
 
        DEBUG_TRACE (DEBUG::PluginManager, string_compose ("Discovering linuxVST plugins along %1\n", path));
 
-       plugin_objects = scanner (lxvst_search_path(), lxvst_filter, 0, false, true);
+       plugin_objects = scanner (Config->get_plugin_path_lxvst(), lxvst_filter, 0, false, true);
 
        if (plugin_objects) {
                for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
@@ -809,6 +803,7 @@ PluginManager::lxvst_discover (string path, bool cache_only)
 {
        DEBUG_TRACE (DEBUG::PluginManager, string_compose ("checking apparent LXVST plugin at %1\n", path));
 
+       _cancel_timeout = false;
        vector<VSTInfo*> * finfos = vstfx_get_info_lx (const_cast<char *> (path.c_str()),
                        cache_only ? VST_SCAN_CACHE_ONLY : VST_SCAN_USE_APP);
 
@@ -846,7 +841,8 @@ PluginManager::lxvst_discover (string path, bool cache_only)
                info->index = 0;
                info->n_inputs.set_audio (finfo->numInputs);
                info->n_outputs.set_audio (finfo->numOutputs);
-               info->n_inputs.set_midi (finfo->wantMidi ? 1 : 0);
+               info->n_inputs.set_midi ((finfo->wantMidi&1) ? 1 : 0);
+               info->n_outputs.set_midi ((finfo->wantMidi&2) ? 1 : 0);
                info->type = ARDOUR::LXVST;
 
                                        /* Make sure we don't find the same plugin in more than one place along