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
This commit is contained in:
Tim Mayberry
2007-06-27 12:12:18 +00:00
parent 1b77a35353
commit 0abcfb16ba
17 changed files with 379 additions and 90 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 = "" );

View File

@@ -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 ();

View File

@@ -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

View File

@@ -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

View File

@@ -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);

View File

@@ -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;
for (vector<sys::path>::iterator i = cp_modules.begin(); i != cp_modules.end(); ++i) {
control_protocol_discover ((*i).to_string());
}
delete found;
}
int

View File

@@ -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

View File

@@ -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

View File

@@ -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 = "")
{

View File

@@ -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)
{

View File

@@ -28,6 +28,7 @@ enumwriter.cc
dmalloc.cc
error.cc
filesystem.cc
file_utils.cc
fpu.cc
id.cc
mountpoint.cc

132
libs/pbd/file_utils.cc Normal file
View File

@@ -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

99
libs/pbd/pbd/file_utils.h Normal file
View File

@@ -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

View File

@@ -53,13 +53,25 @@ 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.

View File

@@ -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)