- if (set_state (*tree.root())) {
- error << string_compose(_("Ardour: user configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
- return -1;
- }
- } else {
- warning << _("your Ardour configuration file is empty. This is not normal.") << endmsg;
- }
- }
-
- if (!found)
- error << "Ardour: could not find configuration file (ardour.rc), canvas will look broken." << endmsg;
-
- return 0;
-}
-
-int
-Configuration::save_state()
-{
- XMLTree tree;
-
- try
- {
- sys::create_directories (user_config_directory ());
- }
- catch (const sys::filesystem_error& ex)
- {
- error << "Could not create user configuration directory" << endmsg;
- return -1;
- }
-
- sys::path rcfile_path(user_config_directory());
-
- rcfile_path /= "ardour.rc";
- const string rcfile = rcfile_path.to_string();
-
- // this test seems bogus?
- if (rcfile.length()) {
- tree.set_root (&get_state());
- if (!tree.write (rcfile.c_str())){
- error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
- return -1;
- }
- }
-
- return 0;
-}
-
-void
-Configuration::add_instant_xml(XMLNode& node)
-{
- Stateful::add_instant_xml (node, user_config_directory ());
-}
-
-XMLNode*
-Configuration::instant_xml(const string& node_name)
-{
- return Stateful::instant_xml (node_name, user_config_directory ());
-}
-
-
-bool
-Configuration::save_config_options_predicate (ConfigVariableBase::Owner owner)
-{
- /* only save things that were in the config file to start with */
- return owner & ConfigVariableBase::Config;
-}
-
-XMLNode&
-Configuration::get_state ()
-{
- XMLNode* root;
- LocaleGuard lg (X_("POSIX"));
-
- root = new XMLNode("Ardour");
-
- MIDI::Manager::PortMap::const_iterator i;
- const MIDI::Manager::PortMap& ports = MIDI::Manager::instance()->get_midi_ports();
-
- for (i = ports.begin(); i != ports.end(); ++i) {
- root->add_child_nocopy(i->second->get_state());
- }
-
- root->add_child_nocopy (get_variables (sigc::mem_fun (*this, &Configuration::save_config_options_predicate), "Config"));
-
- if (_extra_xml) {
- root->add_child_copy (*_extra_xml);
- }
-
- root->add_child_nocopy (ControlProtocolManager::instance().get_state());
-
- return *root;
-}
-
-XMLNode&
-Configuration::get_variables (sigc::slot<bool,ConfigVariableBase::Owner> predicate, std::string which_node)
-{
- XMLNode* node;
- LocaleGuard lg (X_("POSIX"));
-
- node = new XMLNode(which_node);
-
-#undef CONFIG_VARIABLE
-#undef CONFIG_VARIABLE_SPECIAL
-#define CONFIG_VARIABLE(type,var,Name,value) \
- if (node->name() == "Config") { if (predicate (var.owner())) { var.add_to_node (*node); }}
-#define CONFIG_VARIABLE_SPECIAL(type,var,Name,value,mutator) \
- if (node->name() == "Config") { if (predicate (var.owner())) { var.add_to_node (*node); }}
-#include "ardour/configuration_vars.h"
-#undef CONFIG_VARIABLE
-#undef CONFIG_VARIABLE_SPECIAL
-
- return *node;
-}
-
-int
-Configuration::set_state (const XMLNode& root)
-{
- if (root.name() != "Ardour") {
- return -1;
- }
-
- XMLNodeList nlist = root.children();
- XMLNodeConstIterator niter;
- XMLNode *node;
-
- for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
-
- node = *niter;
-
- if (node->name() == "MIDI-port") {
-
- try {
-
- MIDI::Port::Descriptor desc (*node);
- map<string,XMLNode>::iterator x;
- if ((x = midi_ports.find (desc.tag)) != midi_ports.end()) {
- midi_ports.erase (x);