- MidiBuffer& mbuf = get_midi(i);
- LV2Buffers::value_type b = _lv2_buffers.at(i * 2 + (input ? 0 : 1));
- LV2EventBuffer* ebuf = b.second;
-
- ebuf->reset();
- if (input) {
- for (MidiBuffer::iterator e = mbuf.begin(); e != mbuf.end(); ++e) {
- const Evoral::MIDIEvent<nframes_t> ev(*e, false);
- uint32_t type = LV2Plugin::midi_event_type();
- ebuf->append(ev.time(), 0, type, ev.size(), ev.buffer());
+ assert(count().get(DataType::MIDI) > i);
+
+ LV2Buffers::value_type b = _lv2_buffers.at(i * 2 + (input ? 0 : 1));
+ LV2_Evbuf* evbuf = b.second;
+
+ if (lv2_evbuf_get_capacity(evbuf) >= buffer_capacity) return;
+
+ lv2_evbuf_free(b.second);
+ _lv2_buffers.at(i * 2 + (input ? 0 : 1)) =
+ std::make_pair(false, lv2_evbuf_new(
+ buffer_capacity,
+ LV2_EVBUF_EVENT,
+ URIMap::instance().urids.atom_Chunk,
+ URIMap::instance().urids.atom_Sequence));
+}
+
+LV2_Evbuf*
+BufferSet::get_lv2_midi(bool input, size_t i, bool old_api)
+{
+ assert(count().get(DataType::MIDI) > i);
+
+ LV2Buffers::value_type b = _lv2_buffers.at(i * 2 + (input ? 0 : 1));
+ LV2_Evbuf* evbuf = b.second;
+
+ lv2_evbuf_set_type(evbuf, old_api ? LV2_EVBUF_EVENT : LV2_EVBUF_ATOM);
+ lv2_evbuf_reset(evbuf, input);
+ return evbuf;
+}
+
+void
+BufferSet::forward_lv2_midi(LV2_Evbuf* buf, size_t i, bool purge_ardour_buffer)
+{
+ MidiBuffer& mbuf = get_midi(i);
+ if (purge_ardour_buffer) {
+ mbuf.silence(0, 0);
+ }
+ for (LV2_Evbuf_Iterator i = lv2_evbuf_begin(buf);
+ lv2_evbuf_is_valid(i);
+ i = lv2_evbuf_next(i)) {
+ uint32_t frames, subframes, type, size;
+ uint8_t* data;
+ lv2_evbuf_get(i, &frames, &subframes, &type, &size, &data);
+ if (type == URIMap::instance().urids.midi_MidiEvent) {
+ mbuf.push_back(frames, size, data);