First stage of options rework.
[ardour.git] / libs / ardour / session_state.cc
index e04333a2fa6b75beca279021ec800f8a16c8fc64..c7cb3fc5a1c807da64c6be916769ab681b7dffc2 100644 (file)
@@ -163,7 +163,6 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        _transport_frame = 0;
        end_location = new Location (0, 0, _("end"), Location::Flags ((Location::IsMark|Location::IsEnd)));
        start_location = new Location (0, 0, _("start"), Location::Flags ((Location::IsMark|Location::IsStart)));
-       _end_location_is_free = true;
        g_atomic_int_set (&_record_status, Disabled);
        loop_changing = false;
        play_loop = false;
@@ -205,7 +204,6 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        _npan_buffers = 0;
        pending_abort = false;
        destructive_index = 0;
-       current_trans = 0;
        first_file_data_format_reset = true;
        first_file_header_format_reset = true;
        butler_thread = (pthread_t) 0;
@@ -215,8 +213,8 @@ Session::first_stage_init (string fullpath, string snapshot_name)
 
        /* default short fade = 15ms */
 
-       Crossfade::set_short_xfade_length ((nframes_t) floor (Config->get_short_xfade_seconds() * frame_rate()));
-       SndFileSource::setup_standard_crossfades (frame_rate());
+       Crossfade::set_short_xfade_length ((nframes_t) floor (config.get_short_xfade_seconds() * frame_rate()));
+       SndFileSource::setup_standard_crossfades (*this, frame_rate());
 
        last_mmc_step.tv_sec = 0;
        last_mmc_step.tv_usec = 0;
@@ -340,8 +338,7 @@ Session::second_stage_init (bool new_session)
        /* handle this one in a different way than all others, so that its clear what happened */
        
        catch (AudioEngine::PortRegistrationFailure& err) {
-               error << _("Unable to create all required ports")
-                     << endmsg;
+               error << err.what() << endmsg;
                return -1;
        }
 
@@ -365,11 +362,7 @@ Session::second_stage_init (bool new_session)
 
        ControlProtocolManager::instance().set_session (*this);
 
-       if (new_session) {
-               _end_location_is_free = true;
-       } else {
-               _end_location_is_free = false;
-       }
+       config.set_end_marker_is_free (new_session);
 
        _state_of_the_state = Clean;
        
@@ -863,7 +856,7 @@ Session::load_options (const XMLNode& node)
        XMLProperty* prop;
        LocaleGuard lg (X_("POSIX"));
 
-       Config->set_variables (node, ConfigVariableBase::Session);
+       config.set_variables (node);
 
        /* now reset MIDI ports because the session can have its own 
           MIDI configuration.
@@ -871,38 +864,9 @@ Session::load_options (const XMLNode& node)
 
        setup_midi ();
 
-       if ((child = find_named_node (node, "end-marker-is-free")) != 0) {
-               if ((prop = child->property ("val")) != 0) {
-                       _end_location_is_free = (prop->value() == "yes");
-               }
-       }
-
        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_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");
-
-       return option_root;
-}
-
 XMLNode&
 Session::get_state()
 {
@@ -978,7 +942,7 @@ Session::state(bool full_state)
 
        /* various options */
 
-       node->add_child_nocopy (get_options());
+       node->add_child_nocopy (config.get_variables ());
 
        node->add_child_nocopy (_metadata->get_state());
 
@@ -1408,8 +1372,10 @@ Session::XMLRouteFactory (const XMLNode& node)
        
        DataType type = DataType::AUDIO;
        const XMLProperty* prop = node.property("default-type");
-       if (prop)
+
+       if (prop) {
                type = DataType(prop->value());
+       } 
        
        assert(type != DataType::NIL);
 
@@ -2249,29 +2215,36 @@ Session::edit_group_by_name (string name)
 }
 
 void
