debug flag for session destruction and waf option for boost SP debug
[ardour.git] / libs / ardour / midi_ring_buffer.cc
index 5fcd3e82984bdf4eeb624200647e66a53c009597..df49b570c72adb4a7f4b530d9c10855633a81ed8 100644 (file)
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include "pbd/compose.h"
+
+#include "ardour/debug.h"
 #include "ardour/midi_ring_buffer.h"
 #include "ardour/midi_buffer.h"
 #include "ardour/event_type_map.h"
 
 using namespace std;
-
-namespace ARDOUR {
+using namespace ARDOUR;
 
 /** Read a block of MIDI events from buffer into a MidiBuffer.
  *
@@ -46,13 +48,15 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes
        while (this->read_space() >= sizeof(T) + sizeof(Evoral::EventType) + sizeof(uint32_t)) {
 
                this->full_peek(sizeof(T), (uint8_t*)&ev_time);
-               
+
                if (ev_time > end) {
-                       // cerr << "MRB event @ " << ev_time << " past end @ " << end << endl;
+                       DEBUG_TRACE (DEBUG::MidiDiskstreamIO, string_compose ("MRB event @ %1 past end @ %2\n", ev_time, end));
                        break;
                } else if (ev_time < start) {
-                       // cerr << "MRB event @ " << ev_time << " before start @ " << start << endl;
+                       DEBUG_TRACE (DEBUG::MidiDiskstreamIO, string_compose ("MRB event @ %1 before start @ %2\n", ev_time, start));
                        break;
+               } else {
+                       DEBUG_TRACE (DEBUG::MidiDiskstreamIO, string_compose ("MRB event @ %1 in range %2 .. %3\n", ev_time, start, end));
                }
 
                bool success = read_prefix(&ev_time, &ev_type, &ev_size);
@@ -80,12 +84,12 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes
                if (is_channel_event(status) && get_channel_mode() == FilterChannels) {
                        const uint8_t channel = status & 0x0F;
                        if (!(get_channel_mask() & (1L << channel))) {
-                               //cerr << "MRB skipping event due to channel mask" << endl;
+                               // cerr << "MRB skipping event due to channel mask" << endl;
                                this->skip(ev_size); // Advance read pointer to next event
                                continue;
                        }
                }
-               
+
                assert(ev_time >= start);
                ev_time -= start;
                ev_time += offset;
@@ -93,19 +97,21 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes
                // write the timestamp to address (write_loc - 1)
                uint8_t* write_loc = dst.reserve(ev_time, ev_size);
                if (write_loc == NULL) {
-                       cerr << "MRB: Unable to reserve space in buffer, event skipped";
+                       // cerr << "MRB: Unable to reserve space in buffer, event skipped";
                        continue;
                }
-               
+
                // write MIDI buffer contents
                success = Evoral::EventRingBuffer<T>::full_read(ev_size, write_loc);
-               
-#if 0
-               cerr << "wrote MidiEvent to Buffer: " << hex;
+
+#ifndef NDEBUG
+               DEBUG_TRACE (DEBUG::MidiDiskstreamIO, "wrote MidiEvent to Buffer: ");
                for (size_t i=0; i < ev_size; ++i) {
-                       cerr << (int) write_loc[i] << ' ';
+                       DEBUG_STR_SET(a, hex);
+                       DEBUG_STR(a) << "0x" << (int)write_loc[i] << ' ';
+                       DEBUG_TRACE (DEBUG::MidiDiskstreamIO, DEBUG_STR(a).str());
                }
-               cerr << dec << endl;
+               DEBUG_TRACE (DEBUG::MidiDiskstreamIO, "\n");
 #endif
 
                if (success) {
@@ -117,12 +123,12 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes
                        cerr << "WARNING: error reading event contents from MIDI ring" << endl;
                }
        }
-       
+
        return count;
 }
 template<typename T>
 void
-MidiRingBuffer<T>::dump(ostream& str) 
+MidiRingBuffer<T>::dump(ostream& str)
 {
        size_t rspace;
 
@@ -137,21 +143,21 @@ MidiRingBuffer<T>::dump(ostream& str)
        size_t read_ptr = g_atomic_int_get (&this->_read_ptr);
 
        str << "Dump @ " << read_ptr << endl;
-       
+
        while (1) {
                uint8_t* wp;
                uint8_t* data;
                size_t write_ptr;
 
 #define space(r,w) ((w > r) ? (w - r) : ((w - r + this->_size) % this->_size))
-               
+
                write_ptr  = g_atomic_int_get (&this->_write_ptr);
                if (space (read_ptr, write_ptr) < sizeof (T)) {
                        break;
                }
 
                wp = &this->_buf[read_ptr];
-               memcpy (&ev_time, wp, sizeof (T)); 
+               memcpy (&ev_time, wp, sizeof (T));
                read_ptr = (read_ptr + sizeof (T)) % this->_size;
                str << "time " << ev_time;
 
@@ -161,7 +167,7 @@ MidiRingBuffer<T>::dump(ostream& str)
                }
 
                wp = &this->_buf[read_ptr];
-               memcpy (&ev_type, wp, sizeof (ev_type)); 
+               memcpy (&ev_type, wp, sizeof (ev_type));
                read_ptr = (read_ptr + sizeof (ev_type)) % this->_size;
                str << " type " << ev_type;
 
@@ -172,7 +178,7 @@ MidiRingBuffer<T>::dump(ostream& str)
                }
 
                wp = &this->_buf[read_ptr];
-               memcpy (&ev_size, wp, sizeof (ev_size)); 
+               memcpy (&ev_size, wp, sizeof (ev_size));
                read_ptr = (read_ptr + sizeof (ev_size)) % this->_size;
                str << " size " << ev_size;
 
@@ -181,11 +187,11 @@ MidiRingBuffer<T>::dump(ostream& str)
                        str << "!OUT!\n";
                        break;
                }
-               
+
                data = new uint8_t[ev_size];
-               
+
                wp = &this->_buf[read_ptr];
-               memcpy (data, wp, ev_size); 
+               memcpy (data, wp, ev_size);
                read_ptr = (read_ptr + ev_size) % this->_size;
 
                for (uint32_t i = 0; i != ev_size; ++i) {
@@ -201,5 +207,3 @@ MidiRingBuffer<T>::dump(ostream& str)
 
 template class MidiRingBuffer<nframes_t>;
 
-} // namespace ARDOUR
-