when renaming redirects, scan all routes AND sends AND port inserts for the name...
[ardour.git] / libs / ardour / globals.cc
index fc0b0748344c7d5dfb357a42dc3f3fcb0f067952..65740d5a5d0ec8430901f6b3af3bff21eaeb1baa 100644 (file)
 #include <fst.h>
 #endif
 
+#ifdef HAVE_AUDIOUNITS
+#include <ardour/audio_unit.h>
+#endif
+
 #ifdef __SSE__
 #include <xmmintrin.h>
 #endif
 
 #include <glibmm/fileutils.h>
+#include <glibmm/miscutils.h>
 
 #include <lrdf.h>
 
@@ -43,6 +48,7 @@
 #include <pbd/id.h>
 #include <pbd/strsplit.h>
 #include <pbd/fpu.h>
+#include <pbd/pathscanner.h>
 
 #include <midi++/port.h>
 #include <midi++/manager.h>
@@ -84,9 +90,9 @@ using namespace ARDOUR;
 using namespace std;
 using namespace PBD;
 
-MIDI::Port *default_mmc_port = 0;
-MIDI::Port *default_mtc_port = 0;
-MIDI::Port *default_midi_port = 0;
+MIDI::Port *ARDOUR::default_mmc_port = 0;
+MIDI::Port *ARDOUR::default_mtc_port = 0;
+MIDI::Port *ARDOUR::default_midi_port = 0;
 
 Change ARDOUR::StartChanged = ARDOUR::new_change ();
 Change ARDOUR::LengthChanged = ARDOUR::new_change ();
@@ -94,6 +100,8 @@ Change ARDOUR::PositionChanged = ARDOUR::new_change ();
 Change ARDOUR::NameChanged = ARDOUR::new_change ();
 Change ARDOUR::BoundsChanged = Change (0); // see init(), below
 
+sigc::signal<void,std::string> ARDOUR::BootMessage;
+
 #ifdef HAVE_LIBLO
 static int
 setup_osc ()
@@ -105,21 +113,25 @@ setup_osc ()
        osc = new OSC (Config->get_osc_port());
        
        if (Config->get_use_osc ()) {
+               BootMessage (_("Starting OSC"));
                return osc->start ();
        } else {
                return 0;
        }
 }
+
 #endif
 
-static int 
-setup_midi ()
+int
+ARDOUR::setup_midi ()
 {
        if (Config->midi_ports.size() == 0) {
                warning << _("no MIDI ports specified: no MMC or MTC control possible") << endmsg;
                return 0;
        }
 
+       BootMessage (_("Configuring MIDI ports"));
+
        for (std::map<string,XMLNode>::iterator i = Config->midi_ports.begin(); i != Config->midi_ports.end(); ++i) {
                MIDI::Manager::instance()->add_port (i->second);
        }
@@ -175,16 +187,17 @@ setup_midi ()
                        << endmsg;
                return 0;
        } 
 
        if (default_mtc_port == 0) {
                warning << string_compose (_("No MTC support (MIDI port \"%1\" not available)"), Config->get_mtc_port_name()) 
                        << endmsg;
-       }
+       } 
 
        if (default_midi_port == 0) {
                warning << string_compose (_("No MIDI parameter support (MIDI port \"%1\" not available)"), Config->get_midi_port_name()) 
                        << endmsg;
-       }
+       } 
 
        return 0;
 }
@@ -294,6 +307,8 @@ ARDOUR::init (bool use_vst, bool try_optimization)
        lrdf_init();
        Library = new AudioLibrary;
 
