add left/right side trim cursors and use them for region trimming, as appropriate
[ardour.git] / libs / ardour / midi_ring_buffer.cc
index f886eb84439dc9de3bb7c8581c7e9ef439525d36..2999621b70918d731be7b2517ff8dac685b9ad11 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;
+using namespace PBD;
 
 /** Read a block of MIDI events from buffer into a MidiBuffer.
  *
@@ -47,12 +50,14 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes
 
                this->full_peek(sizeof(T), (uint8_t*)&ev_time);
 
-               if (ev_time > end) {
-                       // cerr << "MRB event @ " << ev_time << " past end @ " << end << endl;
+               if (ev_time >= end) {
+                       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);
@@ -65,7 +70,7 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes
                if (ev_type == LoopEventType) {
                        /*ev_time -= start;
                          ev_time += offset;*/
-                       // cerr << "MRB loop boundary @ " << ev_time << endl;
+                       cerr << "MRB loop boundary @ " << ev_time << endl;
 
                        // Return without reading data or writing to buffer (loop events have no data)
                        // FIXME: This is not correct, loses events after the loop this cycle
@@ -93,19 +98,25 @@ 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";
+                       this->skip (ev_size); // Advance read pointer to next event
                        continue;
                }
 
                // write MIDI buffer contents
-               success = Evoral::EventRingBuffer<T>::full_read(ev_size, write_loc);
+               success = read_contents (ev_size, write_loc);
 
-#if 0
-               cerr << "wrote MidiEvent to Buffer: " << hex;
+#ifndef NDEBUG
+                DEBUG_STR_DECL(a);
+                DEBUG_STR_APPEND(a, string_compose ("wrote MidiEvent to Buffer (time=%1, start=%2 offset=%3)", ev_time, start, offset));
                for (size_t i=0; i < ev_size; ++i) {
-                       cerr << (int) write_loc[i] << ' ';
+                       DEBUG_STR_APPEND(a,hex);
+                       DEBUG_STR_APPEND(a,"0x");
+                       DEBUG_STR_APPEND(a,(int)write_loc[i]);
+                        DEBUG_STR_APPEND(a,' ');
                }
-               cerr << dec << endl;
+                DEBUG_STR_APPEND(a,'\n');
+                DEBUG_TRACE (DEBUG::MidiDiskstreamIO, DEBUG_STR(a).str());
 #endif
 
                if (success) {
@@ -201,5 +212,3 @@ MidiRingBuffer<T>::dump(ostream& str)
 
 template class MidiRingBuffer<nframes_t>;
 
-} // namespace ARDOUR
-