use Glib::build_filename() more widely

git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@3347 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2008-05-14 02:26:03 +00:00
parent 49f73b561b
commit 371ca6da98
15 changed files with 149 additions and 114 deletions

View file

@ -20,6 +20,8 @@
#include <unistd.h>
#include <cstdio> /* for snprintf, grrr */
#include <glibmm/miscutils.h>
#include <pbd/failed_constructor.h>
#include <pbd/xml++.h>
#include <pbd/error.h>
@ -125,8 +127,7 @@ UIConfiguration::save_state()
XMLTree tree;
string rcfile;
rcfile = get_user_ardour_path ();
rcfile += "ardour2_ui.conf";
rcfile = Glib::build_filename (get_user_ardour_path (), "ardour2_ui.conf");
if (rcfile.length()) {
tree.set_root (&get_state());

View file

@ -395,6 +395,7 @@ class IO : public PBD::StatefulDestructible
int create_ports (const XMLNode&);
int make_connections (const XMLNode&);
Connection *find_possible_connection(const string &desired_name, const string &default_name, const string &connection_type_name);
void setup_peak_meters ();
void meter ();

View file

@ -22,6 +22,7 @@
#include <libxml/uri.h>
#include <lrdf.h>
#include <glibmm/miscutils.h>
#include <pbd/compose.h>
@ -37,11 +38,14 @@ static const char* TAG = "http://ardour.org/ontology/Tag";
AudioLibrary::AudioLibrary ()
{
src = "file:" + get_user_ardour_path() + "sfdb";
/* XXX URL - '/' is always the separator */
src = "file:" + get_user_ardour_path() + "/sfdb";
// workaround for possible bug in raptor that crashes when saving to a
// non-existant file.
touch_file(get_user_ardour_path() + "sfdb");
touch_file(Glib::build_filename (get_user_ardour_path(), "sfdb"));
lrdf_read_file(src.c_str());
}

View file

@ -22,6 +22,7 @@
#include <glib.h>
#include <glib/gstdio.h> /* for g_stat() */
#include <glibmm/miscutils.h>
#include <pbd/failed_constructor.h>
#include <pbd/xml++.h>
@ -155,8 +156,7 @@ Configuration::save_state()
XMLTree tree;
string rcfile;
rcfile = get_user_ardour_path ();
rcfile += "ardour.rc";
rcfile = Glib::build_filename (get_user_ardour_path (), "ardour.rc");
if (rcfile.length()) {
tree.set_root (&get_state());

View file

@ -493,11 +493,12 @@ 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;
}
@ -543,6 +544,8 @@ ARDOUR::find_bindings_files (map<string,string>& files)
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 ();

View file

@ -1782,6 +1782,83 @@ IO::ports_became_legal ()
return ret;
}
Connection *
IO::find_possible_connection(const string &desired_name, const string &default_name, const string &connection_type_name) {
Connection* c = _session.connection_by_name (desired_name);
if (!c) {
int connection_number, i, n, p, mask;
string possible_name;
bool stereo = false;
error << string_compose(_("Unknown connection \"%1\" listed for %2 of %3"), desired_name, connection_type_name, _name)
<< endmsg;
// find numeric suffix of desired name
connection_number = 0;
p = 1;
i = desired_name.length();
while (n = desired_name[--i], isdigit(n) && i) {
connection_number += (n-'0') * p;
p *= 10;
}
if (i && n == '+') {
// see if it's a stereo connection e.g. "in 3+4"
int left_connection_number = 0;
p = 1;
info << "assuming port " << desired_name << " is stereo" << endmsg;
while (n = desired_name[--i], isdigit(n) && i) {
left_connection_number += (n-'0') * p;
p *= 10;
}
if (left_connection_number > 0 && left_connection_number + 1 == connection_number) {
connection_number--;
stereo = true;
}
}
// make 0-based
connection_number--;
// cerr << "desired_name = " << desired_name << ", connection_number = " << connection_number << endl;
// find highest set bit
mask = 1;
while ((mask <= connection_number) && (mask <<= 1)) {
}
// "wrap" connection number into largest possible power of 2
// that works...
while (mask && !c) {
if (connection_number & mask) {
connection_number &= ~mask;
stringstream s;
s << default_name << " " << connection_number + 1;
if (stereo) {
s << "+" << connection_number + 2;
}
possible_name = s.str();
c = _session.connection_by_name (possible_name);
}
mask >>= 1;
}
if (c) {
info << string_compose (_("Connection %1 was not available - \"%2\" used instead"), desired_name, possible_name)
<< endmsg;
} else {
error << string_compose(_("No %1 connections available as a replacement"), connection_type_name)
<< endmsg;
}
}
return c;
}
int
IO::create_ports (const XMLNode& node)
{
@ -1791,19 +1868,10 @@ IO::create_ports (const XMLNode& node)
if ((prop = node.property ("input-connection")) != 0) {
Connection* c = _session.connection_by_name (prop->value());
Connection* c = find_possible_connection(prop->value(), _("in"), _("input"));
if (c == 0) {
error << string_compose(_("Unknown connection \"%1\" listed for input of %2"), prop->value(), _name) << endmsg;
if ((c = _session.connection_by_name (_("in 1"))) == 0) {
error << _("No input connections available as a replacement")
<< endmsg;
return -1;
} else {
info << string_compose (_("Connection %1 was not available - \"in 1\" used instead"), prop->value())
<< endmsg;
}
return -1;
}
num_inputs = c->nports();
@ -1814,19 +1882,10 @@ IO::create_ports (const XMLNode& node)
}
if ((prop = node.property ("output-connection")) != 0) {
Connection* c = _session.connection_by_name (prop->value());
Connection* c = find_possible_connection(prop->value(), _("out"), _("output"));
if (c == 0) {
error << string_compose(_("Unknown connection \"%1\" listed for output of %2"), prop->value(), _name) << endmsg;
if ((c = _session.connection_by_name (_("out 1"))) == 0) {
error << _("No output connections available as a replacement")
<< endmsg;
return -1;
} else {
info << string_compose (_("Connection %1 was not available - \"out 1\" used instead"), prop->value())
<< endmsg;
}
return -1;
}
num_outputs = c->nports ();
@ -1857,19 +1916,10 @@ IO::make_connections (const XMLNode& node)
const XMLProperty* prop;
if ((prop = node.property ("input-connection")) != 0) {
Connection* c = _session.connection_by_name (prop->value());
Connection* c = find_possible_connection (prop->value(), _("in"), _("input"));
if (c == 0) {
error << string_compose(_("Unknown connection \"%1\" listed for input of %2"), prop->value(), _name) << endmsg;
if ((c = _session.connection_by_name (_("in 1"))) == 0) {
error << _("No input connections available as a replacement")
<< endmsg;
return -1;
} else {
info << string_compose (_("Connection %1 was not available - \"in 1\" used instead"), prop->value())
<< endmsg;
}
return -1;
}
use_input_connection (*c, this);
@ -1882,19 +1932,10 @@ IO::make_connections (const XMLNode& node)
}
if ((prop = node.property ("output-connection")) != 0) {
Connection* c = _session.connection_by_name (prop->value());
Connection* c = find_possible_connection (prop->value(), _("out"), _("output"));
if (c == 0) {
error << string_compose(_("Unknown connection \"%1\" listed for output of %2"), prop->value(), _name) << endmsg;
if ((c = _session.connection_by_name (_("out 1"))) == 0) {
error << _("No output connections available as a replacement")
<< endmsg;
return -1;
} else {
info << string_compose (_("Connection %1 was not available - \"out 1\" used instead"), prop->value())
<< endmsg;
}
return -1;
}
use_output_connection (*c, this);

View file

@ -28,6 +28,8 @@
#include <unistd.h>
#include <fcntl.h>
#include <glibmm/miscutils.h>
#include <pbd/pthread_utils.h>
#include <ardour/osc.h>
@ -103,18 +105,17 @@ OSC::start ()
cerr << "OSC @ " << get_server_url () << endl;
_osc_url_file = get_user_ardour_path () + "/osc_url";
ofstream urlfile;
urlfile.open(_osc_url_file.c_str(),ios::trunc);
if ( urlfile )
{
urlfile << get_server_url () << endl;
urlfile.close();
}
else
{
cerr << "Couldn't write '" << _osc_url_file << "'" <<endl;
}
_osc_url_file = Glib::build_filename (get_user_ardour_path (), "osc_url");
ofstream urlfile;
urlfile.open(_osc_url_file.c_str(),ios::trunc);
if (urlfile) {
urlfile << get_server_url () << endl;
urlfile.close();
} else {
cerr << "Couldn't write '" << _osc_url_file << "'" <<endl;
}
register_callbacks();

View file

@ -30,6 +30,8 @@
#include <string.h>
#endif // VST_SUPPORT
#include <glibmm/miscutils.h>
#include <pbd/pathscanner.h>
#include <ardour/ladspa.h>
@ -500,10 +502,7 @@ PluginManager::is_a_favorite_plugin (const PluginInfoPtr& pi)
void
PluginManager::save_favorites ()
{
Glib::ustring path = get_user_ardour_path ();
path += '/';
path += "favorite_plugins";
Glib::ustring path = Glib::build_filename (get_user_ardour_path (), "favorite_plugins");
ofstream ofs;
ofs.open (path.c_str(), ios_base::openmode (ios::out|ios::trunc));
@ -537,9 +536,7 @@ PluginManager::save_favorites ()
void
PluginManager::load_favorites ()
{
Glib::ustring path = get_user_ardour_path ();
path += '/';
path += "favorite_plugins";
Glib::ustring path = Glib::build_filename (get_user_ardour_path (),"favorite_plugins");
ifstream ifs (path.c_str());

View file

@ -22,7 +22,11 @@
#include <unistd.h>
#include <fstream>
#include <algorithm>
#include <glibmm/miscutils.h>
#include <pbd/error.h>
#include <ardour/configuration.h>
#include <ardour/recent_sessions.h>
#include <ardour/utils.h>
@ -35,8 +39,7 @@ using namespace PBD;
int
ARDOUR::read_recent_sessions (RecentSessions& rs)
{
string path = get_user_ardour_path();
path += "/recent";
Glib::ustring path = Glib::build_filename (get_user_ardour_path(), "recent");
ifstream recent (path.c_str());
@ -78,8 +81,7 @@ ARDOUR::read_recent_sessions (RecentSessions& rs)
int
ARDOUR::write_recent_sessions (RecentSessions& rs)
{
string path = get_user_ardour_path();
path += "/recent";
Glib::ustring path = Glib::build_filename (get_user_ardour_path(), "recent");
ofstream recent (path.c_str());

View file

@ -1253,6 +1253,12 @@ Session::handle_locations_changed (Locations::LocationList& locations)
set_loop = true;
}
if (location->is_start()) {
start_location = location;
}
if (location->is_end()) {
end_location = location;
}
}
if (!set_loop) {

View file

@ -68,7 +68,7 @@ Session::memento_command_factory(XMLNode *n)
before = new XMLNode(*n->children().front());
after = new XMLNode(*n->children().back());
child = before;
}
}
if (!child)
{

View file

@ -2064,44 +2064,31 @@ Session::sound_dir (bool with_path) const
string
Session::peak_dir () const
{
string res = _path;
res += peak_dir_name;
res += '/';
return res;
return Glib::build_filename (_path, peak_dir_name);
}
string
Session::automation_dir () const
{
string res = _path;
res += "automation/";
return res;
return Glib::build_filename (_path, "automation");
}
string
Session::analysis_dir () const
{
string res = _path;
res += "analysis/";
return res;
return Glib::build_filename (_path, "analysis");
}
string
Session::template_dir ()
{
string path = get_user_ardour_path();
path += "templates/";
return path;
return Glib::build_filename (get_user_ardour_path(), "templates");
}
string
Session::export_dir () const
{
string res = _path;
res += export_dir_name;
res += '/';
return res;
return Glib::build_filename (_path, export_dir_name);
}
string
@ -2515,8 +2502,7 @@ Session::get_template_list (list<string> &template_names)
int
Session::read_favorite_dirs (FavoriteDirs & favs)
{
string path = get_user_ardour_path();
path += "/favorite_dirs";
Glib::ustring path = Glib::build_filename (get_user_ardour_path(), "favorite_dirs");
ifstream fav (path.c_str());
@ -2550,8 +2536,7 @@ Session::read_favorite_dirs (FavoriteDirs & favs)
int
Session::write_favorite_dirs (FavoriteDirs & favs)
{
string path = get_user_ardour_path();
path += "/favorite_dirs";
Glib::ustring path = Glib::build_filename (get_user_ardour_path(), "favorite_dirs");
ofstream fav (path.c_str());

View file

@ -155,12 +155,9 @@ VSTPlugin::get_state()
/* save it to a file */
string path;
Glib::ustring path = Glib::build_ustring (get_user_ardour_path (), "vst");
struct stat sbuf;
path = get_user_ardour_path ();
path += "vst";
if (stat (path.c_str(), &sbuf)) {
if (errno == ENOENT) {
if (g_mkdir_with_parents (path.c_str(), 0600)) {
@ -183,7 +180,7 @@ VSTPlugin::get_state()
return *root;
}
path += "something";
path = Glib::build_filename (path, "something");
/* store information */

View file

@ -44,15 +44,11 @@ class FunctorCommand : public Command
typedef typename FunctorMap::iterator FunctorMapIterator;
public:
FunctorCommand(
std::string functor,
obj_type object,
arg_type b,
arg_type a
) : functor_name(functor),
object(object),
before(b),
after(a)
FunctorCommand(std::string functor, obj_type& object, arg_type b, arg_type a)
: functor_name(functor)
, object(object)
, before(b)
, after(a)
{
method = find_functor(functor);
@ -76,6 +72,7 @@ class FunctorCommand : public Command
std::stringstream ss;
XMLNode *node = new XMLNode("FunctorCommand");
node->add_property("type_name", typeid(obj_type).name());
node->add_property("functor", functor_name);
ss << before;
node->add_property("before", ss.str());

View file

@ -20,7 +20,7 @@ vamp-sdk/RealTime.cpp
""")
Import('env install_prefix libraries')
vampsdk = env.Copy()
vampsdk = env.Clone()
vampsdk.Merge ([libraries['fftw3'], libraries['fftw3f']])