-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui2.c
180 lines (147 loc) · 5.58 KB
/
ui2.c
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <stdio.h>
#include <SDL2/SDL.h>
#include "lv2/lv2plug.in/ns/ext/atom/atom.h"
#include "lv2/lv2plug.in/ns/ext/atom/forge.h"
#include "lv2/lv2plug.in/ns/ext/atom/util.h"
#include "lv2/lv2plug.in/ns/ext/patch/patch.h"
#include "lv2/lv2plug.in/ns/extensions/ui/ui.h"
#include <SDL2/SDL_syswm.h>
#include <xcb/xcb.h>
#define SDLMETER_UI_URI "http://m4l3z.abod.co/plugin/sdlmeter#ui"
#define SDLMETER_URI "http://m4l3z.abod.co/plugin/sdlmeter"
// Drawing area size
#define DAWIDTH (640)
#define DAHEIGHT (480)
const char* WINDOW_TITLE = "SDL Meter ";
typedef struct {
LV2UI_Write_Function write;
LV2UI_Controller controller;
LV2UI_Widget* widget;
SDL_Surface *sdlscreen;
SDL_Surface *meter;
SDL_Window* window;
void* parentXwindow;
}sdlmeterUI;
static LV2UI_Handle instantiate(const 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)
{
sdlmeterUI* ui = (sdlmeterUI*)malloc(sizeof(sdlmeterUI));
ui->write = write_function;
ui->controller = controller;
ui->sdlscreen = NULL;
ui->meter = NULL;
ui->widget = widget;
LV2UI_Resize *host_resize = NULL;
ui->parentXwindow = 0;
if (strcmp(plugin_uri, SDLMETER_URI) != 0) {
printf(stderr, "Error: this GUI does not support plugin with URI %s\n", plugin_uri);
return NULL;
}
for(int i =0; features[i]; i++)
{
if(!strcmp(features[i]->URI, LV2_UI__parent))
{
ui->parentXwindow = features[i]->data;
printf("Found parent window : %i", ui->parentXwindow);
}
else if(!strcmp(features[i]->URI, LV2_UI__resize))
host_resize = features[i]->data;
}
if(!ui->parentXwindow)
{
free(ui);
return NULL;
}
char winhack[100];
sprintf(winhack, "SDL_WINDOWID=%ld", ui->parentXwindow);
putenv(winhack);
//ui->window = SDL_CreateWindowFrom(ui->parentXwindow);
ui->window = SDL_CreateWindow("test", 0, 0, 640, 480, NULL);
if(!ui->window) printf("\n unable to create sdl window with winhack from %ld", ui->parentXwindow);
ui->sdlscreen= SDL_CreateRGBSurface(0, 640, 480, 32,
0, 0, 0, 0);
SDL_FillRect(ui->sdlscreen, NULL, SDL_MapRGB(ui->sdlscreen->format, 255, 0, 0));
SDL_BlitSurface(ui->sdlscreen, 0, SDL_GetWindowSurface(ui->window),0);
SDL_UpdateWindowSurface(ui->window );
*(uintptr_t *)widget = (uintptr_t)ui->widget;
if(host_resize)
host_resize->ui_resize(host_resize->handle, 640, 480);
SDL_Quit();
return (LV2UI_Handle) ui;
}
static void cleanup(LV2UI_Handle handle)
{
sdlmeterUI* ui = (sdlmeterUI*)handle;
SDL_Quit();
free(ui);
}
static int ui_show(LV2UI_Handle handle)
{
sdlmeterUI* ui = (sdlmeterUI*)handle;
// SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0,SDL_HWSURFACE | SDL_DOUBLEBUF );
/*
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption( WINDOW_TITLE, 0 );
SDL_FillRect(ui->screen, NULL, SDL_MapRGB(ui->screen->format, 255, 0, 0));
SDL_Flip(ui->screen);
SDL_UpdateRect(ui->screen ,0 ,0 ,0 ,0);
*/
//SDL_Init(SDL_INIT_VIDEO);
//SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0,SDL_HWSURFACE | SDL_DOUBLEBUF );
//SDL_Window* window =SDL_CreateWindowFrom((const void *) ui->widget);
//ui->screen= SDL_GetWindowSurface( ui->window );
//SDL_FillRect(ui->screen, NULL, SDL_MapRGB(ui->screen->format, 255, 0, 0));
//SDL_UpdateWindowSurface( ui->window );
//ui->widget = SDL_GetWindowID(window);
SDL_SetHint(SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT, "1");
ui->window = SDL_CreateWindowFrom(ui->parentXwindow);
if(!ui->window) {printf("\n couldnt create sdl window");}
ui->sdlscreen = SDL_CreateRGBSurface(0, 640, 480, 32, 0, 0, 0, 0);
SDL_BlitSurface(ui->sdlscreen, 0, SDL_GetWindowSurface(ui->window),0);
if(!SDL_UpdateWindowSurface(ui->window)) {printf("\n couldnt update ui");}
return 0;
}
static int ui_hide(LV2UI_Handle handle)
{
sdlmeterUI* ui = (sdlmeterUI*)handle;
SDL_Quit();
return 0;
}
static void send_ui_state(LV2UI_Handle handle)
{
sdlmeterUI* ui = (sdlmeterUI*)handle;
}
static void send_ui_disable(LV2UI_Handle handle)
{
sdlmeterUI* ui = (sdlmeterUI*)handle;
}
static void send_ui_enable(LV2UI_Handle handle)
{
sdlmeterUI* ui = (sdlmeterUI*)handle;
}
static void port_event(LV2UI_Handle handle, uint32_t port_index, uint32_t buffer_size, uint32_t format, const void* buffer)
{
sdlmeterUI* ui = (sdlmeterUI*)handle;
}
static const void*
extension_data(const char* uri)
{
return NULL;
}
static const LV2UI_Descriptor descriptor = {
SDLMETER_UI_URI,
instantiate,
cleanup,
port_event,
extension_data,
NULL
};
LV2_SYMBOL_EXPORT const LV2UI_Descriptor* lv2ui_descriptor(uint32_t index)
{
switch (index) {
case 0:
return &descriptor;
default:
return NULL;
}
}