monster commit: transport mgmt changes from 2.X (omnibus edition); make slave use...
[ardour.git] / libs / ardour / session_state.cc
index de99558c16745db293147be42a137d7d1d102152..1a4758186eac9aee5c99545ee9f7e49f14d4c557 100644 (file)
@@ -6,7 +6,7 @@
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
@@ -71,6 +71,7 @@
 #include "ardour/audioregion.h"
 #include "ardour/auditioner.h"
 #include "ardour/buffer.h"
+#include "ardour/butler.h"
 #include "ardour/configuration.h"
 #include "ardour/control_protocol_manager.h"
 #include "ardour/crossfade.h"
@@ -173,6 +174,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        auto_play_legal = false;
        transport_sub_state = 0;
        _transport_frame = 0;
+       _requested_return_frame = -1;
        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)));
        g_atomic_int_set (&_record_status, Disabled);
@@ -184,25 +186,21 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        pending_locate_frame = 0;
        pending_locate_roll = false;
        pending_locate_flush = false;
-       audio_dstream_buffer_size = 0;
-       midi_dstream_buffer_size = 0;
        state_was_pending = false;
        set_next_event ();
-       outbound_mtc_smpte_frame = 0;
+       outbound_mtc_timecode_frame = 0;
        next_quarter_frame_to_send = -1;
        current_block_size = 0;
        solo_update_disabled = false;
        _have_captured = false;
        _worst_output_latency = 0;
        _worst_input_latency = 0;
-       _worst_track_latency = 0;
+       _worst_track_latency = 0;
        _state_of_the_state = StateOfTheState(CannotSave|InitialConnecting|Loading);
-
+       _was_seamless = Config->get_seamless_loop ();
        _slave = 0;
        session_send_mmc = false;
        session_send_mtc = false;
-       post_transport_work = PostTransportWork (0);
-       g_atomic_int_set (&butler_should_do_transport_work, 0);
        g_atomic_int_set (&_playback_load, 100);
        g_atomic_int_set (&_capture_load, 100);
        g_atomic_int_set (&_playback_load_min, 100);
@@ -217,7 +215,6 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        destructive_index = 0;
        first_file_data_format_reset = true;
        first_file_header_format_reset = true;
-       butler_thread = (pthread_t) 0;
        //midi_thread = (pthread_t) 0;
 
        AudioDiskstream::allocate_working_buffers();
@@ -247,10 +244,10 @@ Session::first_stage_init (string fullpath, string snapshot_name)
                waiting_for_sync_offset = false;
        }
 
-       last_smpte_when = 0;
-       _smpte_offset = 0;
-       _smpte_offset_negative = true;
-       last_smpte_valid = false;
+       last_timecode_when = 0;
+       _timecode_offset = 0;
+       _timecode_offset_negative = true;
+       last_timecode_valid = false;
 
        sync_time_vars ();
 
@@ -299,7 +296,7 @@ Session::second_stage_init (bool new_session)
                remove_empty_sounds ();
        }
 
