21 #ifndef LVTK_WRITE_MIDI_HPP 22 #define LVTK_WRITE_MIDI_HPP 24 #warning "WriteMIDI uses deprecated LV2 extensions. WriteMIDI will \ 25 probably not work correctly in a LV2 Rev 3 UI." 29 #include <lvtk/ext/event.hpp> 30 #include <lvtk/ext/urimap.hpp> 43 template <
bool Required = true>
51 template <
class Derived>
52 struct I : Behavior<Required>
55 I() : m_midi_type(0) {
56 m_buffer = lv2_event_buffer_new(
sizeof(LV2_Event) + EVENT_BUFFER_SIZE,
62 Derived* d =
static_cast<Derived*
>(
this);
64 uri_to_id(LV2_EVENT_URI,
"http://lv2plug.in/ns/ext/midi#MidiEvent");
65 m_event_buffer_format = d->
66 uri_to_id(LV2_UI_URI,
"http://lv2plug.in/ns/extensions/ui#Events");
68 if (m_midi_type != 0) {
69 std::clog<<
" [LV2::WriteMIDI] Host does not map (\"" 71 <<
"\", \"http://lv2plug.in/ns/ext/midi#MidiEvent\") " 72 <<
"to any valid ID.\n";
74 if (m_event_buffer_format != 0) {
75 std::clog<<
" [LV2::WriteMIDI] Host does not map (\"" 77 <<
"\", \"http://lv2plug.in/ns/extensions/ui#Events\") " 78 <<
"to any valid ID.\n";
80 if (!Required || (m_midi_type && m_event_buffer_format))
81 std::clog<<
" [LV2::WriteMIDI] Validation succeeded."<<std::endl;
83 std::clog<<
" [LV2::WriteMIDI] Validation failed."<<std::endl;
85 return !Required || (m_midi_type && m_event_buffer_format);
101 bool write_midi(uint32_t port, uint32_t size,
const uint8_t* data) {
104 std::clog<<
"[LV2::WriteMIDI] write_midi("<<port<<
", "<<size
106 for (uint32_t i = 0; i < size; ++i) {
109 std::clog<<std::hex<<std::setw(2)<<std::setfill(
'0')
110 <<
static_cast<unsigned>(data[i]);
112 std::clog<<
"\") -> ";
115 if (m_midi_type == 0) {
117 std::clog<<
"false (Host does not support MIDI writing)"<<std::endl;
121 LV2_Event_Buffer* buffer;
125 buffer = lv2_event_buffer_new(
sizeof(LV2_Event) + size, 0);
126 lv2_event_buffer_reset(m_buffer, 0, m_buffer->data);
127 LV2_Event_Iterator iter;
128 lv2_event_begin(&iter, m_buffer);
129 lv2_event_write(&iter, 0, 0, m_midi_type, size, data);
130 static_cast<Derived*
>(
this)->
131 write(port, m_buffer->header_size + m_buffer->capacity,
132 m_event_buffer_format, m_buffer);
137 std::clog<<
"true"<<std::endl;
141 uint32_t m_midi_type;
142 uint32_t m_event_buffer_format;
143 LV2_Event_Buffer* m_buffer;
Definition: write_midi.hpp:44
bool write_midi(uint32_t port, uint32_t size, const uint8_t *data)
Definition: write_midi.hpp:101
Definition: write_midi.hpp:52
Definition: feature.hpp:34