most of the 2.X->3.0 commit (up to rev 4299) except for gtk2_ardour/editor_canvas...
[ardour.git] / libs / ardour / session_state.cc
index 0975d4dc8ac88f312771a6c98e7d54a18d8a1201..cb4a9e5813f25b61c7592b24ca4e513b82031797 100644 (file)
@@ -86,6 +86,7 @@
 #include <ardour/tempo.h>
 #include <ardour/audio_track.h>
 #include <ardour/midi_track.h>
+#include <ardour/midi_patch_manager.h>
 #include <ardour/cycle_timer.h>
 #include <ardour/utils.h>
 #include <ardour/named_selection.h>
 #include <ardour/filename_extensions.h>
 #include <ardour/directory_names.h>
 #include <ardour/template_utils.h>
+#include <ardour/ticker.h>
 
 #include <control_protocol/control_protocol.h>
 
@@ -163,6 +165,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        g_atomic_int_set (&_record_status, Disabled);
        loop_changing = false;
        play_loop = false;
+       have_looped = false;
        _last_roll_location = 0;
        _last_record_location = 0;
        pending_locate_frame = 0;
@@ -170,7 +173,6 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        pending_locate_flush = false;
        audio_dstream_buffer_size = 0;
        midi_dstream_buffer_size = 0;
-       state_tree = 0;
        state_was_pending = false;
        set_next_event ();
        outbound_mtc_smpte_frame = 0;
@@ -185,14 +187,10 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        _state_of_the_state = StateOfTheState(CannotSave|InitialConnecting|Loading);
 
        _slave = 0;
-       butler_mixdown_buffer = 0;
-       butler_gain_buffer = 0;
-       mmc = 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 (&butler_active, 0);
        g_atomic_int_set (&_playback_load, 100);
        g_atomic_int_set (&_capture_load, 100);
        g_atomic_int_set (&_playback_load_min, 100);
@@ -226,8 +224,6 @@ Session::first_stage_init (string fullpath, string snapshot_name)
           waveforms for clicks.
        */
        
-       click_data = 0;
-       click_emphasis_data = 0;
        click_length = 0;
        click_emphasis_length = 0;
        _clicking = false;
@@ -254,7 +250,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
 
        /* slave stuff */
 
-       average_slave_delta = 1800;
+       average_slave_delta = 1800; // !!! why 1800 ????
        have_first_delta_accumulator = false;
        delta_accumulator_cnt = 0;
        slave_state = Stopped;
@@ -357,6 +353,11 @@ Session::second_stage_init (bool new_session)
        _engine.transport_locate (0);
        deliver_mmc (MIDI::MachineControl::cmdMmcReset, 0);
        deliver_mmc (MIDI::MachineControl::cmdLocate, 0);
+       
+       MidiClockTicker::instance().set_session(*this);
+       MIDI::Name::MidiPatchManager::instance().set_session(*this);
+
+       /* initial program change will be delivered later; see ::config_changed() */
 
        BootMessage (_("Reset Control Protocols"));
 
@@ -872,6 +873,12 @@ Session::load_options (const XMLNode& node)
 
        Config->set_variables (node, ConfigVariableBase::Session);
 
+       /* now reset MIDI ports because the session can have its own 
+          MIDI configuration.
+       */
+
+       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");
@@ -1204,10 +1211,10 @@ Session::set_state (const XMLNode& node)
 
        /* Object loading order:
 
-       MIDI Control
        Path
        extra
        Options/Config
+       MIDI Control // relies on data from Options/Config
        Metadata
        Locations
        Sources
@@ -1221,9 +1228,6 @@ Session::set_state (const XMLNode& node)
        ControlProtocols
        */
 
-       if (use_config_midi_ports ()) {
-       }
-
        if ((child = find_named_node (node, "extra")) != 0) {
                _extra_xml = new XMLNode (*child);
        }
@@ -1236,6 +1240,9 @@ Session::set_state (const XMLNode& node)
                error << _("Session: XML state has no options section") << endmsg;
        }
 
+       if (use_config_midi_ports ()) {
+       }
+
        if ((child = find_named_node (node, "Metadata")) == 0) {
                warning << _("Session: XML state has no metadata section (2.0 session?)") << endmsg;
        } else if (_metadata->set_state (*child)) {
@@ -3251,7 +3258,28 @@ Session::config_changed (const char* parameter_name)
        } else if (PARAM_IS ("history-depth")) {
                set_history_depth (Config->get_history_depth());
        } else if (PARAM_IS ("sync-all-route-ordering")) {
-               sync_order_keys ();
+               sync_order_keys ("session");
+       } else if (PARAM_IS ("initial-program-change")) {
+
+               if (_mmc_port && Config->get_initial_program_change() >= 0) {
+                       MIDI::byte buf[2];
+                       
+                       buf[0] = MIDI::program; // channel zero by default
+                       buf[1] = (Config->get_initial_program_change() & 0x7f);
+
+                       _mmc_port->midimsg (buf, sizeof (buf), 0);
+               }
+       } else if (PARAM_IS ("initial-program-change")) {
+
+               if (_mmc_port && Config->get_initial_program_change() >= 0) {
+                       MIDI::byte* buf = new MIDI::byte[2];
+                       
+                       buf[0] = MIDI::program; // channel zero by default
+                       buf[1] = (Config->get_initial_program_change() & 0x7f);
+                       // deliver_midi (_mmc_port, buf, 2);
+               }
+       } else if (PARAM_IS ("solo-mute-override")) {
+               catch_up_on_solo_mute_override ();
        }
 
        set_dirty ();