/
powercut_ui_main.cxx
145 lines (123 loc) · 3.13 KB
/
powercut_ui_main.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/x.H>
#include "powercut_ui.h"
#include "lv2/lv2plug.in/ns/extensions/ui/ui.h"
#define POWERCUTUI_URI "http://ssj71.github.io/infamousPlugins/plugs.html#powercut_ui"
static LV2UI_Handle init_powercutUI(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)
{
if(strcmp(plugin_uri, POWERCUT_URI) != 0)
{
return 0;
}
PowerCutUI* self = new PowerCutUI();
if(!self) return 0;
LV2UI_Resize* resize = NULL;
self->controller = controller;
self->write_function = write_function;
void* parentXwindow = 0;
for (int i = 0; features[i]; ++i)
{
if (!strcmp(features[i]->URI, LV2_UI__parent))
{
parentXwindow = features[i]->data;
}
else if (!strcmp(features[i]->URI, LV2_UI__resize))
{
resize = (LV2UI_Resize*)features[i]->data;
}
}
self->ui = self->show();
fl_open_display();
// set host to change size of the window
// self->ui->size(.5*self->ui->w(), .5*self->ui->h());//I want it a bit smaller than I designed it
if (resize)
{
resize->ui_resize(resize->handle, self->ui->w(), self->ui->h());
}
fl_embed( self->ui,(Window)parentXwindow);
*widget = (LV2UI_Widget)fl_xid(self->ui);
return (LV2UI_Handle)self;
}
void cleanup_powercutUI(LV2UI_Handle ui)
{
PowerCutUI *self = (PowerCutUI*)ui;
delete self->ui;
delete self;
}
void powercutUI_port_event(LV2UI_Handle ui, uint32_t port_index, uint32_t buffer_size, uint32_t format, const void * buffer)
{
PowerCutUI *self = (PowerCutUI*)ui;
if(!format)
{
float val = *(float*)buffer;
switch(port_index)
{
case PULL_THE_PLUG:
self->power->value((int)val);
self->reel->trigger = val;
break;
case DECAY_TIME:
self->time->value(val);
self->reel->time = val/.06;
break;
case DECAY_CURVE:
self->curve->value(val);
self->reel->curve = val;
break;
}
}
}
static int
idle(LV2UI_Handle handle)
{
PowerCutUI* self = (PowerCutUI*)handle;
self->idle();
return 0;
}
static int
resize_func(LV2UI_Feature_Handle handle, int w, int h)
{
PowerCutUI* self = (PowerCutUI*)handle;
if(self && w>0 && h>0)
self->ui->size(w,h);
return 0;
}
static const LV2UI_Idle_Interface idle_iface = { idle };
static const LV2UI_Resize resize_ui = { 0, resize_func };
static const void*
extension_data(const char* uri)
{
if (!strcmp(uri, LV2_UI__idleInterface))
{
return &idle_iface;
}
if (!strcmp(uri, LV2_UI__resize))
{
return &resize_ui;
}
return NULL;
}
static const LV2UI_Descriptor powercutUI_descriptor = {
POWERCUTUI_URI,
init_powercutUI,
cleanup_powercutUI,
powercutUI_port_event,
extension_data
};
LV2_SYMBOL_EXPORT
const LV2UI_Descriptor* lv2ui_descriptor(uint32_t index)
{
switch (index) {
case 0:
return &powercutUI_descriptor;
default:
return NULL;
}
}