scan VSTs in background, allow to cancel & timeout
authorRobin Gareus <robin@gareus.org>
Tue, 25 Feb 2014 12:11:07 +0000 (13:11 +0100)
committerRobin Gareus <robin@gareus.org>
Tue, 25 Feb 2014 13:57:59 +0000 (14:57 +0100)
libs/ardour/ardour/plugin_manager.h
libs/ardour/plugin_manager.cc
libs/ardour/vst_info_file.cc

index 0806935a26e5748344eb6c087bd34ed357f438f3..d8e6b4c5ecb723a02d4a14bad8cdedf37d3d30d9 100644 (file)
@@ -56,6 +56,8 @@ class LIBARDOUR_API PluginManager : public boost::noncopyable {
        void clear_vst_cache ();
        void clear_vst_blacklist ();
 
+       bool cancelled () { return cancel_scan; }
+
        int add_windows_vst_directory (std::string dirpath);
        int add_lxvst_directory (std::string dirpath);
 
index 070936add1b72b109adb6dcdb48e7c27f5c637cd..c145fd3aa4116778819fac7ee880aaf5f6b193a1 100644 (file)
@@ -187,6 +187,7 @@ PluginManager::refresh (bool cache_only)
 {
        DEBUG_TRACE (DEBUG::PluginManager, "PluginManager::refresh\n");
        BootMessage (_("Discovering Plugins"));
+       cancel_scan = false;
 
        ladspa_refresh ();
 #ifdef LV2_SUPPORT
@@ -210,12 +211,13 @@ PluginManager::refresh (bool cache_only)
 
        PluginListChanged (); /* EMIT SIGNAL */
        PluginScanMessage(X_("closeme"), "");
+       cancel_scan = false;
 }
 
 void
 PluginManager::cancel_plugin_scan ()
 {
-       // TODO
+       cancel_scan = true;
 }
 
 void
@@ -661,6 +663,7 @@ PluginManager::windows_vst_discover_from_path (string path, bool cache_only)
 
        if (plugin_objects) {
                for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
+                       if (cancelled()) break;
                        ARDOUR::PluginScanMessage(_("VST"), **x);
                        windows_vst_discover (**x, cache_only);
                }
@@ -800,6 +803,7 @@ PluginManager::lxvst_discover_from_path (string path, bool cache_only)
 
        if (plugin_objects) {
                for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
+                       if (cancelled()) break;
                        ARDOUR::PluginScanMessage(_("LXVST"), **x);
                        lxvst_discover (**x, cache_only);
                }
index 8bb3f4aa7adf8451e61c5f458c399176758f4f74..fac3f199bc079494f6f64cc31bc4cb692cf55333 100644 (file)
@@ -52,6 +52,7 @@
 #include "ardour/vst_info_file.h"
 
 #define MAX_STRING_LEN 256
+#define PLUGIN_SCAN_TIMEOUT (600) // in deciseconds
 
 using namespace std;
 
@@ -746,8 +747,13 @@ vstfx_get_info (const char* dllpath, int type, enum VSTScanMode mode)
                        PBD::error << "Cannot launch VST scanner app '" << scanner_bin_path << "': "<< strerror(errno) << endmsg;
                        return infos;
                } else {
-                       // TODO idle loop (emit signal to GUI to call gtk_main_iteration()) check cancel.
-                       scanner.wait();
+                       int timeout = PLUGIN_SCAN_TIMEOUT;
+                       while (scanner.is_running() && --timeout) {
+                               ARDOUR::GUIIdle();
+                               Glib::usleep (100000);
+                               if (ARDOUR::PluginManager::instance().cancelled()) break;
+                       }
+                       scanner.terminate();
                }
                /* re-read index */
                vstfx_clear_info_list(infos);