-Session::begin_reversible_command (const string& name)
+Session::begin_reversible_command(const string& name)
 {
-       current_trans = new UndoTransaction;
-       current_trans->set_name (name);
+       UndoTransaction* trans = new UndoTransaction();
+       trans->set_name(name);
+       if (!_current_trans.empty()) {
+               _current_trans.top()->add_command(trans);
+       }
+       _current_trans.push(trans);
 }
 
 void
-Session::commit_reversible_command (Command *cmd)
+Session::commit_reversible_command(Command *cmd)
 {
+       assert(!_current_trans.empty());
        struct timeval now;
 
        if (cmd) {
-               current_trans->add_command (cmd);
+               _current_trans.top()->add_command(cmd);
        }
 
-       if (current_trans->empty()) {
+       if (_current_trans.top()->empty()) {
+               _current_trans.pop();
                return;
        }
 
-       gettimeofday (&now, 0);
-       current_trans->set_timestamp (now);
+       gettimeofday(&now, 0);
+       _current_trans.top()->set_timestamp(now);
 
-       _history.add (current_trans);
+       _history.add(_current_trans.top());
+       _current_trans.pop();
 }
 
 Session::GlobalRouteBooleanState 
@@ -2360,32 +2333,6 @@ Session::set_global_record_enable (GlobalRouteBooleanState s, void* src)
        set_global_route_boolean (s, &Route::set_record_enable, src);
 }
 
-#if 0
-UndoAction
-Session::global_mute_memento (void* src)
-{
-       return sigc::bind (mem_fun (*this, &Session::set_global_mute), get_global_route_boolean (&Route::muted), src);
-}
-
-UndoAction
-Session::global_metering_memento (void* src)
-{
-       return sigc::bind (mem_fun (*this, &Session::set_global_route_metering), get_global_route_metering (), src);
-}
-
-UndoAction
-Session::global_solo_memento (void* src)
-{
-       return sigc::bind (mem_fun (*this, &Session::set_global_solo), get_global_route_boolean (&Route::soloed), src);
-}
-
-UndoAction
-Session::global_record_enable_memento (void* src)
-{
-       return sigc::bind (mem_fun (*this, &Session::set_global_record_enable), get_global_route_boolean (&Route::record_enabled), src);
-}
-#endif
-
 static bool
 accept_all_non_peak_files (const string& path, void *arg)
 {
@@ -2849,7 +2796,12 @@ void
 Session::set_deletion_in_progress ()
 {
        _state_of_the_state = StateOfTheState (_state_of_the_state | Deletion);
+}
 
+void
+Session::clear_deletion_in_progress ()
+{
+       _state_of_the_state = StateOfTheState (_state_of_the_state & (~Deletion));
 }
 
 void
@@ -3069,7 +3021,7 @@ Session::config_changed (const char* parameter_name)
                        
                        for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
                                if ((*i)->record_enabled ()) {
-                                       (*i)->monitor_input (!Config->get_auto_input());
+                                       (*i)->monitor_input (!config.get_auto_input());
                                }
                        }
                }
@@ -3080,7 +3032,7 @@ Session::config_changed (const char* parameter_name)
                
                if ((location = _locations.auto_punch_location()) != 0) {
                        
-                       if (Config->get_punch_in ()) {
+                       if (config.get_punch_in ()) {
                                replace_event (Event::PunchIn, location->start());
                        } else {
                                remove_event (location->start(), Event::PunchIn);
@@ -3093,7 +3045,7 @@ Session::config_changed (const char* parameter_name)
                
                if ((location = _locations.auto_punch_location()) != 0) {
                        
-                       if (Config->get_punch_out()) {
+                       if (config.get_punch_out()) {
                                replace_event (Event::PunchOut, location->end());
                        } else {
                                clear_events (Event::PunchOut);
@@ -3134,7 +3086,7 @@ Session::config_changed (const char* parameter_name)
 
        } else if (PARAM_IS ("raid-path")) {
 
-               setup_raid_path (Config->get_raid_path());
+               setup_raid_path (config.get_raid_path());
 
        } else if (PARAM_IS ("smpte-format")) {