move MidiPortManager from AudioEngine to Session
[ardour.git] / libs / ardour / session_state.cc
index 50905ef434716f3b1ecbee52ce7b31db6211e1f8..a7d7a0be4ca57503851db7bf79468f654082726d 100644 (file)
@@ -361,8 +361,8 @@ Session::second_stage_init ()
        // send_full_time_code (0);
        _engine.transport_locate (0);
 
-       AudioEngine::instance()->mmc().send (MIDI::MachineControlCommand (MIDI::MachineControl::cmdMmcReset));
-       AudioEngine::instance()->mmc().send (MIDI::MachineControlCommand (Timecode::Time ()));
+       _mmc->send (MIDI::MachineControlCommand (MIDI::MachineControl::cmdMmcReset));
+       _mmc->send (MIDI::MachineControlCommand (Timecode::Time ()));
 
        MIDI::Name::MidiPatchManager::instance().set_session (this);
 
@@ -983,6 +983,15 @@ Session::state (bool full_state)
 
        /* various options */
 
+       list<XMLNode*> midi_port_nodes = _midi_ports->get_midi_port_states();
+       if (!midi_port_nodes.empty()) {
+               XMLNode* midi_port_stuff = new XMLNode ("MIDIPorts");
+               for (list<XMLNode*>::const_iterator n = midi_port_nodes.begin(); n != midi_port_nodes.end(); ++n) {
+                       midi_port_stuff->add_child_nocopy (**n);
+               }
+               node->add_child_nocopy (*midi_port_stuff);
+       }
+
        node->add_child_nocopy (config.get_variables ());
 
        node->add_child_nocopy (ARDOUR::SessionMetadata::Metadata()->get_state());
@@ -1188,6 +1197,11 @@ Session::set_state (const XMLNode& node, int version)
                 Evoral::init_event_id_counter (atoi (prop->value()));
         }
 
+
+       if ((child = find_named_node (node, "MIDIPorts")) != 0) {
+               _midi_ports->set_midi_port_states (child->children());
+       }
+
        IO::disable_connecting ();
 
        Stateful::save_extra_xml (node);
