1 
2 #include "../avtk/avtk.hxx"
3 
4 /// lv2 core / ui includes
5 #include "lv2/lv2plug.in/ns/lv2core/lv2.h"
6 #include "lv2/lv2plug.in/ns/extensions/ui/ui.h"
7 
8 #define AVTK_UI_URI "http://www.openavproductions.com/avtk#testUI"
9 
10 #include "../test_ui.hxx"
11 
12 
avtk_instantiate(const struct LV2UI_Descriptor * descriptor,const char * plugin_uri,const char * bundle_path,LV2UI_Write_Function write_function,LV2UI_Controller controller,LV2UI_Widget * widget,const LV2_Feature * const * features)13 static LV2UI_Handle avtk_instantiate(const struct LV2UI_Descriptor * descriptor,
14                                      const char * plugin_uri,
15                                      const char * bundle_path,
16                                      LV2UI_Write_Function write_function,
17                                      LV2UI_Controller controller,
18                                      LV2UI_Widget * widget,
19                                      const LV2_Feature * const * features)
20 {
21 	printf("init()\n");
22 
23 	if (strcmp(plugin_uri, "http://www.openavproductions.com/avtk") != 0) {
24 		fprintf(stderr, "AVTK_UI_URI error: this GUI does not support plugin with URI %s\n", plugin_uri);
25 		return NULL;
26 	}
27 
28 	LV2UI_Resize* resize = NULL;
29 	PuglNativeWindow parentXwindow = 0;
30 	for (int i = 0; features[i]; ++i) {
31 		printf("Feature %s\n", features[i]->URI );
32 		if (!strcmp(features[i]->URI, LV2_UI__parent)) {
33 			parentXwindow = (PuglNativeWindow)features[i]->data;
34 			printf("\tParent X11 ID %i\n", parentXwindow );
35 		} else if (!strcmp(features[i]->URI, LV2_UI__resize)) {
36 			resize = (LV2UI_Resize*)features[i]->data;
37 		}
38 
39 	}
40 	//write_function, controller,
41 	TestUI* t = new TestUI( parentXwindow );
42 
43 	*widget = (void*)t->getNativeHandle();
44 
45 	printf("init() - returning\n");
46 
47 	if (resize) {
48 		resize->ui_resize(resize->handle, t->w(), t->h() );
49 	}
50 
51 	return t;
52 }
53 
avtk_cleanup(LV2UI_Handle ui)54 static void avtk_cleanup(LV2UI_Handle ui)
55 {
56 	printf("cleanup()\n");
57 	delete (TestUI*)ui;
58 }
59 
avtk_port_event(LV2UI_Handle handle,uint32_t port_index,uint32_t buffer_size,uint32_t format,const void * buffer)60 static void avtk_port_event(LV2UI_Handle handle,
61                             uint32_t port_index,
62                             uint32_t buffer_size,
63                             uint32_t format,
64                             const void * buffer)
65 {
66 	TestUI* ui = (TestUI*)handle;
67 	printf("port()\n");
68 	ui->redraw();
69 }
70 
avtk_idle(LV2UI_Handle handle)71 static int avtk_idle(LV2UI_Handle handle)
72 {
73 	//printf("idle()\n");
74 	TestUI* ui = (TestUI*)handle;
75 	ui->idle();
76 	return 0;
77 }
78 
79 static const LV2UI_Idle_Interface idle_iface = { avtk_idle };
80 
81 static const void*
avtk_extension_data(const char * uri)82 avtk_extension_data(const char* uri)
83 {
84 	if (!strcmp(uri, LV2_UI__idleInterface)) {
85 		return &idle_iface;
86 	}
87 	return NULL;
88 }
89 
90 static const LV2UI_Descriptor descriptor = {
91 	AVTK_UI_URI,
92 	avtk_instantiate,
93 	avtk_cleanup,
94 	avtk_port_event,
95 	avtk_extension_data
96 };
97 
lv2ui_descriptor(uint32_t index)98 LV2_SYMBOL_EXPORT const LV2UI_Descriptor* lv2ui_descriptor(uint32_t index)
99 {
100 	switch (index) {
101 	case 0:
102 		return &descriptor;
103 	default:
104 		return NULL;
105 	}
106 }
107 
108