From 8fd752b7e8c56c848e05bdcacce46f3abe3456aa Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 6 Jan 2011 18:37:13 +0000 Subject: [PATCH] more fixes for EPA madness git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@8467 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/engine_dialog.cc | 13 ++++ gtk2_ardour/export_range_markers_dialog.cc | 1 - gtk2_ardour/main.cc | 2 +- libs/ardour/audioengine.cc | 2 + libs/pbd/epa.cc | 71 ++++++++++++++++++---- libs/pbd/pbd/epa.h | 27 ++++---- 6 files changed, 90 insertions(+), 26 deletions(-) diff --git a/gtk2_ardour/engine_dialog.cc b/gtk2_ardour/engine_dialog.cc index b84b163b7f..d6ec7f2a12 100644 --- a/gtk2_ardour/engine_dialog.cc +++ b/gtk2_ardour/engine_dialog.cc @@ -6,6 +6,7 @@ #include #include #include +#include #ifdef __APPLE__ #include @@ -560,6 +561,18 @@ EngineControl::build_command_line (vector& cmd) bool EngineControl::engine_running () { + EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa (); + EnvironmentalProtectionAgency current_epa (true); /* will restore settings when we leave scope */ + + /* revert all environment settings back to whatever they were when ardour started + */ + + cerr << "STarting JACK, global EPA = " << global_epa << endl; + + if (global_epa) { + global_epa->restore (); + } + jack_status_t status; jack_client_t* c = jack_client_open ("ardourprobe", JackNoStartServer, &status); diff --git a/gtk2_ardour/export_range_markers_dialog.cc b/gtk2_ardour/export_range_markers_dialog.cc index 5a04b25f86..6163cab28b 100644 --- a/gtk2_ardour/export_range_markers_dialog.cc +++ b/gtk2_ardour/export_range_markers_dialog.cc @@ -111,7 +111,6 @@ string ExportRangeMarkersDialog::get_target_filepath(string path, string filename, string postfix) { string target_filepath = Glib::build_filename (path, filename + postfix); - struct stat statbuf; for (int counter=1; Glib::file_test (target_filepath, Glib::FILE_TEST_EXISTS); counter++) { // while file exists diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc index fd6e7808db..aea928e372 100644 --- a/gtk2_ardour/main.cc +++ b/gtk2_ardour/main.cc @@ -273,7 +273,7 @@ fixup_bundle_environment (int argc, char* argv[]) return; } - EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true)); + EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true, "PREBUNDLE_ENV")); Glib::ustring exec_path = argv[0]; Glib::ustring dir_path = Glib::path_get_dirname (Glib::path_get_dirname (exec_path)); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 6ceef2290a..44036733a0 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -1130,6 +1130,8 @@ AudioEngine::connect_to_jack (string client_name) /* revert all environment settings back to whatever they were when ardour started */ + cerr << "STarting JACK, global EPA = " << global_epa << endl; + if (global_epa) { global_epa->restore (); } diff --git a/libs/pbd/epa.cc b/libs/pbd/epa.cc index 8665823d77..90220a0a0f 100644 --- a/libs/pbd/epa.cc +++ b/libs/pbd/epa.cc @@ -21,6 +21,7 @@ #include #include "pbd/epa.h" +#include "pbd/strsplit.h" extern char** environ; @@ -29,8 +30,9 @@ using namespace std; EnvironmentalProtectionAgency* EnvironmentalProtectionAgency::_global_epa = 0; -EnvironmentalProtectionAgency::EnvironmentalProtectionAgency (bool arm) +EnvironmentalProtectionAgency::EnvironmentalProtectionAgency (bool arm, const std::string& envname) : _armed (arm) + , _envname (envname) { if (_armed) { save (); @@ -55,22 +57,69 @@ EnvironmentalProtectionAgency::save () { e.clear (); - for (size_t i = 0; environ[i]; ++i) { + if (!_envname.empty()) { + + /* fetch environment from named environment string + */ - string estring = environ[i]; - string::size_type equal = estring.find_first_of ('='); + cerr << "Look for " << _envname << endl; - if (equal == string::npos) { - /* say what? an environ value without = ? */ - continue; + const char* estr = getenv (_envname.c_str()); + + cerr << " result = [" << estr << ']' << endl; + + if (!estr) { + return; } + + /* parse line by line, and save into "e" + */ - string before = estring.substr (0, equal); - string after = estring.substr (equal+1); + vector lines; + split (estr, lines, '\n'); - cerr << "Save [" << before << "] = " << after << endl; + cerr << "Parsed to " << lines.size() << " lines\n"; + + for (vector::iterator i = lines.begin(); i != lines.end(); ++i) { - e.insert (pair(before,after)); + string estring = *i; + string::size_type equal = estring.find_first_of ('='); + + if (equal == string::npos) { + /* say what? an environ value without = ? */ + continue; + } + + string before = estring.substr (0, equal); + string after = estring.substr (equal+1); + + cerr << "EN:Save [" << before << "] = " << after << endl; + + e.insert (pair(before,after)); + } + + } else { + + /* fetch environment from "environ" + */ + + for (size_t i = 0; environ[i]; ++i) { + + string estring = environ[i]; + string::size_type equal = estring.find_first_of ('='); + + if (equal == string::npos) { + /* say what? an environ value without = ? */ + continue; + } + + string before = estring.substr (0, equal); + string after = estring.substr (equal+1); + + cerr << "Save [" << before << "] = " << after << endl; + + e.insert (pair(before,after)); + } } } void diff --git a/libs/pbd/pbd/epa.h b/libs/pbd/pbd/epa.h index b2708fbd4c..ffcd78504a 100644 --- a/libs/pbd/pbd/epa.h +++ b/libs/pbd/pbd/epa.h @@ -27,20 +27,21 @@ namespace PBD { class EnvironmentalProtectionAgency { public: - EnvironmentalProtectionAgency (bool arm=true); - ~EnvironmentalProtectionAgency (); - - void arm (); - void save (); - void restore () const; - - static EnvironmentalProtectionAgency* get_global_epa () { return _global_epa; } - static void set_global_epa (EnvironmentalProtectionAgency* epa) { _global_epa = epa; } - + EnvironmentalProtectionAgency (bool arm = true, const std::string& envname = std::string()); + ~EnvironmentalProtectionAgency (); + + void arm (); + void save (); + void restore () const; + + static EnvironmentalProtectionAgency* get_global_epa () { return _global_epa; } + static void set_global_epa (EnvironmentalProtectionAgency* epa) { _global_epa = epa; } + private: - bool _armed; - std::map e; - static EnvironmentalProtectionAgency* _global_epa; + bool _armed; + std::string _envname; + std::map e; + static EnvironmentalProtectionAgency* _global_epa; }; }