32 #include <gtkmm/box.h>
33 #include <gtkmm/main.h>
34 #include <gtkmm/widget.h>
37 #include <lv2_ui_presets.h>
38 #include <lv2_uri_map.h>
39 #include <lv2_event_helpers.h>
41 #include <lv2types.hpp>
49 typedef std::vector<LV2UI_Descriptor*> GUIDescList;
55 GUIDescList& get_lv2g2g_descriptors();
104 template <
bool Required = true>
111 template <
class Derived>
struct I :
public Extension<Required> {
114 static void map_feature_handlers(FeatureHandlerMap& hmap) {
115 hmap[
"http://ll-plugins.nongnu.org/lv2/dev/ui#noUserResize"] =
120 static void handle_feature(
void* instance,
void* data) {
121 Derived* d =
reinterpret_cast<Derived*
>(instance);
140 template <
bool Required = true>
147 template <
class Derived>
struct I :
public Extension<Required> {
150 static void map_feature_handlers(FeatureHandlerMap& hmap) {
151 hmap[
"http://ll-plugins.nongnu.org/lv2/dev/ui#fixedSize"] =
156 static void handle_feature(
void* instance,
void* data) {
157 Derived* d =
reinterpret_cast<Derived*
>(instance);
175 template <
bool Required = true>
182 template <
class Derived>
struct I :
public Extension<Required> {
185 I() : m_hdesc(0), m_host_support(
false) { }
188 static void map_feature_handlers(FeatureHandlerMap& hmap) {
193 static void handle_feature(
void* instance,
void* data) {
194 Derived* d =
reinterpret_cast<Derived*
>(instance);
196 e->m_hdesc =
static_cast<LV2UI_Presets_Feature*
>(data);
197 e->m_ok = (e->m_hdesc != 0);
198 e->m_host_support = (e->m_hdesc != 0);
240 static void const* extension_data(
char const* uri) {
241 static LV2UI_Presets_GDesc desc = { &_preset_added,
244 &_current_preset_changed };
245 if (!std::strcmp(uri, LV2_UI_PRESETS_URI))
256 m_hdesc->change_preset(
static_cast<Derived*
>(
this)->controller(),
265 m_hdesc->save_preset(
static_cast<Derived*
>(
this)->controller(),
272 return m_host_support;
277 static void _preset_added(LV2UI_Handle gui,
283 static void _preset_removed(LV2UI_Handle gui,
288 static void _presets_cleared(LV2UI_Handle gui) {
292 static void _current_preset_changed(LV2UI_Handle gui,
298 LV2UI_Presets_Feature* m_hdesc;
312 template <
bool Required = true>
316 EVENT_BUFFER_SIZE = 4
323 template <
class Derived>
struct I : Extension<Required> {
326 I() : m_midi_type(0) {
327 m_buffer = lv2_event_buffer_new(
sizeof(LV2_Event) + EVENT_BUFFER_SIZE,
333 Derived* d =
static_cast<Derived*
>(
this);
335 uri_to_id(LV2_EVENT_URI,
"http://lv2plug.in/ns/ext/midi#MidiEvent");
336 m_event_buffer_format = d->
337 uri_to_id(LV2_UI_URI,
"http://lv2plug.in/ns/extensions/ui#Events");
338 return !Required || (m_midi_type && m_event_buffer_format);
353 bool write_midi(uint32_t port, uint32_t size,
const uint8_t* data) {
354 if (m_midi_type == 0)
356 LV2_Event_Buffer* buffer;
360 buffer = lv2_event_buffer_new(
sizeof(LV2_Event) + size, 0);
361 lv2_event_buffer_reset(m_buffer, 0, m_buffer->data);
362 LV2_Event_Iterator iter;
363 lv2_event_begin(&iter, m_buffer);
364 lv2_event_write(&iter, 0, 0, m_midi_type, size, data);
365 static_cast<Derived*
>(
this)->
366 write(port, m_buffer->header_size + m_buffer->capacity,
367 m_event_buffer_format, m_buffer);
373 uint32_t m_midi_type;
374 uint32_t m_event_buffer_format;
375 LV2_Event_Buffer* m_buffer;
391 template <
bool Required = true>
398 template <
class Derived>
struct I : Extension<Required> {
400 I() : m_osc_type(0) {
401 m_buffer = lv2_event_buffer_new(
sizeof(LV2_Event) + 256, 0);
405 Derived* d =
static_cast<Derived*
>(
this);
407 uri_to_id(LV2_EVENT_URI,
"http://lv2plug.in/ns/ext/osc#OscEvent");
408 m_event_buffer_format = d->
409 uri_to_id(LV2_UI_URI,
"http://lv2plug.in/ns/extensions/ui#Events");
410 return !Required || (m_osc_type && m_event_buffer_format);
415 bool write_osc(uint32_t port,
const char* path,
const char* types, ...) {
419 lv2_event_buffer_reset(m_buffer, 0, m_buffer->data);
420 LV2_Event_Iterator iter;
421 lv2_event_begin(&iter, m_buffer);
424 uint32_t size = lv2_osc_event_vsize(path, types, ap);
429 bool success = lv2_osc_buffer_vappend(&iter, 0, 0, m_osc_type,
430 path, types, size, ap);
433 static_cast<Derived*
>(
this)->
434 write(port, m_buffer->header_size + m_buffer->capacity,
435 m_event_buffer_format, m_buffer);
442 uint32_t m_event_buffer_format;
443 LV2_Event_Buffer* m_buffer;
466 template<
class Derived,
class Ext1 = End,
class Ext2 = End,
class Ext3 = End,
467 class Ext4 = End,
class Ext5 = End,
class Ext6 = End,
468 class Ext7 = End,
class Ext8 = End,
class Ext9 = End>
469 class GUI :
public Gtk::HBox,
public MixinTree<Derived,
470 Ext1, Ext2, Ext3, Ext4,
471 Ext5, Ext6, Ext7, Ext8, Ext9> {
480 m_features = s_features;
481 m_bundle_path = s_bundle_path;
487 FeatureHandlerMap hmap;
488 Derived::map_feature_handlers(hmap);
489 for (
const Feature*
const* iter = m_features; *iter != 0; ++iter) {
490 FeatureHandlerMap::iterator miter;
491 miter = hmap.find((*iter)->URI);
492 if (miter != hmap.end())
493 miter->second(
static_cast<Derived*
>(
this), (*iter)->data);
501 uint32_t format,
void const* buffer) { }
505 LV2UI_Descriptor* desc =
new LV2UI_Descriptor;
506 std::memset(desc, 0,
sizeof(LV2UI_Descriptor));
507 desc->URI = strdup(uri);
508 desc->instantiate = &Derived::create_ui_instance;
509 desc->cleanup = &Derived::delete_ui_instance;
510 desc->port_event = &Derived::_port_event;
511 desc->extension_data = &Derived::extension_data;
512 get_lv2g2g_descriptors().push_back(desc);
513 return get_lv2g2g_descriptors().size() - 1;
522 inline void write(uint32_t port, uint32_t buffer_size,
523 uint32_t format,
void const* buffer) {
524 (*m_wfunc)(m_ctrl, port, buffer_size, format, buffer);
529 write(port,
sizeof(
float), 0, &value);
540 return m_bundle_path;
556 friend class WriteMIDI<true>::I<Derived>;
557 friend class
WriteMIDI<false>::I<Derived>;
558 friend class WriteOSC<true>::I<Derived>;
559 friend class WriteOSC<false>::I<Derived>;
565 static LV2UI_Handle create_ui_instance(struct _LV2UI_Descriptor const*
567 char const* plugin_uri,
568 char const* bundle_path,
569 LV2UI_Write_Function write_func,
570 LV2UI_Controller ctrl,
571 LV2UI_Widget* widget,
572 Feature const* const* features) {
578 s_wfunc = write_func;
584 Gtk::Main::init_gtkmm_internals();
587 Derived* t =
new Derived(plugin_uri);
588 *widget =
static_cast<Gtk::Widget*
>(t)->gobj();
592 return reinterpret_cast<LV2UI_Handle
>(t);
602 static void delete_ui_instance(LV2UI_Handle instance) {
603 delete static_cast<Derived*
>(instance);
610 static void _port_event(LV2UI_Handle instance, uint32_t port,
611 uint32_t buffer_size, uint32_t format,
612 void const* buffer) {
613 static_cast<Derived*
>(instance)->
port_event(port, buffer_size,
619 LV2UI_Write_Function m_wfunc;
620 LV2::Feature
const*
const* m_features;
621 char const* m_bundle_path;
624 static LV2UI_Write_Function s_wfunc;
625 static LV2::Feature
const*
const* s_features;
626 static char const* s_bundle_path;
632 template<
class Derived,
class Ext1,
class Ext2,
class Ext3,
class Ext4,
633 class Ext5,
class Ext6,
class Ext7,
class Ext8,
class Ext9>
634 void* GUI<Derived, Ext1, Ext2, Ext3, Ext4,
635 Ext5, Ext6, Ext7, Ext8, Ext9>::s_ctrl = 0;
637 template<
class Derived,
class Ext1,
class Ext2,
class Ext3,
class Ext4,
638 class Ext5,
class Ext6,
class Ext7,
class Ext8,
class Ext9>
639 LV2UI_Write_Function GUI<Derived, Ext1, Ext2, Ext3, Ext4,
640 Ext5, Ext6, Ext7, Ext8, Ext9>::s_wfunc = 0;
642 template<
class Derived,
class Ext1,
class Ext2,
class Ext3,
class Ext4,
643 class Ext5,
class Ext6,
class Ext7,
class Ext8,
class Ext9>
644 LV2::Feature
const*
const* GUI<Derived, Ext1, Ext2, Ext3, Ext4,
645 Ext5, Ext6, Ext7, Ext8, Ext9>::s_features = 0;
647 template<
class Derived,
class Ext1,
class Ext2,
class Ext3,
class Ext4,
648 class Ext5,
class Ext6,
class Ext7,
class Ext8,
class Ext9>
649 char const* GUI<Derived, Ext1, Ext2, Ext3, Ext4,
650 Ext5, Ext6, Ext7, Ext8, Ext9>::s_bundle_path = 0;
Definition: lv2gui.hpp:471
static int register_class(char const *uri)
Definition: lv2gui.hpp:504
void write_control(uint32_t port, float value)
Definition: lv2gui.hpp:528
char const * bundle_path() const
Definition: lv2gui.hpp:539
void * controller()
Definition: lv2gui.hpp:547
void port_event(uint32_t port, uint32_t buffer_size, uint32_t format, void const *buffer)
Definition: lv2gui.hpp:500
LV2::Feature const *const * features()
Definition: lv2gui.hpp:534
void write(uint32_t port, uint32_t buffer_size, uint32_t format, void const *buffer)
Definition: lv2gui.hpp:522
Definition: lv2gui.hpp:147
Definition: lv2gui.hpp:141
Definition: lv2gui.hpp:111
Definition: lv2gui.hpp:105
Definition: lv2gui.hpp:182
void preset_removed(uint32_t number)
Definition: lv2gui.hpp:216
void change_preset(uint32_t preset)
Definition: lv2gui.hpp:254
void save_preset(uint32_t preset, char const *name)
Definition: lv2gui.hpp:263
bool host_supports_presets() const
Definition: lv2gui.hpp:271
void preset_added(uint32_t number, char const *name)
Definition: lv2gui.hpp:207
void presets_cleared()
Definition: lv2gui.hpp:223
void current_preset_changed(uint32_t number)
Definition: lv2gui.hpp:233
Definition: lv2gui.hpp:176
Definition: lv2gui.hpp:323
bool write_midi(uint32_t port, uint32_t size, const uint8_t *data)
Definition: lv2gui.hpp:353
Definition: lv2gui.hpp:313
Definition: lv2gui.hpp:398