disable unused windows-vst / ALSA-MIDI code
[ardour.git] / libs / midi++2 / jack_midi_port.cc
index 162e2a5f1ba321ee7fd8f43098adbc41270d755f..05df3171fa46a0c721c71f913a7309e14e23a429 100644 (file)
@@ -40,6 +40,10 @@ using namespace MIDI;
 using namespace std;
 using namespace PBD;
 
+namespace Evoral {
+template class EventRingBuffer<timestamp_t>;
+}
+
 pthread_t JackMIDIPort::_process_thread;
 Signal0<void> JackMIDIPort::JackHalted;
 Signal0<void> JackMIDIPort::MakeConnections;
@@ -50,6 +54,7 @@ JackMIDIPort::JackMIDIPort (string const & name, Flags flags, jack_client_t* jac
        , _nframes_this_cycle (0)
        , _jack_client (jack_client)
        , _jack_port (0)
+       , _last_write_timestamp (0)
        , output_fifo (512)
        , input_fifo (1024)
        , xthread (true)
@@ -64,6 +69,7 @@ JackMIDIPort::JackMIDIPort (const XMLNode& node, jack_client_t* jack_client)
        , _nframes_this_cycle (0)
        , _jack_client (jack_client)
        , _jack_port (0)
+       , _last_write_timestamp (0)
        , output_fifo (512)
        , input_fifo (1024)
        , xthread (true)
@@ -76,7 +82,7 @@ JackMIDIPort::JackMIDIPort (const XMLNode& node, jack_client_t* jack_client)
 }
 
 void
-JackMIDIPort::init (string const & name, Flags flags)
+JackMIDIPort::init (const string& /*name*/, Flags /*flags*/)
 {
        if (!create_port ()) {
                _ok = true;
@@ -210,13 +216,20 @@ JackMIDIPort::write (const byte * msg, size_t msglen, timestamp_t timestamp)
 {
        int ret = 0;
 
+       if (!_jack_client || !_jack_port) {
+               /* poof ! make it just vanish into thin air, since we are no
+                  longer connected to JACK.
+               */
+               return msglen;
+       }
+
        if (!sends_output()) {
                return ret;
        }
        
        if (!is_process_thread()) {
 
-               Glib::Mutex::Lock lm (output_fifo_lock);
+               Glib::Threads::Mutex::Lock lm (output_fifo_lock);
                RingBuffer< Evoral::Event<double> >::rw_vector vec = { { 0, 0 }, { 0, 0} };
                
                output_fifo.get_write_vector (&vec);
@@ -244,8 +257,7 @@ JackMIDIPort::write (const byte * msg, size_t msglen, timestamp_t timestamp)
 
        } else {
 
-               // XXX This had to be temporarily commented out to make export work again
-               if (!(timestamp < _nframes_this_cycle)) {
+               if (timestamp >= _nframes_this_cycle) {
                        std::cerr << "attempting to write MIDI event of " << msglen << " bytes at time "
                                  << timestamp << " of " << _nframes_this_cycle
                                  << " (this will not work - needs a code fix)"
@@ -257,17 +269,21 @@ JackMIDIPort::write (const byte * msg, size_t msglen, timestamp_t timestamp)
                                timestamp = _last_write_timestamp;
                        } 
 
-                       if (jack_midi_event_write (jack_port_get_buffer (_jack_port, _nframes_this_cycle), 
-                                               timestamp, msg, msglen) == 0) {
+                       if ((ret = jack_midi_event_write (jack_port_get_buffer (_jack_port, _nframes_this_cycle), 
+                                                         timestamp, msg, msglen)) == 0) {
                                ret = msglen;
                                _last_write_timestamp = timestamp;
 
                        } else {
-                               ret = 0;
-                               cerr << "write of " << msglen << " failed, port holds "
+                               cerr << "write of " << msglen << " @ " << timestamp << " failed, port holds "
                                        << jack_midi_get_event_count (jack_port_get_buffer (_jack_port, _nframes_this_cycle))
-                                       << endl;
-                               // PBD::stacktrace (cerr, 20);
+                                    << " port is " << _jack_port
+                                    << " ntf = " << _nframes_this_cycle
+                                    << " buf = " << jack_port_get_buffer (_jack_port, _nframes_this_cycle)
+                                    << " ret = " << ret
+                                    << endl;
+                               PBD::stacktrace (cerr, 20);
+                               ret = 0;
                        }
                } else {
                        cerr << "write to JACK midi port failed: not currently in a process cycle." << endl;