modify design of configuration state saving to reflect discussions on IRC
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 29 Sep 2006 13:10:46 +0000 (13:10 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Fri, 29 Sep 2006 13:10:46 +0000 (13:10 +0000)
git-svn-id: svn://localhost/ardour2/trunk@934 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/ardour_ui_options.cc
libs/ardour/ardour/configuration.h
libs/ardour/ardour/configuration_variable.h
libs/ardour/ardour/configuration_vars.h
libs/ardour/ardour/session.h
libs/ardour/configuration.cc
libs/ardour/session_state.cc

index 0e9f193653d6306ab174aa768156c3f640cbad06..f7e1faa80652f9a21d285317add53a6a9c774085 100644 (file)
@@ -47,6 +47,8 @@ ARDOUR_UI::toggle_config_state (const char* group, const char* action, bool (Con
 
                if (tact) {
                        bool x = (Config->*get)();
+
+                       cerr << "\ttoggle config, action = " << tact->get_active() << " config = " << x << endl;
                        
                        if (x != tact->get_active()) {
                                (Config->*set) (!x);
@@ -382,18 +384,27 @@ ARDOUR_UI::map_some_state (const char* group, const char* action, bool (Configur
                Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
 
                if (tact) {
+                       
                        bool x = (Config->*get)();
+
+                       cerr << "\tmap state, action = " << tact->get_active() << " config = " << x << endl;
                        
                        if (tact->get_active() != x) {
                                tact->set_active (x);
                        }
+               } else {
+                       cerr << "not a toggle\n";
                }
+       } else {
+               cerr << group << ':' << action << " not an action\n";
        }
 }
 
 void
 ARDOUR_UI::parameter_changed (const char* parameter_name)
 {
+       cerr << "Parameter changed : " << parameter_name << endl;
+
 #define PARAM_IS(x) (!strcmp (parameter_name, (x)))
 
        if (PARAM_IS ("slave-source")) {
@@ -416,8 +427,12 @@ ARDOUR_UI::parameter_changed (const char* parameter_name)
                map_some_state ("options", "UseMIDIcontrol", &Configuration::get_midi_control);
        } else if (PARAM_IS ("do-not-record-plugins")) {
                map_some_state ("options", "DoNotRunPluginsWhileRecording", &Configuration::get_do_not_record_plugins);
+       } else if (PARAM_IS ("automatic-crossfades")) {
+               map_some_state ("Editor", "toggle-auto-xfades", &Configuration::get_automatic_crossfades);
        } else if (PARAM_IS ("crossfades-active")) {
-               map_some_state ("options", "CrossfadesActive", &Configuration::get_crossfades_active);
+               map_some_state ("Editor", "toggle-xfades-active", &Configuration::get_crossfades_active);
+       } else if (PARAM_IS ("crossfades-visible")) {
+               map_some_state ("Editor", "toggle-xfades-visible", &Configuration::get_crossfades_visible);
        } else if (PARAM_IS ("latched-record-enable")) {
                map_some_state ("options", "LatchedRecordEnable", &Configuration::get_latched_record_enable);
        } else if (PARAM_IS ("solo-latched")) {
index 0b933cc5ac4169aafcaf46e07352c255f8cdbcc8..bb49b2dce4703a308411f59ff675b291deb1424f 100644 (file)
@@ -62,7 +62,7 @@ class Configuration : public Stateful
 
        int set_state (const XMLNode&);
        XMLNode& get_state (void);
-       XMLNode& get_partial_state (ConfigVariableBase::Owner);
+       XMLNode& get_variables (sigc::slot<bool,ConfigVariableBase::Owner>);
        void set_variables (const XMLNode&, ConfigVariableBase::Owner owner);
 
        void set_current_owner (ConfigVariableBase::Owner);
@@ -100,7 +100,8 @@ class Configuration : public Stateful
        ConfigVariableBase::Owner current_owner;
        XMLNode* _control_protocol_state;
 
-       XMLNode& state (ConfigVariableBase::Owner);
+       XMLNode& state (sigc::slot<bool,ConfigVariableBase::Owner>);
+       bool     save_config_options_predicate (ConfigVariableBase::Owner owner);
 };
 
 extern Configuration *Config;
index 4eba3101a230ec8d10696532f6a50bc62370edbd..6f0a8a35718ff80a3002a98b488ffba8369316fc 100644 (file)
@@ -11,11 +11,11 @@ namespace ARDOUR {
 class ConfigVariableBase {
   public:
        enum Owner {
-               Default,
-               System,
-               Config,
-               Session,
-               Interface
+               Default = 0x1,
+               System = 0x2,
+               Config = 0x4,
+               Session = 0x8,
+               Interface = 0x10
        };
 
        ConfigVariableBase (std::string str) : _name (str), _owner (Default) {}
@@ -44,7 +44,7 @@ class ConfigVariable : public ConfigVariableBase
                        return false;
                }
                value = val;
-               _owner = owner;
+               _owner = (ConfigVariableBase::Owner)(_owner |owner);
                return true;
        }
 
@@ -85,7 +85,7 @@ class ConfigVariable : public ConfigVariableBase
                                                                std::stringstream ss;
                                                                ss << prop->value();
                                                                ss >> value;
-                                                               _owner = owner;
+                                                               _owner = (ConfigVariableBase::Owner)(_owner |owner);
                                                                return true;
                                                        }
                                                }
@@ -113,7 +113,7 @@ class ConfigVariable : public ConfigVariableBase
                                                std::stringstream ss;
                                                ss << opt_prop->value();
                                                ss >> value;
-                                               _owner = owner;
+                                               _owner = (ConfigVariableBase::Owner)(_owner |owner);
                                                return true;
                                        }
                                }
index 8cd66decb11c9e45240641bd94df53258db65eaf..9cdba051fdee515ad79c7af80d22d91b8c62d137 100644 (file)
@@ -55,9 +55,11 @@ CONFIG_VARIABLE (bool, send_mmc, "send-mmc", false)
 CONFIG_VARIABLE (bool, mmc_control, "mmc-control", false)
 CONFIG_VARIABLE (bool, midi_feedback, "midi-feedback", false)
 CONFIG_VARIABLE (bool, midi_control, "midi-control", false)
+CONFIG_VARIABLE (bool, automatic_crossfades, "automatic-crossfades", false)
 CONFIG_VARIABLE (bool, crossfades_active, "crossfades-active", false)
+CONFIG_VARIABLE (bool, crossfades_visible, "crossfades-visible", false)
 CONFIG_VARIABLE (bool, seamless_loop, "seamless-loop", false)
-CONFIG_VARIABLE (bool, do_not_record_plugins, "do_not_record_plugins", false)
+CONFIG_VARIABLE (bool, do_not_record_plugins, "do-not-record-plugins", false)
 CONFIG_VARIABLE (AutoConnectOption, output_auto_connect, "output-auto-connect", AutoConnectOption (0))
 CONFIG_VARIABLE (AutoConnectOption, input_auto_connect, "input-auto-connect", AutoConnectOption (0))
 CONFIG_VARIABLE (EditMode, edit_mode, "edit-mode", Slide)
index 2ac2d3c48fa967192ccc4f011ad64ab3528df0f5..a55bc84e7e544f1e438b9642fec5ae39b084ade0 100644 (file)
@@ -1087,6 +1087,7 @@ class Session : public sigc::trackable, public PBD::StatefulDestructible
        int      load_options (const XMLNode&);
        XMLNode& get_options () const;
        int      load_state (string snapshot_name);
+       bool     save_config_options_predicate (ConfigVariableBase::Owner owner) const;
 
        nframes_t   _last_roll_location;
        nframes_t   _last_record_location;
index d811be0f6e2f641167ce36befbc114ddede797fd..37666f7dca994bf72c794bda6159e054ca33e6f2 100644 (file)
@@ -132,14 +132,11 @@ Configuration::save_state()
        XMLTree tree;
        string rcfile;
 
-       /* Note: this only writes the state not touched by Session or Interface
-       */
-
        rcfile = get_user_ardour_path ();
        rcfile += "ardour.rc";
 
        if (rcfile.length()) {
-               tree.set_root (&state (ConfigVariableBase::Config));
+               tree.set_root (&get_state());
                if (!tree.write (rcfile.c_str())){
                        error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
                        return -1;
@@ -149,22 +146,42 @@ Configuration::save_state()
        return 0;
 }
 
-XMLNode&
-Configuration::get_state ()
+bool
+Configuration::save_config_options_predicate (ConfigVariableBase::Owner owner)
 {
-       return state (ConfigVariableBase::Config);
+       const ConfigVariableBase::Owner default_or_from_config_file = (ConfigVariableBase::Owner)
+               (ConfigVariableBase::Default|ConfigVariableBase::System|ConfigVariableBase::Config);
+       
+       return owner & default_or_from_config_file;
 }
 
 XMLNode&
-Configuration::get_partial_state (ConfigVariableBase::Owner owner)
+Configuration::get_state ()
 {
-       return state (owner);
+       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());
+       }
+       
+       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::state (ConfigVariableBase::Owner owner)
+Configuration::get_variables (sigc::slot<bool,ConfigVariableBase::Owner> predicate)
 {
-       XMLNode* root;
        XMLNode* node;
        LocaleGuard lg (X_("POSIX"));
 
@@ -173,36 +190,14 @@ Configuration::state (ConfigVariableBase::Owner owner)
 #undef  CONFIG_VARIABLE
 #undef  CONFIG_VARIABLE_SPECIAL        
 #define CONFIG_VARIABLE(type,var,name,value) \
-         if (var.owner() <= owner) var.add_to_node (*node);
+         if (predicate (var.owner())) { var.add_to_node (*node); }
 #define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) \
-         if (var.owner() <= owner) 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        
-
-       if (owner == ConfigVariableBase::Config) {
-
-               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());
-               }
-
-               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());
-
-       } else {
-
-               root = node;
-       }
-               
-       return *root;
+       
+       return *node;
 }
 
 int
index 54c1b59f397e3c862accc94adaa13469a70b7b0b..fdbdb2da8d7875bf1cf7c724340c08946ea75e9c 100644 (file)
@@ -725,13 +725,22 @@ Session::load_options (const XMLNode& node)
        return 0;
 }
 
+bool
+Session::save_config_options_predicate (ConfigVariableBase::Owner owner) const
+{
+       const ConfigVariableBase::Owner modified_by_session_or_user = (ConfigVariableBase::Owner)
+               (ConfigVariableBase::Session|ConfigVariableBase::Interface);
+
+       return owner & modified_by_session_or_user;
+}
+
 XMLNode&
 Session::get_options () const
 {
        XMLNode* child;
        LocaleGuard lg (X_("POSIX"));
 
-       XMLNode& option_root = Config->get_partial_state (ConfigVariableBase::Interface);
+       XMLNode& option_root = Config->get_variables (mem_fun (*this, &Session::save_config_options_predicate));
 
        child = option_root.add_child ("end-marker-is-free");
        child->add_property ("val", _end_location_is_free ? "yes" : "no");