-       if (start_butler_thread()) {
+       if (_butler->start_thread()) {
                return -1;
        }
 
@@ -311,7 +308,7 @@ Session::second_stage_init (bool new_session)
        // to call setup_raid_path() here.
 
        if (state_tree) {
-               if (set_state (*state_tree->root())) {
+               if (set_state (*state_tree->root(), Stateful::loading_state_version)) {
                        return -1;
                }
        } else {
@@ -756,7 +753,7 @@ int
 Session::restore_state (string snapshot_name)
 {
        if (load_state (snapshot_name) == 0) {
-               set_state (*state_tree->root());
+               set_state (*state_tree->root(), Stateful::loading_state_version);
        }
 
        return 0;
@@ -824,20 +821,20 @@ Session::load_state (string snapshot_name)
        }
 
        const XMLProperty* prop;
-       bool is_old = false; // session is _very_ old (pre-2.0)
 
        if ((prop = root.property ("version")) == 0) {
                /* no version implies very old version of Ardour */
-               is_old = true;
+               Stateful::loading_state_version = 1000;
        } else {
-               int major_version;
-               major_version = atoi (prop->value().c_str()); // grab just the first number before the period
-               if (major_version < 2) {
-                       is_old = true;
-               }
-       }
+               int major;
+               int minor;
+               int micro;
 
-       if (is_old) {
+               sscanf (prop->value().c_str(), "%d.%d.%d", &major, &minor, &micro);
+               Stateful::loading_state_version = (major * 1000) + minor;
+       }
+               
+       if (Stateful::loading_state_version < CURRENT_SESSION_FILE_VERSION) {
 
                sys::path backup_path(_session_dir->root_path());
 
@@ -1212,7 +1209,7 @@ Session::set_state (const XMLNode& node, int version)
        if (version >= 3000) {
                if ((child = find_named_node (node, "Metadata")) == 0) {
                        warning << _("Session: XML state has no metadata section") << endmsg;
-               } else if (_metadata->set_state (*child)) {
+               } else if (_metadata->set_state (*child, version)) {
                        goto out;
                }
        }
@@ -1220,7 +1217,7 @@ Session::set_state (const XMLNode& node, int version)
        if ((child = find_named_node (node, "Locations")) == 0) {
                error << _("Session: XML state has no locations section") << endmsg;
                goto out;
-       } else if (_locations.set_state (*child)) {
+       } else if (_locations.set_state (*child, version)) {
                goto out;
        }
 
@@ -1331,7 +1328,7 @@ Session::set_state (const XMLNode& node, int version)
        if ((child = find_named_node (node, "TempoMap")) == 0) {
                error << _("Session: XML state has no Tempo Map section") << endmsg;
                goto out;
-       } else if (_tempo_map->set_state (*child)) {
+       } else if (_tempo_map->set_state (*child, version)) {
                goto out;
        }
 
@@ -1345,7 +1342,7 @@ Session::set_state (const XMLNode& node, int version)
        if ((child = find_named_node (node, "Click")) == 0) {
                warning << _("Session: XML state has no click section") << endmsg;
        } else if (_click_io) {
-               _click_io->set_state (*child);
+               _click_io->set_state (*child, version);
        }
 
        if ((child = find_named_node (node, "ControlProtocols")) != 0) {
@@ -1419,7 +1416,7 @@ Session::XMLRouteFactory (const XMLNode& node, int version)
                        return ret;
                }
        } else {
-               boost::shared_ptr<Route> ret (new Route (*this, node, version));
+               boost::shared_ptr<Route> ret (new Route (*this, node));
                return ret;
        }
 }
@@ -2439,7 +2436,7 @@ struct RegionCounter {
 };
 
 int
-Session::cleanup_sources (Session::cleanup_report& rep)
+Session::cleanup_sources (CleanupReport& rep)
 {
        // FIXME: needs adaptation to midi
 
@@ -2506,7 +2503,7 @@ Session::cleanup_sources (Session::cleanup_report& rep)
                   capture files.
                */
 
-               if (!i->second->used() && i->second->length(i->second->timeline_position()) > 0) {
+               if (!source_use_count(i->second) && i->second->length(i->second->timeline_position()) > 0) {
                        dead_sources.push_back (i->second);
                        i->second->GoingAway();
                }
@@ -2702,7 +2699,7 @@ Session::cleanup_sources (Session::cleanup_report& rep)
 }
 
 int
-Session::cleanup_trash_sources (Session::cleanup_report& rep)
+Session::cleanup_trash_sources (CleanupReport& rep)
 {
        // FIXME: needs adaptation for MIDI
 
@@ -2936,7 +2933,7 @@ Session::restore_history (string snapshot_name)
        const string xml_filename = legalize_for_path (snapshot_name) + history_suffix;
        const sys::path xml_path = _session_dir->root_path() / xml_filename;
 
-       cerr << "Loading history from " << xml_path.to_string() << endmsg;
+       info << "Loading history from " << xml_path.to_string() << endmsg;
 
        if (!sys::exists (xml_path)) {
                info << string_compose (_("%1: no history file \"%2\" for this session."),
@@ -2990,19 +2987,20 @@ Session::restore_history (string snapshot_name)
                                PBD::ID  id(n->property("midi-source")->value());
                                boost::shared_ptr<MidiSource> midi_source =
                                        boost::dynamic_pointer_cast<MidiSource, Source>(source_by_id(id));
-                               if(midi_source) {
+                               if (midi_source) {
                                        ut->add_command(new MidiModel::DeltaCommand(midi_source->model(), *n));
                                } else {
-                                       error << "FIXME: Failed to downcast MidiSource for DeltaCommand" << endmsg;
+                                       error << _("Failed to downcast MidiSource for DeltaCommand") << endmsg;
                                }
+
                        } else if (n->name() == "DiffCommand") {
                                PBD::ID  id(n->property("midi-source")->value());
                                boost::shared_ptr<MidiSource> midi_source =
                                        boost::dynamic_pointer_cast<MidiSource, Source>(source_by_id(id));
-                               if(midi_source) {
+                               if (midi_source) {
                                        ut->add_command(new MidiModel::DiffCommand(midi_source->model(), *n));
                                } else {
-                                       error << "FIXME: Failed to downcast MidiSource for DeltaCommand" << endmsg;
+                                       error << _("Failed to downcast MidiSource for DeltaCommand") << endmsg;
                                }
 
                        } else {
@@ -3105,7 +3103,7 @@ Session::config_changed (std::string p, bool ours)
 
                setup_raid_path (config.get_raid_path());
 
-       } else if (p == "smpte-format") {
+       } else if (p == "timecode-format") {
 
                sync_time_vars ();