summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2007-06-27 12:12:18 +0000
committerTim Mayberry <mojofunk@gmail.com>2007-06-27 12:12:18 +0000
commit0abcfb16ba203be43fcb2d2cd0b740da85679e7a (patch)
treea3960e9ff490dab3ff5a239acc561ae21ab23a64
parent1b77a3535304c25a49686886054db148442b1032 (diff)
Replace code for finding ControlProtocols/Surface plugins with a portable equivalent.
Remove Session::control_protocol_path and the supporting non-portable Session::suffixed_search_path from Session. Add ARDOUR::control_protocol_search_path which is used in place of Session::control_protocol_path Replace ARDOUR::get_system_module_path with ARDOUR::system_module_directory which is used by ARDOUR::control_protocol_search_path Export ARDOUR_SURFACES_PATH in gtk2_ardour/ardev_common.sh which is returned by ARDOUR::control_protocol_search_path if defined. This means the control surfaces in the libs/surfaces/* directories can now be used without installing them. Add pbd/file_utils.h/cc containing functions for finding files matching a certain pattern Update documentation in SearchPath and add another constructor that takes a sys::path git-svn-id: svn://localhost/ardour2/trunk@2049 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--gtk2_ardour/ardev_common.sh.in1
-rw-r--r--libs/ardour/SConscript1
-rw-r--r--libs/ardour/ardour/ardour.h1
-rw-r--r--libs/ardour/ardour/control_protocol_manager.h2
-rw-r--r--libs/ardour/ardour/control_protocol_search_path.h42
-rw-r--r--libs/ardour/ardour/filesystem_paths.h6
-rw-r--r--libs/ardour/ardour/session.h3
-rw-r--r--libs/ardour/control_protocol_manager.cc35
-rw-r--r--libs/ardour/control_protocol_search_path.cc52
-rw-r--r--libs/ardour/filesystem_paths.cc8
-rw-r--r--libs/ardour/globals.cc18
-rw-r--r--libs/ardour/session_state.cc41
-rw-r--r--libs/pbd/SConscript1
-rw-r--r--libs/pbd/file_utils.cc132
-rw-r--r--libs/pbd/pbd/file_utils.h99
-rw-r--r--libs/pbd/pbd/search_path.h16
-rw-r--r--libs/pbd/search_path.cc11
17 files changed, 379 insertions, 90 deletions
diff --git a/gtk2_ardour/ardev_common.sh.in b/gtk2_ardour/ardev_common.sh.in
index 235607163c..8e8f73f6b8 100644
--- a/gtk2_ardour/ardev_common.sh.in
+++ b/gtk2_ardour/ardev_common.sh.in
@@ -5,6 +5,7 @@ cd `dirname "$0"`/..
export ARDOUR_PATH=.:gtk2_ardour/icons:gtk2_ardour/pixmaps:gtk2_ardour
export GTK_PATH=libs/clearlooks
+export ARDOUR_SURFACES_PATH=libs/surfaces/frontier:libs/surfaces/generic_midi:libs/surfaces/mackie:libs/surfaces/tranzport
export LD_LIBRARY_PATH=libs/surfaces/control_protocol:libs/ardour:libs/midi++2:libs/pbd:libs/soundtouch:libs/gtkmm2ext:libs/sigc++2:libs/glibmm2:libs/gtkmm2/atk:libs/gtkmm2/pango:libs/gtkmm2/gdk:libs/gtkmm2/gtk:libs/libgnomecanvasmm:libs/libsndfile:libs/appleutility:$LD_LIBRARY_PATH
diff --git a/libs/ardour/SConscript b/libs/ardour/SConscript
index 1d66b1f6be..e2e84c386c 100644
--- a/libs/ardour/SConscript
+++ b/libs/ardour/SConscript
@@ -66,6 +66,7 @@ automation.cc
automation_event.cc
configuration.cc
control_protocol_manager.cc
+control_protocol_search_path.cc
crossfade.cc
curve.cc
cycle_timer.cc
diff --git a/libs/ardour/ardour/ardour.h b/libs/ardour/ardour/ardour.h
index c7bf7edcf8..e76c984ba4 100644
--- a/libs/ardour/ardour/ardour.h
+++ b/libs/ardour/ardour/ardour.h
@@ -53,7 +53,6 @@ namespace ARDOUR {
std::string get_user_ardour_path ();
std::string get_system_data_path ();
- std::string get_system_module_path ();
std::string find_config_file (std::string name);
std::string find_data_file (std::string name, std::string subdir = "" );
diff --git a/libs/ardour/ardour/control_protocol_manager.h b/libs/ardour/ardour/control_protocol_manager.h
index e8dc0bf22c..c61513e117 100644
--- a/libs/ardour/ardour/control_protocol_manager.h
+++ b/libs/ardour/ardour/control_protocol_manager.h
@@ -58,7 +58,7 @@ struct ControlProtocolInfo {
static ControlProtocolManager& instance() { return *_instance; }
void set_session (Session&);
- void discover_control_protocols (std::string search_path);
+ void discover_control_protocols ();
void foreach_known_protocol (sigc::slot<void,const ControlProtocolInfo*>);
void load_mandatory_protocols ();
diff --git a/libs/ardour/ardour/control_protocol_search_path.h b/libs/ardour/ardour/control_protocol_search_path.h
new file mode 100644
index 0000000000..f9a8103c0c
--- /dev/null
+++ b/libs/ardour/ardour/control_protocol_search_path.h
@@ -0,0 +1,42 @@
+/*
+ Copyright (C) 2007 Tim Mayberry
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef ARDOUR_CONTROL_PROTOCOL_SEARCH_PATH_INCLUDED
+#define ARDOUR_CONTROL_PROTOCOL_SEARCH_PATH_INCLUDED
+
+#include <pbd/search_path.h>
+
+namespace ARDOUR {
+
+ using PBD::SearchPath;
+
+ /**
+ * return a SearchPath containing directories in which to look for
+ * control surface plugins.
+ *
+ * If ARDOUR_SURFACES_PATH is defined then the SearchPath returned
+ * will contain only those directories specified in it, otherwise it will
+ * contain the user and system directories which may contain control
+ * surface plugins.
+ */
+ SearchPath control_protocol_search_path ();
+
+} // namespace ARDOUR
+
+#endif
diff --git a/libs/ardour/ardour/filesystem_paths.h b/libs/ardour/ardour/filesystem_paths.h
index dc0d2576ba..0e17327fa5 100644
--- a/libs/ardour/ardour/filesystem_paths.h
+++ b/libs/ardour/ardour/filesystem_paths.h
@@ -32,6 +32,12 @@ namespace ARDOUR {
*/
sys::path user_config_directory ();
+ /**
+ * @return the path to the directory that contains the system wide ardour
+ * modules.
+ */
+ sys::path system_module_directory ();
+
} // namespace ARDOUR
#endif
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h
index f0a175c624..9001196b60 100644
--- a/libs/ardour/ardour/session.h
+++ b/libs/ardour/ardour/session.h
@@ -261,9 +261,6 @@ class Session : public PBD::StatefulDestructible
std::string automation_dir () const;
- static string suffixed_search_path (std::string suffix, bool data);
- static string control_protocol_path ();
-
static string change_audio_path_by_name (string oldpath, string oldname, string newname, bool destructive);
static string change_midi_path_by_name (string oldpath, string oldname, string newname, bool destructive);
diff --git a/libs/ardour/control_protocol_manager.cc b/libs/ardour/control_protocol_manager.cc
index 00c05b2800..84791ab2c7 100644
--- a/libs/ardour/control_protocol_manager.cc
+++ b/libs/ardour/control_protocol_manager.cc
@@ -20,13 +20,14 @@
#include <dlfcn.h>
#include <pbd/compose.h>
+#include <pbd/file_utils.h>
#include <pbd/error.h>
-#include <pbd/pathscanner.h>
#include <control_protocol/control_protocol.h>
#include <ardour/session.h>
#include <ardour/control_protocol_manager.h>
+#include <ardour/control_protocol_search_path.h>
using namespace ARDOUR;
using namespace std;
@@ -168,15 +169,6 @@ ControlProtocolManager::teardown (ControlProtocolInfo& cpi)
return 0;
}
-static bool protocol_filter (const string& str, void *arg)
-{
- /* Not a dotfile, has a prefix before a period, suffix is "so", or "dylib" */
-
- return str[0] != '.'
- && ((str.length() > 3 && str.find (".so") == (str.length() - 3))
- || (str.length() > 6 && str.find (".dylib") == (str.length() - 6)));
-}
-
void
ControlProtocolManager::load_mandatory_protocols ()
{
@@ -193,21 +185,24 @@ ControlProtocolManager::load_mandatory_protocols ()
}
void
-ControlProtocolManager::discover_control_protocols (string path)
+ControlProtocolManager::discover_control_protocols ()
{
- vector<string *> *found;
- PathScanner scanner;
+ vector<sys::path> cp_modules;
- info << string_compose (_("looking for control protocols in %1"), path) << endmsg;
+ Glib::PatternSpec so_extension_pattern("*.so");
+ Glib::PatternSpec dylib_extension_pattern("*.dylib");
- found = scanner (path, protocol_filter, 0, false, true);
+ find_matching_files_in_search_path (control_protocol_search_path (),
+ so_extension_pattern, cp_modules);
- for (vector<string*>::iterator i = found->begin(); i != found->end(); ++i) {
- control_protocol_discover (**i);
- delete *i;
- }
+ find_matching_files_in_search_path (control_protocol_search_path (),
+ dylib_extension_pattern, cp_modules);
+
+ info << string_compose (_("looking for control protocols in %1"), control_protocol_search_path().get_string()) << endmsg;
- delete found;
+ for (vector<sys::path>::iterator i = cp_modules.begin(); i != cp_modules.end(); ++i) {
+ control_protocol_discover ((*i).to_string());
+ }
}
int
diff --git a/libs/ardour/control_protocol_search_path.cc b/libs/ardour/control_protocol_search_path.cc
new file mode 100644
index 0000000000..aac83c602a
--- /dev/null
+++ b/libs/ardour/control_protocol_search_path.cc
@@ -0,0 +1,52 @@
+/*
+ Copyright (C) 2007 Tim Mayberry
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <glibmm/miscutils.h>
+
+#include <ardour/control_protocol_search_path.h>
+#include <ardour/directory_names.h>
+#include <ardour/filesystem_paths.h>
+
+namespace {
+ const char * const surfaces_env_variable_name = "ARDOUR_SURFACES_PATH";
+} // anonymous
+
+namespace ARDOUR {
+
+SearchPath
+control_protocol_search_path ()
+{
+ bool surfaces_path_defined = false;
+ SearchPath spath_env(Glib::getenv(surfaces_env_variable_name, surfaces_path_defined));
+
+ if (surfaces_path_defined)
+ {
+ return spath_env;
+ }
+
+ SearchPath spath(user_config_directory ());
+
+ spath += system_module_directory ();
+
+ spath.add_subdirectory_to_paths(surfaces_dir_name);
+
+ return spath;
+}
+
+} // namespace ARDOUR
diff --git a/libs/ardour/filesystem_paths.cc b/libs/ardour/filesystem_paths.cc
index 55a8a9983f..465d07bddc 100644
--- a/libs/ardour/filesystem_paths.cc
+++ b/libs/ardour/filesystem_paths.cc
@@ -49,4 +49,12 @@ user_config_directory ()
return p;
}
+sys::path
+system_module_directory ()
+{
+ sys::path module_directory(MODULE_DIR);
+ module_directory /= "ardour2";
+ return module_directory;
+}
+
} // namespace ARDOUR
diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc
index 1a5e2bb5b5..c51d2339ea 100644
--- a/libs/ardour/globals.cc
+++ b/libs/ardour/globals.cc
@@ -307,7 +307,7 @@ ARDOUR::init (bool use_vst, bool try_optimization)
/* singleton - first object is "it" */
new ControlProtocolManager ();
- ControlProtocolManager::instance().discover_control_protocols (Session::control_protocol_path());
+ ControlProtocolManager::instance().discover_control_protocols ();
XMLNode* node;
if ((node = Config->control_protocol_state()) != 0) {
@@ -405,22 +405,6 @@ ARDOUR::get_system_data_path ()
return path;
}
-string
-ARDOUR::get_system_module_path ()
-{
- string path;
- char *envvar;
-
- if ((envvar = getenv ("ARDOUR_MODULE_PATH")) != 0) {
- path = envvar;
- } else {
- path += MODULE_DIR;
- path += "/ardour2/";
- }
-
- return path;
-}
-
static string
find_file (string name, string dir, string subdir = "")
{
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index b1a9b87536..446743796d 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -56,7 +56,6 @@
#include <pbd/pathscanner.h>
#include <pbd/pthread_utils.h>
#include <pbd/search_path.h>
-#include <pbd/strsplit.h>
#include <pbd/stacktrace.h>
#include <pbd/copyfile.h>
@@ -1839,46 +1838,6 @@ Session::automation_dir () const
return res;
}
-string
-Session::suffixed_search_path (string suffix, bool data)
-{
- string path;
-
- path += get_user_ardour_path();
- if (path[path.length()-1] != ':') {
- path += ':';
- }
-
- if (data) {
- path += get_system_data_path();
- } else {
- path += get_system_module_path();
- }
-
- vector<string> split_path;
-
- split (path, split_path, ':');
- path = "";
-
- for (vector<string>::iterator i = split_path.begin(); i != split_path.end(); ++i) {
- path += *i;
- path += suffix;
- path += '/';
-
- if (distance (i, split_path.end()) != 1) {
- path += ':';
- }
- }
-
- return path;
-}
-
-string
-Session::control_protocol_path ()
-{
- return suffixed_search_path (surfaces_dir_name, false);
-}
-
int
Session::load_bundles (const XMLNode& node)
{
diff --git a/libs/pbd/SConscript b/libs/pbd/SConscript
index 3dee418398..bb1f56e6c7 100644
--- a/libs/pbd/SConscript
+++ b/libs/pbd/SConscript
@@ -28,6 +28,7 @@ enumwriter.cc
dmalloc.cc
error.cc
filesystem.cc
+file_utils.cc
fpu.cc
id.cc
mountpoint.cc
diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc
new file mode 100644
index 0000000000..30ecbc0586
--- /dev/null
+++ b/libs/pbd/file_utils.cc
@@ -0,0 +1,132 @@
+/*
+ Copyright (C) 2007 Tim Mayberry
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <algorithm>
+
+#include <glibmm/fileutils.h>
+#include <glibmm/pattern.h>
+
+#include <pbd/compose.h>
+#include <pbd/file_utils.h>
+
+#include <pbd/error.h>
+
+namespace PBD {
+
+void
+get_files_in_directory (const sys::path& directory_path, vector<string>& result)
+{
+ if (!is_directory(directory_path)) return;
+
+ try
+ {
+ Glib::Dir dir(directory_path.to_string());
+ std::copy(dir.begin(), dir.end(), std::back_inserter(result));
+ }
+ catch (Glib::FileError& err)
+ {
+ warning << err.what();
+ }
+}
+
+void
+find_matching_files_in_directory (const sys::path& directory,
+ const Glib::PatternSpec& pattern,
+ vector<sys::path>& result)
+{
+ vector<string> tmp_files;
+
+ get_files_in_directory (directory, tmp_files);
+
+ for (vector<string>::iterator file_iter = tmp_files.begin();
+ file_iter != tmp_files.end();
+ ++file_iter)
+ {
+ if (!pattern.match(*file_iter)) continue;
+
+ sys::path full_path(directory);
+ full_path /= *file_iter;
+
+ result.push_back(full_path);
+ }
+}
+
+void
+find_matching_files_in_directories (const vector<sys::path>& paths,
+ const Glib::PatternSpec& pattern,
+ vector<sys::path>& result)
+{
+ for (vector<sys::path>::const_iterator path_iter = paths.begin();
+ path_iter != paths.end();
+ ++path_iter)
+ {
+ find_matching_files_in_directory (*path_iter, pattern, result);
+ }
+}
+
+void
+find_matching_files_in_search_path (const SearchPath& search_path,
+ const Glib::PatternSpec& pattern,
+ vector<sys::path>& result)
+{
+ vector<sys::path> dirs;
+ std::copy(search_path.begin(), search_path.end(), std::back_inserter(dirs));
+ find_matching_files_in_directories (dirs, pattern, result);
+}
+
+bool
+find_file_in_search_path(const SearchPath& search_path,
+ const string& filename,
+ sys::path& result)
+{
+ vector<sys::path> tmp;
+ Glib::PatternSpec tmp_pattern(filename);
+
+ find_matching_files_in_search_path (search_path, tmp_pattern, tmp);
+
+ if (tmp.size() == 0)
+ {
+ info << string_compose
+ (
+ "Found no file named %1 in search path %2",
+ filename,
+ search_path.get_string ()
+ )
+ << endmsg;
+
+ return false;
+ }
+
+ if (tmp.size() != 1)
+ {
+ info << string_compose
+ (
+ "Found more than one file matching %1 in search path %2",
+ filename,
+ search_path.get_string ()
+ )
+ << endmsg;
+ }
+
+ result = tmp.front();
+
+ return true;
+}
+
+} // namespace PBD
diff --git a/libs/pbd/pbd/file_utils.h b/libs/pbd/pbd/file_utils.h
new file mode 100644
index 0000000000..a9832ce720
--- /dev/null
+++ b/libs/pbd/pbd/file_utils.h
@@ -0,0 +1,99 @@
+/*
+ Copyright (C) 2007 Tim Mayberry
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef PBD_FILE_UTILS_INCLUDED
+#define PBD_FILE_UTILS_INCLUDED
+
+#include <string>
+#include <vector>
+
+#include <glibmm/pattern.h>
+
+#include <pbd/search_path.h>
+
+namespace PBD {
+
+using std::string;
+using std::vector;
+
+/**
+ * Get a list of files in a directory.
+ * @note You must join path with result to get the absolute path
+ * to the file.
+ *
+ * @param path An Absolute path to a directory
+ * @param result A vector of filenames.
+ */
+void
+get_files_in_directory (const sys::path& path,
+ vector<string>& result);
+
+/**
+ * Takes a directory path and returns all the files in the directory
+ * matching a particular pattern.
+ *
+ * @param directory A directory path
+ * @param pattern A Glib::PatternSpec used to match the files.
+ * @param result A vector in which to place the resulting matches.
+ */
+void
+find_matching_files_in_directory (const sys::path& directory,
+ const Glib::PatternSpec& pattern,
+ vector<sys::path>& result);
+
+/**
+ * Takes a number of directory paths and returns all the files matching
+ * a particular pattern.
+ *
+ * @param paths A vector containing the Absolute paths
+ * @param pattern A Glib::PatternSpec used to match the files
+ * @param result A vector in which to place the resulting matches.
+ */
+void
+find_matching_files_in_directories (const vector<sys::path>& directory_paths,
+ const Glib::PatternSpec& pattern,
+ vector<sys::path>& result);
+
+/**
+ * Takes a SearchPath and puts a list of all the files in the search path
+ * that match pattern into the result vector.
+ *
+ * @param search_path A SearchPath
+ * @param pattern A Glib::PatternSpec used to match the files
+ * @param result A vector in which to place the resulting matches.
+ */
+void
+find_matching_files_in_search_path (const SearchPath& search_path,
+ const Glib::PatternSpec& pattern,
+ vector<sys::path>& result);
+
+/**
+ * Takes a search path and a file name and place the full path
+ * to that file in result if it is found within the search path.
+ *
+ * @return true If file is found within the search path.
+ */
+bool
+find_file_in_search_path (const SearchPath& search_path,
+ const string& filename,
+ sys::path& result);
+
+} // namespace PBD
+
+#endif
diff --git a/libs/pbd/pbd/search_path.h b/libs/pbd/pbd/search_path.h
index 18f05ef014..e51d5de4ad 100644
--- a/libs/pbd/pbd/search_path.h
+++ b/libs/pbd/pbd/search_path.h
@@ -53,14 +53,26 @@ public:
SearchPath ();
/**
- * Initialize SearchPath from a string each path may or may not
- * exist.
+ * Initialize SearchPath from a string where the string contains
+ * one or more absolute paths to directories which are delimited
+ * by a path separation character. The path delimeter is a
+ * colon(:) on unix and a semi-colon(;) on windows.
+ *
+ * Each path contained in the search path may or may not resolve to
+ * an existing directory in the filesystem.
*
* @param search_path A path string.
*/
SearchPath (const string& search_path);
/**
+ * Initialize SearchPath from a sys::path.
+ *
+ * @param directory_path A directory path.
+ */
+ SearchPath (const sys::path& directory_path);
+
+ /**
* Initialize SearchPath from a vector of paths that may or may
* not exist.
*
diff --git a/libs/pbd/search_path.cc b/libs/pbd/search_path.cc
index 146fd7eaf0..b3590ba7bd 100644
--- a/libs/pbd/search_path.cc
+++ b/libs/pbd/search_path.cc
@@ -42,14 +42,15 @@ SearchPath::SearchPath (const string& path)
{
vector<sys::path> tmp;
- if(!tokenize ( path, string(path_delimiter), std::back_inserter (tmp)))
+ if(tokenize (path, string(path_delimiter), std::back_inserter (tmp)))
{
- // log warning(info perhaps?) that the path is empty
- warning << "SearchPath contains no tokens" << endmsg;
-
+ add_directories (tmp);
}
+}
- add_directories (tmp);
+SearchPath::SearchPath (const sys::path& directory_path)
+{
+ add_directory (directory_path);
}
SearchPath::SearchPath (const vector<sys::path>& paths)