fix crash when copy'ing latent plugins
[ardour.git] / libs / ardour / globals.cc
index 0a1d0cd085406dd66920e8b15a6cef90ff013ed1..974247aef57cb08d26daebf280485cee9bc1da8e 100644 (file)
@@ -41,6 +41,7 @@
 #include "pbd/gstdio_compat.h"
 
 #ifdef PLATFORM_WINDOWS
+#include <stdio.h> // for _setmaxstdio
 #include <windows.h> // for LARGE_INTEGER
 #endif
 
@@ -79,7 +80,6 @@
 #include "pbd/fpu.h"
 #include "pbd/file_utils.h"
 #include "pbd/enumwriter.h"
-#include "pbd/basename.h"
 
 #include "midi++/port.h"
 #include "midi++/mmc.h"
 #include "ardour/event_type_map.h"
 #include "ardour/filesystem_paths.h"
 #include "ardour/midi_region.h"
+#include "ardour/midi_ui.h"
 #include "ardour/midiport_manager.h"
 #include "ardour/mix.h"
 #include "ardour/operations.h"
 #include "ardour/panner_manager.h"
 #include "ardour/plugin_manager.h"
+#include "ardour/presentation_info.h"
 #include "ardour/process_thread.h"
 #include "ardour/profile.h"
 #include "ardour/rc_configuration.h"
 #include "audiographer/routines.h"
 
 #if defined (__APPLE__)
-       #include <Carbon/Carbon.h> // For Gestalt
+#include <CoreFoundation/CoreFoundation.h>
 #endif
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 ARDOUR::RCConfiguration* ARDOUR::Config = 0;
 ARDOUR::RuntimeProfile* ARDOUR::Profile = 0;
@@ -204,12 +206,8 @@ setup_hardware_optimization (bool try_optimization)
                }
 
 #elif defined (__APPLE__) && defined (BUILD_VECLIB_OPTIMIZATIONS)
-               SInt32 sysVersion = 0;
 
-               if (noErr != Gestalt(gestaltSystemVersion, &sysVersion))
-                       sysVersion = 0;
-
-               if (sysVersion >= 0x00001040) { // Tiger at least
+               if (floor (kCFCoreFoundationVersionNumber) > kCFCoreFoundationVersionNumber10_4) { /* at least Tiger */
                        compute_peak           = veclib_compute_peak;
                        find_peaks             = veclib_find_peaks;
                        apply_gain_to_buffer   = veclib_apply_gain_to_buffer;
@@ -273,6 +271,21 @@ lotsa_files_please ()
        } else {
                error << string_compose (_("Could not get system open files limit (%1)"), strerror (errno)) << endmsg;
        }
+#else
+       /* this only affects stdio. 2048 is the maxium possible (512 the default).
+        *
+        * If we want more, we'll have to replaces the POSIX I/O interfaces with
+        * Win32 API calls (CreateFile, WriteFile, etc) which allows for 16K.
+        *
+        * see http://stackoverflow.com/questions/870173/is-there-a-limit-on-number-of-open-files-in-windows
+        * and http://bugs.mysql.com/bug.php?id=24509
+        */
+       int newmax = _setmaxstdio (2048);
+       if (newmax > 0) {
+               info << string_compose (_("Your system is configured to limit %1 to only %2 open files"), PROGRAM_NAME, newmax) << endmsg;
+       } else {
+               error << string_compose (_("Could not set system open files limit. Current limit is %1 open files"), _getmaxstdio)  << endmsg;
+       }
 #endif
 }
 
@@ -288,7 +301,7 @@ copy_configuration_files (string const & old_dir, string const & new_dir, int ol
                return -1;
        }
 
-       if (old_version == 3) {
+       if (old_version >= 3) {
 
                old_name = Glib::build_filename (old_dir, X_("recent"));
                new_name = Glib::build_filename (new_dir, X_("recent"));
@@ -426,6 +439,7 @@ ARDOUR::init (bool use_windows_vst, bool try_optimization, const char* localedir
        RouteGroup::make_property_quarks ();
         Playlist::make_property_quarks ();
         AudioPlaylist::make_property_quarks ();
+        PresentationInfo::make_property_quarks ();
 
        /* this is a useful ready to use PropertyChange that many
           things need to check. This avoids having to compose
@@ -497,6 +511,22 @@ ARDOUR::init (bool use_windows_vst, bool try_optimization, const char* localedir
 #endif
        (void) EventTypeMap::instance();
 
+       ControlProtocolManager::instance().discover_control_protocols ();
+
+       /* for each control protocol, check for a request buffer factory method
+          and if it exists, store it in the EventLoop list of such
+          methods. This allows the relevant threads to register themselves
+          with EventLoops so that signal emission can be RT-safe.
+       */
+
+       ControlProtocolManager::instance().register_request_buffer_factories ();
+       /* it would be nice if this could auto-register itself in the
+          constructor, since MidiControlUI is a singleton, but it can't be
+          created until after the engine is running. Therefore we have to
+          explicitly register it here.
+       */
+       EventLoop::register_request_buffer_factory (X_("midiUI"), MidiControlUI::request_factory);
+
         ProcessThread::init ();
        /* the + 4 is a bit of a handwave. i don't actually know
           how many more per-thread buffer sets we need above
@@ -537,8 +567,6 @@ ARDOUR::init (bool use_windows_vst, bool try_optimization, const char* localedir
 void
 ARDOUR::init_post_engine ()
 {
-       ControlProtocolManager::instance().discover_control_protocols ();
-
        XMLNode* node;
        if ((node = Config->control_protocol_state()) != 0) {
                ControlProtocolManager::instance().set_state (*node, Stateful::loading_state_version);
@@ -577,31 +605,6 @@ ARDOUR::cleanup ()
        return;
 }
 
-void
-ARDOUR::find_bindings_files (map<string,string>& files)
-{
-       vector<std::string> found;
-       Searchpath spath = ardour_config_search_path();
-
-       if (getenv ("ARDOUR_SAE")) {
-               find_files_matching_pattern (found, spath, "*SAE-*.bindings");
-       } else {
-               find_files_matching_pattern (found, spath, "*.bindings");
-       }
-
-       if (found.empty()) {
-               return;
-       }
-
-       for (vector<std::string>::iterator x = found.begin(); x != found.end(); ++x) {
-               std::string path(*x);
-               pair<string,string> namepath;
-               namepath.second = path;
-               namepath.first = PBD::basename_nosuffix (path);
-               files.insert (namepath);
-       }
-}
-
 bool
 ARDOUR::no_auto_connect()
 {