permit different sizes for audio playback & capture buffers
[ardour.git] / libs / ardour / lv2_event_buffer.cc
index 5405701da103b1f0bd7e733a924383481d3e6c3c..9bc61d93d15569a84ed343b08ccea83f1cf4a0b8 100644 (file)
@@ -1,17 +1,17 @@
 /*
-    Copyright (C) 2009 Paul Davis 
+    Copyright (C) 2009 Paul Davis
     Author: Dave Robillard
 
     This program is free software; you can redistribute it and/or modify it
     under the terms of the GNU General Public License as published by the Free
     Software Foundation; either version 2 of the License, or (at your option)
     any later version.
-    
+
     This program is distributed in the hope that it will be useful, but WITHOUT
     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     for more details.
-    
+
     You should have received a copy of the GNU General Public License along
     with this program; if not, write to the Free Software Foundation, Inc.,
     675 Mass Ave, Cambridge, MA 02139, USA.
@@ -20,9 +20,9 @@
 #define __STDC_LIMIT_MACROS 1
 #include <stdint.h>
 #include <iostream>
-#include "ardour/lv2_event_buffer.h"
 #include "lv2ext/lv2_event.h"
 #include "lv2ext/lv2_event_helpers.h"
+#include "ardour/lv2_event_buffer.h"
 
 using namespace std;
 
@@ -41,6 +41,11 @@ LV2EventBuffer::LV2EventBuffer(size_t capacity)
                throw std::bad_alloc();
        }
 
+       if (capacity == 0) {
+               cerr << "ERROR: LV2 event buffer of size 0 created." << endl;
+               capacity = 1024;
+       }
+
 #ifdef NO_POSIX_MEMALIGN
        _data = (LV2_Event_Buffer*)malloc(sizeof(LV2_Event_Buffer) + capacity);
        int ret = (_data != NULL) ? 0 : -1;
@@ -94,14 +99,14 @@ LV2EventBuffer::is_valid() const
 
 
 /** Read an event from the current position in the buffer
- * 
+ *
  * \return true if read was successful, or false if end of buffer reached
  */
 bool
 LV2EventBuffer::get_event(uint32_t* frames,
-                          uint32_t* subframes, 
-                          uint16_t* type, 
-                          uint16_t* size, 
+                          uint32_t* subframes,
+                          uint16_t* type,
+                          uint16_t* size,
                           uint8_t** data) const
 {
        if (lv2_event_is_valid(&_iter)) {
@@ -139,7 +144,8 @@ LV2EventBuffer::append(uint32_t       frames,
 #endif
 
        /*cout << "Appending event type " << type << ", size " << size
-               << " @ " << frames << "." << subframes << endl;*/
+               << " @ " << frames << "." << subframes << endl;
+       cout << "Buffer capacity " << _data->capacity << ", size " << _data->size << endl;*/
 
        if (!lv2_event_write(&_iter, frames, subframes, type, size, data)) {
                cerr << "ERROR: Failed to write event." << endl;
@@ -159,7 +165,7 @@ LV2EventBuffer::append(uint32_t       frames,
  * \return true on success
  */
 bool
-LV2EventBuffer::append(const LV2_Event_Buffer* buf)
+LV2EventBuffer::append(const LV2_Event_Buffer* /*buf*/)
 {
        uint8_t** data = NULL;
        bool      ret  = true;
@@ -182,7 +188,7 @@ LV2EventBuffer::append(const LV2_Event_Buffer* buf)
                _latest_frames = ev->frames;
                _latest_subframes = ev->subframes;
        }
-       
+
        return ret;
 }