@@ -3364,11 +3378,11 @@ Session::config_changed (std::string p, bool ours)
 
        } else if (p == "mmc-device-id" || p == "mmc-receive-id" || p == "mmc-receive-device-id") {
 
-               AudioEngine::instance()->mmc().set_receive_device_id (Config->get_mmc_receive_device_id());
+               _mmc->set_receive_device_id (Config->get_mmc_receive_device_id());
 
        } else if (p == "mmc-send-id" || p == "mmc-send-device-id") {
 
-               AudioEngine::instance()->mmc().set_send_device_id (Config->get_mmc_send_device_id());
+               _mmc->set_send_device_id (Config->get_mmc_send_device_id());
 
        } else if (p == "midi-control") {
 
@@ -3431,7 +3445,7 @@ Session::config_changed (std::string p, bool ours)
 
        } else if (p == "send-mmc") {
 
-               AudioEngine::instance()->mmc().enable_send (Config->get_send_mmc ());
+               _mmc->enable_send (Config->get_send_mmc ());
 
        } else if (p == "midi-feedback") {
 
@@ -3489,13 +3503,13 @@ Session::config_changed (std::string p, bool ours)
                        
        } else if (p == "initial-program-change") {
 
-               if (AudioEngine::instance()->mmc().output_port() && Config->get_initial_program_change() >= 0) {
+               if (_mmc->output_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);
 
-                       AudioEngine::instance()->mmc().output_port()->midimsg (buf, sizeof (buf), 0);
+                       _mmc->output_port()->midimsg (buf, sizeof (buf), 0);
                }
        } else if (p == "solo-mute-override") {
                // catch_up_on_solo_mute_override ();
@@ -3559,27 +3573,25 @@ Session::load_diskstreams_2X (XMLNode const & node, int)
 void
 Session::setup_midi_machine_control ()
 {
-       MIDI::MachineControl& mmc (AudioEngine::instance()->mmc ());
-
-       mmc.Play.connect_same_thread (*this, boost::bind (&Session::mmc_deferred_play, this, _1));
-       mmc.DeferredPlay.connect_same_thread (*this, boost::bind (&Session::mmc_deferred_play, this, _1));
-       mmc.Stop.connect_same_thread (*this, boost::bind (&Session::mmc_stop, this, _1));
-       mmc.FastForward.connect_same_thread (*this, boost::bind (&Session::mmc_fast_forward, this, _1));
-       mmc.Rewind.connect_same_thread (*this, boost::bind (&Session::mmc_rewind, this, _1));
-       mmc.Pause.connect_same_thread (*this, boost::bind (&Session::mmc_pause, this, _1));
-       mmc.RecordPause.connect_same_thread (*this, boost::bind (&Session::mmc_record_pause, this, _1));
-       mmc.RecordStrobe.connect_same_thread (*this, boost::bind (&Session::mmc_record_strobe, this, _1));
-       mmc.RecordExit.connect_same_thread (*this, boost::bind (&Session::mmc_record_exit, this, _1));
-       mmc.Locate.connect_same_thread (*this, boost::bind (&Session::mmc_locate, this, _1, _2));
-       mmc.Step.connect_same_thread (*this, boost::bind (&Session::mmc_step, this, _1, _2));
-       mmc.Shuttle.connect_same_thread (*this, boost::bind (&Session::mmc_shuttle, this, _1, _2, _3));
-       mmc.TrackRecordStatusChange.connect_same_thread (*this, boost::bind (&Session::mmc_record_enable, this, _1, _2, _3));
+       _mmc->Play.connect_same_thread (*this, boost::bind (&Session::mmc_deferred_play, this, _1));
+       _mmc->DeferredPlay.connect_same_thread (*this, boost::bind (&Session::mmc_deferred_play, this, _1));
+       _mmc->Stop.connect_same_thread (*this, boost::bind (&Session::mmc_stop, this, _1));
+       _mmc->FastForward.connect_same_thread (*this, boost::bind (&Session::mmc_fast_forward, this, _1));
+       _mmc->Rewind.connect_same_thread (*this, boost::bind (&Session::mmc_rewind, this, _1));
+       _mmc->Pause.connect_same_thread (*this, boost::bind (&Session::mmc_pause, this, _1));
+       _mmc->RecordPause.connect_same_thread (*this, boost::bind (&Session::mmc_record_pause, this, _1));
+       _mmc->RecordStrobe.connect_same_thread (*this, boost::bind (&Session::mmc_record_strobe, this, _1));
+       _mmc->RecordExit.connect_same_thread (*this, boost::bind (&Session::mmc_record_exit, this, _1));
+       _mmc->Locate.connect_same_thread (*this, boost::bind (&Session::mmc_locate, this, _1, _2));
+       _mmc->Step.connect_same_thread (*this, boost::bind (&Session::mmc_step, this, _1, _2));
+       _mmc->Shuttle.connect_same_thread (*this, boost::bind (&Session::mmc_shuttle, this, _1, _2, _3));
+       _mmc->TrackRecordStatusChange.connect_same_thread (*this, boost::bind (&Session::mmc_record_enable, this, _1, _2, _3));
 
        /* also handle MIDI SPP because its so common */
 
-       mmc.SPPStart.connect_same_thread (*this, boost::bind (&Session::spp_start, this));
-       mmc.SPPContinue.connect_same_thread (*this, boost::bind (&Session::spp_continue, this));
-       mmc.SPPStop.connect_same_thread (*this, boost::bind (&Session::spp_stop, this));
+       _mmc->SPPStart.connect_same_thread (*this, boost::bind (&Session::spp_start, this));
+       _mmc->SPPContinue.connect_same_thread (*this, boost::bind (&Session::spp_continue, this));
+       _mmc->SPPStop.connect_same_thread (*this, boost::bind (&Session::spp_stop, this));
 }
 
 boost::shared_ptr<Controllable>