Merging undo branch into trunk. It compiles and works for limited tests. Keep
[ardour.git] / libs / ardour / session_midi.cc
index 2b7afa354aa6cda898ff0544feb48d7397596bf4..821f894eeb1f4cb64d803c87c90c896c1e1fa16f 100644 (file)
 #include <midi++/port.h>
 #include <midi++/manager.h>
 #include <pbd/error.h>
-#include <pbd/lockmonitor.h>
+#include <glibmm/thread.h>
 #include <pbd/pthread_utils.h>
 
 #include <ardour/configuration.h>
 #include <ardour/audioengine.h>
 #include <ardour/session.h>
 #include <ardour/audio_track.h>
-#include <ardour/diskstream.h>
+#include <ardour/audio_diskstream.h>
 #include <ardour/slave.h>
 #include <ardour/cycles.h>
 
@@ -45,7 +45,7 @@
 
 using namespace std;
 using namespace ARDOUR;
-//using namespace sigc;
+using namespace PBD;
 using namespace MIDI;
 
 MachineControl::CommandSignature MMC_CommandSignature;
@@ -109,13 +109,6 @@ Session::set_midi_control (bool yn)
        set_dirty();
        poke_midi_thread ();
 
-       if (_midi_port) {
-               RWLockMonitor lm (route_lock, false, __LINE__, __FILE__);
-               for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
-                       (*i)->reset_midi_control (_midi_port, midi_control);
-               }
-       }
-
        ControlChanged (MidiControl); /* EMIT SIGNAL */
 }
 
@@ -166,6 +159,17 @@ Session::set_send_mmc (bool yn)
        ControlChanged (SendMMC); /* EMIT SIGNAL */
 }
 
+void
+Session::set_midi_feedback (bool yn)
+{
+}
+
+bool
+Session::get_midi_feedback () const
+{
+       return false;
+}
+
 bool
 Session::get_send_mtc () const
 {
@@ -308,6 +312,10 @@ Session::set_midi_port (string port_tag)
        }
 
        _midi_port = port;
+       
+       /* XXX need something to forward this to control protocols ? or just
+          use the signal below 
+       */
 
        Config->set_midi_port_name (port_tag);
 
@@ -449,42 +457,6 @@ Session::get_trace_midi_output(MIDI::Port *port)
 
 }
 
-
-void
-Session::set_midi_feedback (bool yn)
-{
-       if (_midi_port == 0) {
-               return;
-       }
-       
-       midi_feedback = yn;
-       set_dirty();
-
-       if (yn) {
-               /* make sure the feedback thread is alive */
-               start_feedback ();
-       } else {
-               /* maybe put the feedback thread to sleep */
-               stop_feedback ();
-       }
-
-       ControlChanged (MidiFeedback); /* EMIT SIGNAL */
-
-       send_all_midi_feedback ();
-}
-
-void
-Session::send_all_midi_feedback ()
-{
-       if (midi_feedback) {
-               // send out current state of all routes
-               RWLockMonitor lm (route_lock, false, __LINE__, __FILE__);
-               for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
-                       (*i)->send_all_midi_feedback ();
-               }
-       }
-}
-
 void
 Session::setup_midi_control ()
 {
@@ -622,7 +594,7 @@ Session::mmc_record_strobe (MIDI::MachineControl &mmc)
                */
                
                save_state ("", true);
-               atomic_set (&_record_status, Enabled);
+               g_atomic_int_set (&_record_status, Enabled);
                RecordStateChanged (); /* EMIT SIGNAL */
                
                request_transport_speed (1.0);
@@ -637,7 +609,7 @@ void
 Session::mmc_record_exit (MIDI::MachineControl &mmc)
 {
        if (mmc_control) {
-               disable_record ();
+               disable_record (false);
        }
 }
 
@@ -745,7 +717,7 @@ Session::mmc_locate (MIDI::MachineControl &mmc, const MIDI::byte* mmc_tc)
        }
 
        jack_nframes_t target_frame;
-       SMPTE_Time smpte;
+       SMPTE::Time smpte;
 
        smpte.hours = mmc_tc[0] & 0xf;
        smpte.minutes = mmc_tc[1];
