Merged with trunk R992.
[ardour.git] / libs / ardour / configuration.cc
index 84c3e3a83444d9e1685d9b9f9daaeb07bdb93b93..e84e92fa26beabc64d5fe3a976ccef2aa0265379 100644 (file)
@@ -56,7 +56,7 @@ Configuration::Configuration ()
 #undef  CONFIG_VARIABLE
 #undef  CONFIG_VARIABLE_SPECIAL        
 
-       user_configuration (false)
+       current_owner (ConfigVariableBase::Default)
 {
        _control_protocol_state = 0;
 }
@@ -65,6 +65,12 @@ Configuration::~Configuration ()
 {
 }
 
+void
+Configuration::set_current_owner (ConfigVariableBase::Owner owner)
+{
+       current_owner = owner;
+}
+
 int
 Configuration::load_state ()
 {
@@ -85,15 +91,14 @@ Configuration::load_state ()
                        return -1;
                }
 
+               current_owner = ConfigVariableBase::System;
+
                if (set_state (*tree.root())) {
                        error << string_compose(_("Ardour: system configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
                        return -1;
                }
        }
 
-       /* from this point on, all configuration changes are user driven */
-
-       user_configuration = true;
 
        /* now load configuration file for user */
        
@@ -110,6 +115,8 @@ Configuration::load_state ()
                        return -1;
                }
 
+               current_owner = ConfigVariableBase::Config;
+
                if (set_state (*tree.root())) {
                        error << string_compose(_("Ardour: user configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
                        return -1;
@@ -125,15 +132,11 @@ Configuration::save_state()
        XMLTree tree;
        string rcfile;
 
-       /* Note: this only writes the per-user file, and therefore
-          only saves variables marked as user-set or modified
-       */
-
        rcfile = get_user_ardour_path ();
        rcfile += "ardour.rc";
 
        if (rcfile.length()) {
-               tree.set_root (&state (true));
+               tree.set_root (&get_state());
                if (!tree.write (rcfile.c_str())){
                        error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
                        return -1;
@@ -143,45 +146,56 @@ Configuration::save_state()
        return 0;
 }
 
-XMLNode&
-Configuration::get_state ()
+bool
+Configuration::save_config_options_predicate (ConfigVariableBase::Owner owner)
 {
-       return state (false);
+       /* only save things that were in the config file to start with */
+       return owner & ConfigVariableBase::Config;
 }
 
 XMLNode&
-Configuration::state (bool user_only)
+Configuration::get_state ()
 {
-       XMLNode* root = new XMLNode("Ardour");
+       XMLNode* root;
        LocaleGuard lg (X_("POSIX"));
 
+       root = new XMLNode("Ardour");
        typedef map<string, MidiPortDescriptor*>::const_iterator CI;
        for(CI m = midi_ports.begin(); m != midi_ports.end(); ++m){
                root->add_child_nocopy(m->second->get_state());
        }
-
-       XMLNode* node = new XMLNode("Config");
        
+       root->add_child_nocopy (get_variables (sigc::mem_fun (*this, &Configuration::save_config_options_predicate)));
+       
+       if (_extra_xml) {
+               root->add_child_copy (*_extra_xml);
+       }
+       
+       root->add_child_nocopy (ControlProtocolManager::instance().get_state());
+       root->add_child_nocopy (Library->get_state());
+       
+       return *root;
+}
+
+XMLNode&
+Configuration::get_variables (sigc::slot<bool,ConfigVariableBase::Owner> predicate)
+{
+       XMLNode* node;
+       LocaleGuard lg (X_("POSIX"));
+
+       node = new XMLNode("Config");
+
 #undef  CONFIG_VARIABLE
 #undef  CONFIG_VARIABLE_SPECIAL        
 #define CONFIG_VARIABLE(type,var,name,value) \
-         if (!user_only || var.is_user()) var.add_to_node (*node);
+         if (predicate (var.owner())) { var.add_to_node (*node); }
 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
-         if (!user_only || var.is_user()) var.add_to_node (*node);
+         if (predicate (var.owner())) { var.add_to_node (*node); }
 #include "ardour/configuration_vars.h"
 #undef  CONFIG_VARIABLE
 #undef  CONFIG_VARIABLE_SPECIAL        
-
-       root->add_child_nocopy (*node);
-
-       if (_extra_xml) {
-               root->add_child_copy (*_extra_xml);
-       }
-
-       root->add_child_nocopy (ControlProtocolManager::instance().get_state());
-       root->add_child_nocopy (Library->get_state());
-
-       return *root;
+       
+       return *node;
 }
 
 int
@@ -213,18 +227,8 @@ Configuration::set_state (const XMLNode& root)
                        }
 
                } else if (node->name() == "Config") {
-
-#undef  CONFIG_VARIABLE
-#undef  CONFIG_VARIABLE_SPECIAL        
-#define CONFIG_VARIABLE(type,var,name,value) \
-         var.set_from_node (*node); \
-        var.set_is_user (user_configuration);
-#define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
-         var.set_from_node (*node); \
-        var.set_is_user (user_configuration);
-#include "ardour/configuration_vars.h"
-#undef  CONFIG_VARIABLE
-#undef  CONFIG_VARIABLE_SPECIAL        
+                       
+                       set_variables (*node, ConfigVariableBase::Config);
                        
                } else if (node->name() == "extra") {
                        _extra_xml = new XMLNode (*node);
@@ -241,6 +245,25 @@ Configuration::set_state (const XMLNode& root)
        return 0;
 }
 
+void
+Configuration::set_variables (const XMLNode& node, ConfigVariableBase::Owner owner)
+{
+#undef  CONFIG_VARIABLE
+#undef  CONFIG_VARIABLE_SPECIAL        
+#define CONFIG_VARIABLE(type,var,name,value) \
+         if (var.set_from_node (node, owner)) { \
+                ParameterChanged (name); \
+        }
+#define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
+         if (var.set_from_node (node, owner)) { \
+                ParameterChanged (name); \
+        }
+#include "ardour/configuration_vars.h"
+#undef  CONFIG_VARIABLE
+#undef  CONFIG_VARIABLE_SPECIAL        
+
+}
+
 Configuration::MidiPortDescriptor::MidiPortDescriptor (const XMLNode& node)
 {
        const XMLProperty *prop;
@@ -287,3 +310,14 @@ Configuration::MidiPortDescriptor::get_state()
        return *root;
 }
 
+void
+Configuration::map_parameters (sigc::slot<void,const char*> theSlot)
+{
+#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);
+#include "ardour/configuration_vars.h"
+#undef  CONFIG_VARIABLE
+#undef  CONFIG_VARIABLE_SPECIAL        
+}