X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsession_configuration.cc;h=b8814711f376a856e6fea8df430cf9ceb8a89bbe;hb=b6c3e5537269e53bb145300e7724e8b89dfb74d6;hp=498e91ea200c7c3300ec27d41674170d43e68478;hpb=29e8fe16987548d44b6376a38c81da7737efde28;p=ardour.git diff --git a/libs/ardour/session_configuration.cc b/libs/ardour/session_configuration.cc index 498e91ea20..b8814711f3 100644 --- a/libs/ardour/session_configuration.cc +++ b/libs/ardour/session_configuration.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2009 Paul Davis + Copyright (C) 2009 Paul Davis 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 @@ -17,19 +17,29 @@ */ +#include +#include "pbd/gstdio_compat.h" +#include /* for build_filename() */ + +#include "pbd/error.h" +#include "pbd/file_utils.h" +#include "pbd/locale_guard.h" +#include "pbd/pathexpand.h" + #include "ardour/types.h" -#include "ardour/utils.h" +#include "ardour/filesystem_paths.h" #include "ardour/session_configuration.h" -#include "ardour/ardour.h" -#include "i18n.h" +#include "ardour/utils.h" +#include "pbd/i18n.h" using namespace ARDOUR; +using namespace PBD; SessionConfiguration::SessionConfiguration () : /* construct variables */ #undef CONFIG_VARIABLE -#undef CONFIG_VARIABLE_SPECIAL +#undef CONFIG_VARIABLE_SPECIAL #define CONFIG_VARIABLE(Type,var,name,value) var (name,value), #define CONFIG_VARIABLE_SPECIAL(Type,var,name,value,mutator) var (name,value,mutator), #include "ardour/session_configuration_vars.h" @@ -37,14 +47,14 @@ SessionConfiguration::SessionConfiguration () #undef CONFIG_VARIABLE_SPECIAL foo (0) { - + } XMLNode& SessionConfiguration::get_state () { XMLNode* root; - LocaleGuard lg (X_("POSIX")); + LocaleGuard lg; root = new XMLNode ("Ardour"); root->add_child_nocopy (get_variables ()); @@ -57,26 +67,26 @@ XMLNode& SessionConfiguration::get_variables () { XMLNode* node; - LocaleGuard lg (X_("POSIX")); + LocaleGuard lg; node = new XMLNode ("Config"); #undef CONFIG_VARIABLE -#undef CONFIG_VARIABLE_SPECIAL +#undef CONFIG_VARIABLE_SPECIAL #define CONFIG_VARIABLE(type,var,Name,value) \ var.add_to_node (*node); #define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \ var.add_to_node (*node); #include "ardour/session_configuration_vars.h" #undef CONFIG_VARIABLE -#undef CONFIG_VARIABLE_SPECIAL +#undef CONFIG_VARIABLE_SPECIAL return *node; } int -SessionConfiguration::set_state (XMLNode const& root) +SessionConfiguration::set_state (XMLNode const& root, int /*version*/) { if (root.name() != "Ardour") { return -1; @@ -95,7 +105,7 @@ void SessionConfiguration::set_variables (const XMLNode& node) { #undef CONFIG_VARIABLE -#undef CONFIG_VARIABLE_SPECIAL +#undef CONFIG_VARIABLE_SPECIAL #define CONFIG_VARIABLE(type,var,name,value) \ if (var.set_from_node (node)) { \ ParameterChanged (name); \ @@ -108,16 +118,80 @@ SessionConfiguration::set_variables (const XMLNode& node) #include "ardour/session_configuration_vars.h" #undef CONFIG_VARIABLE #undef CONFIG_VARIABLE_SPECIAL - + } void -SessionConfiguration::map_parameters (sigc::slot theSlot) +SessionConfiguration::map_parameters (boost::function& functor) { #undef CONFIG_VARIABLE -#undef CONFIG_VARIABLE_SPECIAL -#define CONFIG_VARIABLE(type,var,name,value) theSlot (name); -#define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) theSlot (name); +#undef CONFIG_VARIABLE_SPECIAL +#define CONFIG_VARIABLE(type,var,name,value) functor (name); +#define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) functor (name); #include "ardour/session_configuration_vars.h" #undef CONFIG_VARIABLE -#undef CONFIG_VARIABLE_SPECIAL +#undef CONFIG_VARIABLE_SPECIAL +} + + +bool +SessionConfiguration::load_state () +{ + std::string rcfile; + GStatBuf statbuf; + if (find_file (ardour_config_search_path(), "session.rc", rcfile)) { + if (g_stat (rcfile.c_str(), &statbuf)) { + return false; + } + if (statbuf.st_size == 0) { + return false; + } + XMLTree tree; + if (!tree.read (rcfile.c_str())) { + error << string_compose(_("%1: cannot part default session options \"%2\""), PROGRAM_NAME, rcfile) << endmsg; + return false; + } + + XMLNode& root (*tree.root()); + if (root.name() != X_("SessionDefaults")) { + warning << _("Invalid session default XML Root.") << endmsg; + return false; + } + + XMLNode* node; + if (((node = find_named_node (root, X_("Config"))) != 0)) { + LocaleGuard lg; + set_variables(*node); + info << _("Loaded custom session defaults.") << endmsg; + } else { + warning << _("Found no session defaults in XML file.") << endmsg; + return false; + } + + /* CUSTOM OVERRIDES */ + set_audio_search_path(""); + set_midi_search_path(""); + set_raid_path(""); + } + return true; +} + +bool +SessionConfiguration::save_state () +{ + const std::string rcfile = Glib::build_filename (user_config_directory(), "session.rc"); + if (rcfile.empty()) { + return false; + } + + XMLTree tree; + XMLNode* root = new XMLNode(X_("SessionDefaults")); + root->add_child_nocopy (get_variables ()); + tree.set_root (root); + + if (!tree.write (rcfile.c_str())) { + error << _("Could not save session options") << endmsg; + return false; + } + + return true; }