@@ -804,12 +776,12 @@ Session::mmc_record_enable (MIDI::MachineControl &mmc, size_t trk, bool enabled)
        if (mmc_control) {
 
                RouteList::iterator i;
-               RWLockMonitor (route_lock, false, __LINE__, __FILE__);
+               boost::shared_ptr<RouteList> r = routes.reader();
                
-               for (i = routes.begin(); i != routes.end(); ++i) {
+               for (i = r->begin(); i != r->end(); ++i) {
                        AudioTrack *at;
 
-                       if ((at = dynamic_cast<AudioTrack*>(*i)) != 0) {
+                       if ((at = dynamic_cast<AudioTrack*>((*i).get())) != 0) {
                                if (trk == at->remote_control_id()) {
                                        at->set_record_enable (enabled, &mmc);
                                        break;
@@ -879,7 +851,7 @@ Session::send_full_time_code ()
 
 {
        MIDI::byte msg[10];
-       SMPTE_Time smpte;
+       SMPTE::Time smpte;
 
        if (_mtc_port == 0 || !send_mtc) {
                return 0;
@@ -905,7 +877,7 @@ Session::send_full_time_code ()
                outbound_mtc_smpte_frame = _transport_frame;
                if (((mtc_smpte_bits >> 5) != MIDI::MTC_25_FPS) && (transmitting_smpte_time.frames % 2)) {
                        // start MTC quarter frame transmission on an even frame
-                       smpte_increment( transmitting_smpte_time );
+                       SMPTE::increment( transmitting_smpte_time );
                        outbound_mtc_smpte_frame += (jack_nframes_t) _frames_per_smpte_frame;
                }
        }
@@ -929,7 +901,7 @@ Session::send_full_time_code ()
        msg[8] = smpte.frames;
 
        {
-               LockMonitor lm (midi_lock, __LINE__, __FILE__);
+               Glib::Mutex::Lock lm (midi_lock);
     
                if (_mtc_port->midimsg (msg, sizeof (msg))) {
                        error << _("Session: could not send full MIDI time code") << endmsg;
@@ -961,7 +933,7 @@ Session::send_midi_time_code ()
 
                // Send quarter frames up to current time
                {
-                       LockMonitor lm (midi_lock, __LINE__, __FILE__);
+                       Glib::Mutex::Lock lm (midi_lock);
 
                        switch(next_quarter_frame_to_send) {
                        case 0:
@@ -1006,8 +978,8 @@ Session::send_midi_time_code ()
                                // Wrap quarter frame counter
                                next_quarter_frame_to_send = 0;
                                // Increment smpte time twice
-                               smpte_increment( transmitting_smpte_time );
-                               smpte_increment( transmitting_smpte_time );        
+                               SMPTE::increment( transmitting_smpte_time );
+                               SMPTE::increment( transmitting_smpte_time );        
                                // Re-calculate timing of first quarter frame
                                smpte_to_sample( transmitting_smpte_time, outbound_mtc_smpte_frame, true /* use_offset */, false );
                                // Compensate for audio latency
@@ -1045,7 +1017,7 @@ Session::deliver_mmc (MIDI::MachineControl::Command cmd, jack_nframes_t where)
 {
        using namespace MIDI;
        int nbytes = 4;
-       SMPTE_Time smpte;
+       SMPTE::Time smpte;
 
        if (_mmc_port == 0 || !send_mmc) {
                return;
@@ -1096,7 +1068,7 @@ Session::deliver_mmc (MIDI::MachineControl::Command cmd, jack_nframes_t where)
 
                mmc_buffer[nbytes++] = 0xf7; // terminate SysEx/MMC message
 
-               LockMonitor lm (midi_lock, __LINE__, __FILE__);
+               Glib::Mutex::Lock lm (midi_lock);
 
                if (_mmc_port->write (mmc_buffer, nbytes) != nbytes) {
                        error << string_compose(_("MMC: cannot send command %1%2%3"), &hex, cmd, &dec) << endmsg;
@@ -1272,7 +1244,7 @@ Session::midi_thread_work ()
        bool restart;
        vector<MIDI::Port*> ports;
 
-       PBD::ThreadCreated (pthread_self(), X_("MIDI"));
+       PBD::ThreadCreatedWithRequestSize (pthread_self(), X_("MIDI"), 2048);
 
        memset (&rtparam, 0, sizeof (rtparam));
        rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
@@ -1483,14 +1455,7 @@ Session::get_mmc_control () const
 {
        return mmc_control;
 }
-bool
-Session::get_midi_feedback () const
-{
-       /* since this a "write" function we have to check the port as well 
-          as the control toggle.
-       */
-       return _midi_port && midi_feedback;
-}
+
 bool
 Session::get_midi_control () const
 {