get non-JACK MIDI I/O working again, with debug tracing, naturally
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 1 Dec 2009 17:11:11 +0000 (17:11 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 1 Dec 2009 17:11:11 +0000 (17:11 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@6252 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/debug.h
libs/ardour/debug.cc
libs/ardour/session_midi.cc

index f4170acfeb5afeb8f07755705b33fdfb449d0a0d..2998771dbacc1b7e7f011e4a331e9e69dd54de13 100644 (file)
@@ -50,6 +50,7 @@ namespace ARDOUR {
                        Transport = 0x400,
                        Slave = 0x800,
                        SessionEvents = 0x800,
+                       MidiIO = 0x1000
                };
        }
 
index f6ea85f94667226082205392b568438ece039fa5..037007497d1f6ec2fecd7adfeacc8ae891b8e0c7 100644 (file)
@@ -88,6 +88,8 @@ ARDOUR::parse_debug_options (const char* str)
                        bits |= ARDOUR::DEBUG::Slave;
                } else if (strncasecmp (p, "sessionevents", strlen (p)) == 0) {
                        bits |= ARDOUR::DEBUG::SessionEvents;
+               } else if (strncasecmp (p, "midiio", strlen (p)) == 0) {
+                       bits |= ARDOUR::DEBUG::MidiIO;
                }
 
                p = strtok_r (0, ",", &sp);
@@ -115,4 +117,5 @@ ARDOUR::list_debug_options ()
        cerr << "\tTransport" << endl;
        cerr << "\tSlave" << endl;
        cerr << "\tSessionEvents" << endl;
+       cerr << "\tMidiIO" << endl;
 }
index 3442ac09a16fb8ef462ca96e809e47a1e9f339e4..45642749e2fe897ab1adc83f920cae24423e91bb 100644 (file)
 
 #include <boost/shared_ptr.hpp>
 
+
 #include "midi++/mmc.h"
 #include "midi++/port.h"
 #include "midi++/manager.h"
 #include "pbd/error.h"
-#include <glibmm/thread.h>
 #include "pbd/pthread_utils.h"
 
 #include "ardour/configuration.h"
@@ -1118,7 +1118,7 @@ Session::midi_thread_work ()
                        pfd[nfds].fd = _mmc_port->selectable();
                        pfd[nfds].events = POLLIN|POLLHUP|POLLERR;
                        ports[nfds] = _mmc_port;
-                       //cerr << "MIDI port " << nfds << " = MMC @ " << _mmc_port << endl;
+                       DEBUG_TRACE (DEBUG::MidiIO, string_compose ("set up port #%1 for mmc @ %2\n", nfds, _mmc_port));
                        nfds++;
                }
 
@@ -1131,7 +1131,7 @@ Session::midi_thread_work ()
                        pfd[nfds].fd = _mtc_port->selectable();
                        pfd[nfds].events = POLLIN|POLLHUP|POLLERR;
                        ports[nfds] = _mtc_port;
-                       //cerr << "MIDI port " << nfds << " = MTC @ " << _mtc_port << endl;
+                       DEBUG_TRACE (DEBUG::MidiIO, string_compose ("set up port #%1 for mtc @ %2\n", nfds, _mtc_port));
                        nfds++;
                }
 
@@ -1139,6 +1139,7 @@ Session::midi_thread_work ()
                        pfd[nfds].fd = _midi_clock_port->selectable();
                        pfd[nfds].events = POLLIN|POLLHUP|POLLERR;
                        ports[nfds] = _midi_clock_port;
+                       DEBUG_TRACE (DEBUG::MidiIO, string_compose ("set up port #%1 for midi clock @ %2\n", nfds, _midi_clock_port));
                        nfds++;
                }
 
@@ -1150,7 +1151,7 @@ Session::midi_thread_work ()
                        pfd[nfds].fd = _midi_port->selectable();
                        pfd[nfds].events = POLLIN|POLLHUP|POLLERR;
                        ports[nfds] = _midi_port;
-                       // cerr << "MIDI port " << nfds << " = MIDI @ " << _midi_port << endl;
+                       DEBUG_TRACE (DEBUG::MidiIO, string_compose ("set up port #%1 for midi @ %2\n", nfds, _midi_port));
                        nfds++;
                }
 
@@ -1161,7 +1162,7 @@ Session::midi_thread_work ()
                }
 
          again:
-               // cerr << "MIDI poll on " << nfds << " for " << timeout << endl;
+               DEBUG_TRACE (DEBUG::MidiIO, string_compose ("MIDI poll on %1 fds for %2\n", nfds, timeout));
                if (poll (pfd, nfds, timeout) < 0) {
                        if (errno == EINTR) {
                                /* gdb at work, perhaps */
@@ -1172,7 +1173,7 @@ Session::midi_thread_work ()
 
                        break;
                }
-               // cerr << "MIDI thread wakes at " << get_cycles () << endl;
+               DEBUG_TRACE (DEBUG::MidiIO, "MIDI thread awake\n");
 
                fds_ready = 0;
 
@@ -1186,8 +1187,8 @@ Session::midi_thread_work ()
                if (pfd[0].revents & POLLIN) {
 
                        char foo[16];
-
-                       // cerr << "MIDI request FIFO ready\n";
+                       
+                       DEBUG_TRACE (DEBUG::MidiIO, "MIDI request FIFO ready\n");
                        fds_ready++;
 
                        /* empty the pipe of all current requests */
@@ -1216,12 +1217,13 @@ Session::midi_thread_work ()
                                switch (request->type) {
                                case MIDIRequest::PortChange:
                                        /* restart poll with new ports */
-                                       // cerr << "rebind\n";
+                                       DEBUG_TRACE (DEBUG::MidiIO, "rebind\n");
                                        restart = true;
                                        break;
 
                                case MIDIRequest::Quit:
                                        delete request;
+                                       DEBUG_TRACE (DEBUG::MidiIO, "thread quit\n");
                                        pthread_exit_pbd (0);
                                        /*NOTREACHED*/
                                        break;
@@ -1237,18 +1239,26 @@ Session::midi_thread_work ()
                }
 
                if (restart) {
+                       DEBUG_TRACE (DEBUG::MidiIO, "ports changed, restart poll\n");
+                       restart = false;
                        continue;
                }
 
                /* now read the rest of the ports */
 
                for (int p = 1; p < nfds; ++p) {
+
+                       DEBUG_STR_SET(foo, "port #%1 revents = ");
+                       DEBUG_STR(foo) << hex << pfd[p].revents << dec << endl;
+                       DEBUG_TRACE (DEBUG::MidiIO, string_compose (DEBUG_STR(foo).str(), p));
+
                        if ((pfd[p].revents & ~POLLIN)) {
                                // error << string_compose(_("Transport: error polling MIDI port %1 (revents =%2%3%4"), p, &hex, pfd[p].revents, &dec) << endmsg;
                                break;
                        }
 
                        if (pfd[p].revents & POLLIN) {
+                               DEBUG_TRACE (DEBUG::MidiIO, string_compose ("MIDI fd # %1 has data ready\n", p));
                                fds_ready++;
                                ports[p]->parse ();
                        }
@@ -1258,6 +1268,7 @@ Session::midi_thread_work ()
 
                if (fds_ready < 2 && timeout != -1) {
 
+                       DEBUG_TRACE (DEBUG::MidiIO, "Check timeouts\n");
                        for (MidiTimeoutList::iterator i = midi_timeouts.begin(); i != midi_timeouts.end(); ) {
 
                                MidiTimeoutList::iterator tmp;