+       BootMessage (_("Loading configuration"));
+
        Config = new Configuration;
 
        if (Config->load_state ()) {
@@ -315,11 +330,15 @@ ARDOUR::init (bool use_vst, bool try_optimization)
 #endif
 
 #ifdef VST_SUPPORT
-       if (Config->get_use_vst() && fst_init ()) {
-               return -1;
+       if (Config->get_use_vst() && fst_init (0)) {
+               return -1;
        }
 #endif
-       
+
+#ifdef HAVE_AUDIOUNITS
+       AUPluginInfo::load_cached_info ();
+#endif
+
        /* Make VAMP look in our library ahead of anything else */
 
        char *p = getenv ("VAMP_PATH");
@@ -359,6 +378,9 @@ ARDOUR::cleanup ()
        delete Library;
        lrdf_cleanup ();
        delete &ControlProtocolManager::instance();
+#ifdef VST_SUPPORT
+       fst_exit ();
+#endif
        return 0;
 }
 
@@ -366,11 +388,7 @@ ARDOUR::cleanup ()
 microseconds_t
 ARDOUR::get_microseconds ()
 {
-       /* XXX need JACK to export its functionality */
-
-       struct timeval now;
-       gettimeofday (&now, 0);
-       return now.tv_sec * 1000000ULL + now.tv_usec;
+       return (microseconds_t) jack_get_time ();
 }
 
 ARDOUR::Change
@@ -404,13 +422,13 @@ string
 ARDOUR::get_user_ardour_path ()
 {
        string path;
-       char* envvar;
-       
-       if ((envvar = getenv ("HOME")) == 0 || strlen (envvar) == 0) {
+               
+       path = Glib::get_home_dir();
+
+       if (path.empty()) {
                return "/";
        }
-               
-       path = envvar;
+
        path += "/.ardour2/";
 
        /* create it if necessary */
@@ -484,30 +502,85 @@ find_file (string name, string dir, string subdir = "")
        path = get_user_ardour_path();
                
        if (subdir.length()) {
-               path += subdir + "/";
+               path = Glib::build_filename (path, subdir);
        }
                
-       path += name;
-       if (access (path.c_str(), R_OK) == 0) {
+       path = Glib::build_filename (path, name);
+
+       if (Glib::file_test (path.c_str(), Glib::FILE_TEST_EXISTS)) {
                return path;
        }
 
-       /* 3rd attempt: dir/... */
-       
-       path = dir;
-       path += "/ardour2/";
-       
-       if (subdir.length()) {
-               path += subdir + "/";
+       if (dir.length()) {
+               /* 3rd attempt: dir/... */
+               
+               path = dir;
+               path += "/ardour2/";
+               
+               if (subdir.length()) {
+                       path += subdir + "/";
+               }
+               
+               path += name;
+               
+               if (access (path.c_str(), R_OK) == 0) {
+                       return path;
+               }
        }
+
+       return "";
+}
+
+static bool sae_binding_filter (const string& str, void* arg)
+{
+       /* Not a dotfile, has a prefix before a period, suffix is ".bindings" and contains -sae- */
        
-       path += name;
+       return str[0] != '.' && str.length() > 13 && str.find (".bindings") == (str.length() - 9)
+               && str.find ("SAE-") != string::npos;
+}
+
+static bool binding_filter (const string& str, void* arg)
+{
+       /* Not a dotfile, has a prefix before a period, suffix is ".bindings" */
        
-       if (access (path.c_str(), R_OK) == 0) {
-               return path;
+       return str[0] != '.' && str.length() > 9 && str.find (".bindings") == (str.length() - 9);
+}
+
+void
+ARDOUR::find_bindings_files (map<string,string>& files)
+{
+       PathScanner scanner;
+       vector<string*> *found;
+       string full_path;
+       
+       /* XXX building path, so separators are fixed */
+
+       full_path = get_user_ardour_path ();
+       full_path += ':';
+       full_path = get_system_data_path ();
+
+       if (getenv ("ARDOUR_SAE")) {
+               found = scanner (full_path, sae_binding_filter, 0, false, true);
+       } else {
+               found = scanner (full_path, binding_filter, 0, false, true);
        }
 
-       return "";
+       if (!found) {
+               return;
+       }
+       
+       for (vector<string*>::iterator x = found->begin(); x != found->end(); ++x) {
+               string path = *(*x);
+               pair<string,string> namepath;
+               namepath.second = path;
+               path = Glib::path_get_basename (path);
+               namepath.first = path.substr (0, path.find_first_of ('.'));
+               
+               files.insert (namepath);
+               delete *x;
+       }
+       
+       delete found;
 }
 
 string