trying without pugl

This commit is contained in:
Stefano D'Angelo 2025-03-18 13:53:40 +01:00
parent b3da04681d
commit 1a4d158bc0
4 changed files with 424 additions and 251 deletions

View File

@ -18,21 +18,20 @@
* File author: Stefano D'Angelo, Paolo Marrone * File author: Stefano D'Angelo, Paolo Marrone
*/ */
#include <pugl/pugl.h> #if defined(_WIN32) || defined(__CYGWIN__)
#include <pugl/cairo.h> #elif defined(__APPLE__)
#include <cairo.h> #else
# include <X11/Xlib.h>
#endif
typedef struct { typedef struct {
void * widget; void * widget;
PuglWorld * world;
PuglView * view;
double fw; #if defined(_WIN32) || defined(__CYGWIN__)
double fh; #elif defined(__APPLE__)
double x; #else
double y; Display * display;
double w; #endif
double h;
float gain; float gain;
float delay; float delay;
@ -40,267 +39,76 @@ typedef struct {
char bypass; char bypass;
float y_z1; float y_z1;
int param_down; unsigned int width;
unsigned int height;
plugin_ui_callbacks cbs; plugin_ui_callbacks cbs;
} plugin_ui; } plugin_ui;
#define WIDTH 600.0 #define WIDTH 600.0
#define HEIGHT 400.0 #define HEIGHT 400.0
#define RATIO (WIDTH / HEIGHT)
#define INV_RATIO (HEIGHT / WIDTH)
static void plugin_ui_get_default_size(uint32_t *width, uint32_t *height) { static void plugin_ui_get_default_size(uint32_t *width, uint32_t *height) {
*width = WIDTH; *width = WIDTH;
*height = HEIGHT; *height = HEIGHT;
} }
static void plugin_ui_update_geometry(plugin_ui *instance) {
//PuglRect frame = puglGetFrame(instance->view);
//instance->fw = frame.width;
//instance->fh = frame.height;
//if (frame.width == 0 || frame.height == 0)
// return;
PuglArea size = puglGetSizeHint(instance->view, PUGL_CURRENT_SIZE);
instance->fw = size.width;
instance->fh = size.height;
if (instance->fw == 0 || instance->fh == 0)
return;
if (instance->fw / instance->fh > RATIO) {
instance->w = RATIO * instance->fh;
instance->h = instance->fh;
instance->x = 0.5 * (instance->fw - instance->w);
instance->y = 0.0;
} else {
instance->w = instance->fw;
instance->h = INV_RATIO * instance->fw;
instance->x = 0.0;
instance->y = 0.5 * (instance->fh - instance->h);
}
}
static void plugin_ui_draw(plugin_ui *instance) {
cairo_t *cr = (cairo_t *)puglGetContext(instance->view);
double x = instance->x;
double y = instance->y;
double w = instance->w;
double h = instance->h;
cairo_set_line_width(cr, 0.005 * h);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_paint(cr);
cairo_set_source_rgb(cr, 0.2, 0.2, 0.2);
cairo_rectangle(cr, x, y, w, h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, x + 0.1 * w, y + 0.15 * h, 0.8 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_rectangle(cr, x + 0.1 * w, y + 0.15 * h, 0.8 * w * instance->gain, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
cairo_rectangle(cr, x + 0.1 * w, y + 0.15 * h, 0.8 * w, 0.1 * h);
cairo_stroke(cr);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, x + 0.1 * w, y + 0.3 * h, 0.8 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_rectangle(cr, x + 0.1 * w, y + 0.3 * h, 0.8 * w * instance->delay, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
cairo_rectangle(cr, x + 0.1 * w, y + 0.3 * h, 0.8 * w, 0.1 * h);
cairo_stroke(cr);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, x + 0.1 * w, y + 0.45 * h, 0.8 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_rectangle(cr, x + 0.1 * w, y + 0.45 * h, 0.8 * w * instance->cutoff, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
cairo_rectangle(cr, x + 0.1 * w, y + 0.45 * h, 0.8 * w, 0.1 * h);
cairo_stroke(cr);
if (instance->bypass)
cairo_set_source_rgb(cr, 1.0, 0, 0);
else
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
cairo_rectangle(cr, x + 0.4 * w, y + 0.6 * h, 0.2 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, x + 0.1 * w, y + 0.75 * h, 0.8 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_rectangle(cr, x + 0.1 * w, y + 0.75 * h, 0.8 * w * instance->y_z1, 0.1 * h);
cairo_fill(cr);
}
static PuglStatus plugin_ui_on_event(PuglView *view, const PuglEvent *event) {
switch (event->type) {
case PUGL_CONFIGURE:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
plugin_ui_update_geometry(instance);
puglObscureView(instance->view);
}
break;
case PUGL_BUTTON_PRESS:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
const PuglButtonEvent *ev = (const PuglButtonEvent *)event;
double x = instance->x;
double y = instance->y;
double w = instance->w;
double h = instance->h;
if (ev->x >= x + 0.1 * w && ev->x <= x + 0.9 * w
&& ev->y >= y + 0.15 * h && ev->y <= y + 0.25 * h) {
instance->param_down = 0;
instance->gain = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter_begin(instance->cbs.handle, 0, -60.f + 80.f * instance->gain);
puglObscureView(instance->view);
} else if (ev->x >= x + 0.1 * w && ev->x <= x + 0.9 * w
&& ev->y >= y + 0.3 * h && ev->y <= y + 0.4 * h) {
instance->param_down = 1;
instance->delay = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter_begin(instance->cbs.handle, 1, 1000.f * instance->delay);
puglObscureView(instance->view);
} else if (ev->x >= x + 0.1 * w && ev->x <= x + 0.9 * w
&& ev->y >= y + 0.45 * h && ev->y <= y + 0.55 * h) {
instance->param_down = 2;
instance->cutoff = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter_begin(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff));
puglObscureView(instance->view);
} else if (ev->x >= x + 0.4 * w && ev->x <= x + 0.6 * w
&& ev->y >= y + 0.6 * h && ev->y <= y + 0.7 * h) {
instance->param_down = 3;
}
}
break;
case PUGL_MOTION:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
const PuglMotionEvent *ev = (const PuglMotionEvent *)event;
double x = instance->x;
double w = instance->w;
float v = ev->x < x + 0.1 * w ? 0.f : (ev->x > x + 0.9 * w ? 1.f : (float)((ev->x - (x + 0.1 * w)) / (0.8 * w)));
switch (instance->param_down) {
case 0:
instance->gain = v;
instance->cbs.set_parameter(instance->cbs.handle, 0, -60.f + 80.f * instance->gain);
puglObscureView(instance->view);
break;
case 1:
instance->delay = v;
instance->cbs.set_parameter(instance->cbs.handle, 1, 1000.f * instance->delay);
puglObscureView(instance->view);
break;
case 2:
instance->cutoff = v;
instance->cbs.set_parameter(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff));
puglObscureView(instance->view);
break;
}
}
break;
case PUGL_BUTTON_RELEASE:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
const PuglButtonEvent *ev = (const PuglButtonEvent *)event;
double x = instance->x;
double y = instance->y;
double w = instance->w;
double h = instance->h;
if (instance->param_down == 3)
if (ev->x >= x + 0.4 * w && ev->x <= x + 0.6 * w
&& ev->y >= y + 0.6 * h && ev->y <= y + 0.7 * h) {
instance->bypass = !instance->bypass;
instance->cbs.set_parameter(instance->cbs.handle, 3, instance->bypass ? 1.f : 0.f);
puglObscureView(instance->view);
}
if (instance->param_down != -1) {
float v = ev->x < x + 0.1 * w ? 0.f : (ev->x > x + 0.9 * w ? 1.f : (float)((ev->x - (x + 0.1 * w)) / (0.8 * w)));
switch (instance->param_down) {
case 0:
instance->gain = v;
instance->cbs.set_parameter_end(instance->cbs.handle, 0, -60.f + 80.f * instance->gain);
puglObscureView(instance->view);
break;
case 1:
instance->delay = v;
instance->cbs.set_parameter_end(instance->cbs.handle, 1, 1000.f * instance->delay);
puglObscureView(instance->view);
break;
case 2:
instance->cutoff = v;
instance->cbs.set_parameter_end(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff));
puglObscureView(instance->view);
break;
}
instance->param_down = -1;
}
}
break;
case PUGL_EXPOSE:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
plugin_ui_update_geometry(instance); // I didn't expect this was needed here for X11 to work decently when resizing
plugin_ui_draw(instance);
}
break;
default:
break;
}
return PUGL_SUCCESS;
}
static plugin_ui *plugin_ui_create(char has_parent, void *parent, plugin_ui_callbacks *cbs) { static plugin_ui *plugin_ui_create(char has_parent, void *parent, plugin_ui_callbacks *cbs) {
plugin_ui *instance = malloc(sizeof(plugin_ui)); plugin_ui *instance = malloc(sizeof(plugin_ui));
if (instance == NULL) if (instance == NULL)
return NULL; return NULL;
instance->param_down = -1; #if defined(_WIN32) || defined(__CYGWIN__)
instance->world = puglNewWorld(PUGL_MODULE, 0); #elif defined(__APPLE__)
instance->view = puglNewView(instance->world); #else
puglSetSizeHint(instance->view, PUGL_DEFAULT_SIZE, WIDTH, HEIGHT); instance->display = XOpenDisplay(NULL);
puglSetViewHint(instance->view, PUGL_RESIZABLE, PUGL_TRUE); if (instance->display == NULL) {
puglSetHandle(instance->view, instance); free(instance);
puglSetBackend(instance->view, puglCairoBackend());
//PuglRect frame = { 0, 0, WIDTH, HEIGHT };
//puglSetFrame(instance->view, frame);
puglSetEventFunc(instance->view, plugin_ui_on_event);
if (has_parent)
puglSetParent(instance->view, (PuglNativeView)parent);
if (puglRealize(instance->view)) {
puglFreeView(instance->view);
puglFreeWorld(instance->world);
return NULL; return NULL;
} }
instance->widget = (void *)puglGetNativeView(instance->view); int s = DefaultScreen(instance->display);
Window w = XCreateSimpleWindow(instance->display, has_parent ? (Window)parent : RootWindow(instance->display, s), 0, 0, WIDTH, HEIGHT, 0, 0, 0);
XSelectInput(instance->display, w, ExposureMask | StructureNotifyMask);
XMapWindow(instance->display, w);
XSync(instance->display, False);
instance->widget = (void *)w;
instance->width = WIDTH;
instance->height = HEIGHT;
#endif
instance->cbs = *cbs; instance->cbs = *cbs;
//puglSetFrame(instance->view, frame); // Intentionally duplicated because of ardour/lv2/mac strange event order call
puglShow(instance->view, PUGL_SHOW_RAISE); // Cocoa calls events at this so it's better this happens late
return instance; return instance;
} }
static void plugin_ui_free(plugin_ui *instance) { static void plugin_ui_free(plugin_ui *instance) {
puglFreeView(instance->view); XDestroyWindow(instance->display, (Window)instance->widget);
puglFreeWorld(instance->world); XCloseDisplay(instance->display);
free(instance); free(instance);
} }
static void plugin_ui_idle(plugin_ui *instance) { static void plugin_ui_idle(plugin_ui *instance) {
puglUpdate(instance->world, 0); #if defined(_WIN32) || defined(__CYGWIN__)
#elif defined(__APPLE__)
#else
Window w = (Window)instance->widget;
while (XEventsQueued(instance->display, QueuedAfterFlush) > 0) {
XEvent e;
XNextEvent(instance->display, &e);
if (e.type == Expose) {
XClearWindow(instance->display, w);
GC gc = DefaultGC(instance->display, DefaultScreen(instance->display));
XSetForeground(instance->display, gc, 0xff0000);
XFillRectangle(instance->display, w, gc, 10, 10, instance->width - 20, instance->height - 20);
} else if (e.type == ConfigureNotify) {
XWindowAttributes attrs;
XGetWindowAttributes(instance->display, w, &attrs);
instance->width = attrs.width;
instance->height = attrs.height;
}
}
#endif
} }
static void plugin_ui_set_parameter(plugin_ui *instance, size_t index, float value) { static void plugin_ui_set_parameter(plugin_ui *instance, size_t index, float value) {
@ -322,5 +130,4 @@ static void plugin_ui_set_parameter(plugin_ui *instance, size_t index, float val
instance->y_z1 = 0.5f * value + 0.5f; instance->y_z1 = 0.5f * value + 0.5f;
break; break;
} }
puglObscureView(instance->view);
} }

326
test/plugin_ui_old.h Normal file
View File

@ -0,0 +1,326 @@
/*
* Tibia
*
* Copyright (C) 2024 Orastron Srl unipersonale
*
* Tibia is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Tibia is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tibia. If not, see <http://www.gnu.org/licenses/>.
*
* File author: Stefano D'Angelo, Paolo Marrone
*/
#include <pugl/pugl.h>
#include <pugl/cairo.h>
#include <cairo.h>
typedef struct {
void * widget;
PuglWorld * world;
PuglView * view;
double fw;
double fh;
double x;
double y;
double w;
double h;
float gain;
float delay;
float cutoff;
char bypass;
float y_z1;
int param_down;
plugin_ui_callbacks cbs;
} plugin_ui;
#define WIDTH 600.0
#define HEIGHT 400.0
#define RATIO (WIDTH / HEIGHT)
#define INV_RATIO (HEIGHT / WIDTH)
static void plugin_ui_get_default_size(uint32_t *width, uint32_t *height) {
*width = WIDTH;
*height = HEIGHT;
}
static void plugin_ui_update_geometry(plugin_ui *instance) {
//PuglRect frame = puglGetFrame(instance->view);
//instance->fw = frame.width;
//instance->fh = frame.height;
//if (frame.width == 0 || frame.height == 0)
// return;
PuglArea size = puglGetSizeHint(instance->view, PUGL_CURRENT_SIZE);
instance->fw = size.width;
instance->fh = size.height;
if (instance->fw == 0 || instance->fh == 0)
return;
if (instance->fw / instance->fh > RATIO) {
instance->w = RATIO * instance->fh;
instance->h = instance->fh;
instance->x = 0.5 * (instance->fw - instance->w);
instance->y = 0.0;
} else {
instance->w = instance->fw;
instance->h = INV_RATIO * instance->fw;
instance->x = 0.0;
instance->y = 0.5 * (instance->fh - instance->h);
}
}
static void plugin_ui_draw(plugin_ui *instance) {
cairo_t *cr = (cairo_t *)puglGetContext(instance->view);
double x = instance->x;
double y = instance->y;
double w = instance->w;
double h = instance->h;
cairo_set_line_width(cr, 0.005 * h);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_paint(cr);
cairo_set_source_rgb(cr, 0.2, 0.2, 0.2);
cairo_rectangle(cr, x, y, w, h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, x + 0.1 * w, y + 0.15 * h, 0.8 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_rectangle(cr, x + 0.1 * w, y + 0.15 * h, 0.8 * w * instance->gain, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
cairo_rectangle(cr, x + 0.1 * w, y + 0.15 * h, 0.8 * w, 0.1 * h);
cairo_stroke(cr);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, x + 0.1 * w, y + 0.3 * h, 0.8 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_rectangle(cr, x + 0.1 * w, y + 0.3 * h, 0.8 * w * instance->delay, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
cairo_rectangle(cr, x + 0.1 * w, y + 0.3 * h, 0.8 * w, 0.1 * h);
cairo_stroke(cr);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, x + 0.1 * w, y + 0.45 * h, 0.8 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_rectangle(cr, x + 0.1 * w, y + 0.45 * h, 0.8 * w * instance->cutoff, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
cairo_rectangle(cr, x + 0.1 * w, y + 0.45 * h, 0.8 * w, 0.1 * h);
cairo_stroke(cr);
if (instance->bypass)
cairo_set_source_rgb(cr, 1.0, 0, 0);
else
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
cairo_rectangle(cr, x + 0.4 * w, y + 0.6 * h, 0.2 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
cairo_rectangle(cr, x + 0.1 * w, y + 0.75 * h, 0.8 * w, 0.1 * h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_rectangle(cr, x + 0.1 * w, y + 0.75 * h, 0.8 * w * instance->y_z1, 0.1 * h);
cairo_fill(cr);
}
static PuglStatus plugin_ui_on_event(PuglView *view, const PuglEvent *event) {
switch (event->type) {
case PUGL_CONFIGURE:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
plugin_ui_update_geometry(instance);
puglObscureView(instance->view);
}
break;
case PUGL_BUTTON_PRESS:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
const PuglButtonEvent *ev = (const PuglButtonEvent *)event;
double x = instance->x;
double y = instance->y;
double w = instance->w;
double h = instance->h;
if (ev->x >= x + 0.1 * w && ev->x <= x + 0.9 * w
&& ev->y >= y + 0.15 * h && ev->y <= y + 0.25 * h) {
instance->param_down = 0;
instance->gain = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter_begin(instance->cbs.handle, 0, -60.f + 80.f * instance->gain);
puglObscureView(instance->view);
} else if (ev->x >= x + 0.1 * w && ev->x <= x + 0.9 * w
&& ev->y >= y + 0.3 * h && ev->y <= y + 0.4 * h) {
instance->param_down = 1;
instance->delay = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter_begin(instance->cbs.handle, 1, 1000.f * instance->delay);
puglObscureView(instance->view);
} else if (ev->x >= x + 0.1 * w && ev->x <= x + 0.9 * w
&& ev->y >= y + 0.45 * h && ev->y <= y + 0.55 * h) {
instance->param_down = 2;
instance->cutoff = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter_begin(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff));
puglObscureView(instance->view);
} else if (ev->x >= x + 0.4 * w && ev->x <= x + 0.6 * w
&& ev->y >= y + 0.6 * h && ev->y <= y + 0.7 * h) {
instance->param_down = 3;
}
}
break;
case PUGL_MOTION:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
const PuglMotionEvent *ev = (const PuglMotionEvent *)event;
double x = instance->x;
double w = instance->w;
float v = ev->x < x + 0.1 * w ? 0.f : (ev->x > x + 0.9 * w ? 1.f : (float)((ev->x - (x + 0.1 * w)) / (0.8 * w)));
switch (instance->param_down) {
case 0:
instance->gain = v;
instance->cbs.set_parameter(instance->cbs.handle, 0, -60.f + 80.f * instance->gain);
puglObscureView(instance->view);
break;
case 1:
instance->delay = v;
instance->cbs.set_parameter(instance->cbs.handle, 1, 1000.f * instance->delay);
puglObscureView(instance->view);
break;
case 2:
instance->cutoff = v;
instance->cbs.set_parameter(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff));
puglObscureView(instance->view);
break;
}
}
break;
case PUGL_BUTTON_RELEASE:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
const PuglButtonEvent *ev = (const PuglButtonEvent *)event;
double x = instance->x;
double y = instance->y;
double w = instance->w;
double h = instance->h;
if (instance->param_down == 3)
if (ev->x >= x + 0.4 * w && ev->x <= x + 0.6 * w
&& ev->y >= y + 0.6 * h && ev->y <= y + 0.7 * h) {
instance->bypass = !instance->bypass;
instance->cbs.set_parameter(instance->cbs.handle, 3, instance->bypass ? 1.f : 0.f);
puglObscureView(instance->view);
}
if (instance->param_down != -1) {
float v = ev->x < x + 0.1 * w ? 0.f : (ev->x > x + 0.9 * w ? 1.f : (float)((ev->x - (x + 0.1 * w)) / (0.8 * w)));
switch (instance->param_down) {
case 0:
instance->gain = v;
instance->cbs.set_parameter_end(instance->cbs.handle, 0, -60.f + 80.f * instance->gain);
puglObscureView(instance->view);
break;
case 1:
instance->delay = v;
instance->cbs.set_parameter_end(instance->cbs.handle, 1, 1000.f * instance->delay);
puglObscureView(instance->view);
break;
case 2:
instance->cutoff = v;
instance->cbs.set_parameter_end(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff));
puglObscureView(instance->view);
break;
}
instance->param_down = -1;
}
}
break;
case PUGL_EXPOSE:
{
plugin_ui *instance = (plugin_ui *)puglGetHandle(view);
plugin_ui_update_geometry(instance); // I didn't expect this was needed here for X11 to work decently when resizing
plugin_ui_draw(instance);
}
break;
default:
break;
}
return PUGL_SUCCESS;
}
static plugin_ui *plugin_ui_create(char has_parent, void *parent, plugin_ui_callbacks *cbs) {
plugin_ui *instance = malloc(sizeof(plugin_ui));
if (instance == NULL)
return NULL;
instance->param_down = -1;
instance->world = puglNewWorld(PUGL_MODULE, 0);
instance->view = puglNewView(instance->world);
puglSetSizeHint(instance->view, PUGL_DEFAULT_SIZE, WIDTH, HEIGHT);
puglSetViewHint(instance->view, PUGL_RESIZABLE, PUGL_TRUE);
puglSetHandle(instance->view, instance);
puglSetBackend(instance->view, puglCairoBackend());
//PuglRect frame = { 0, 0, WIDTH, HEIGHT };
//puglSetFrame(instance->view, frame);
puglSetEventFunc(instance->view, plugin_ui_on_event);
if (has_parent)
puglSetParent(instance->view, (PuglNativeView)parent);
if (puglRealize(instance->view)) {
puglFreeView(instance->view);
puglFreeWorld(instance->world);
return NULL;
}
instance->widget = (void *)puglGetNativeView(instance->view);
instance->cbs = *cbs;
//puglSetFrame(instance->view, frame); // Intentionally duplicated because of ardour/lv2/mac strange event order call
puglShow(instance->view, PUGL_SHOW_RAISE); // Cocoa calls events at this so it's better this happens late
return instance;
}
static void plugin_ui_free(plugin_ui *instance) {
puglFreeView(instance->view);
puglFreeWorld(instance->world);
free(instance);
}
static void plugin_ui_idle(plugin_ui *instance) {
puglUpdate(instance->world, 0);
}
static void plugin_ui_set_parameter(plugin_ui *instance, size_t index, float value) {
switch (index) {
case 0:
instance->gain = 0.0125f * value + 0.75f;
break;
case 1:
instance->delay = 0.001f * value;
break;
case 2:
// (bad) approx log unmap
instance->cutoff = (1.0326554320337176f * value - 20.65310864067435f) / (value + 632.4555320336754f);
break;
case 3:
instance->bypass = value >= 0.5f;
break;
case 4:
instance->y_z1 = 0.5f * value + 0.5f;
break;
}
puglObscureView(instance->view);
}

41
test/vars-pre-old.mk Normal file
View File

@ -0,0 +1,41 @@
API_DIR := ../api
ifeq ($(TEMPLATE), cmd)
TINYWAV_DIR := ../../../tinywav
MIDI_PARSER_DIR := ../../../midi-parser
endif
ifeq ($(TEMPLATE), lv2)
CFLAGS_EXTRA := $(shell pkg-config --cflags pugl-cairo-0 pugl-0 cairo)
LDFLAGS_EXTRA := $(shell pkg-config --libs pugl-cairo-0 pugl-0 cairo) -Wl,-rpath,$(shell pkg-config --variable=libdir pugl-cairo-0),-rpath,$(shell pkg-config --variable=libdir pugl-0),-rpath,$(shell pkg-config --variable=libdir cairo)
endif
ifeq ($(TEMPLATE), vst3)
RUTEX_DIR := ../../../rutex
CFLAGS_EXTRA := -I../../../vst3_c_api $(shell pkg-config --cflags pugl-cairo-0)
LDFLAGS_EXTRA := $(shell pkg-config --libs pugl-cairo-0 pugl-0 cairo) -Wl,-rpath,$(shell pkg-config --variable=libdir pugl-cairo-0),-rpath,$(shell pkg-config --variable=libdir pugl-0),-rpath,$(shell pkg-config --variable=libdir cairo)
endif
ifeq ($(TEMPLATE), daisy-seed)
LIBDAISY_DIR := ../../../libDaisy
endif
ifeq ($(TEMPLATE), android)
CXXFLAGS_EXTRA := -I../../../miniaudio
KEY_STORE := keystore.jks
KEY_ALIAS := androidkey
STORE_PASS := android
KEY_PASS := android
SDK_DIR := $(HOME)/Android/Sdk
ANDROIDX_DIR := $(HOME)/Android/androidx
KOTLIN_DIR := $(HOME)/Android/kotlin
NDK_VERSION := 28.0.12674087
BUILD_TOOLS_VERSION := 35.0.0
ANDROID_VERSION := 35
ANDROIDX_CORE_VERSION := 1.15.0
ANDROIDX_LIFECYCLE_COMMON_VERSION := 2.8.7
ANDROIDX_VERSIONEDPARCELABLE_VERSION := 1.2.1
KOTLIN_STDLIB_VERSION := 2.1.10
KOTLINX_COROUTINES_CORE_VERSION := 1.10.1
KOTLINX_COROUTINES_CORE_JVM_VERSION := 1.10.1
endif

View File

@ -6,14 +6,13 @@ ifeq ($(TEMPLATE), cmd)
endif endif
ifeq ($(TEMPLATE), lv2) ifeq ($(TEMPLATE), lv2)
CFLAGS_EXTRA := $(shell pkg-config --cflags pugl-cairo-0 pugl-0 cairo) CFLAGS_EXTRA := $(shell pkg-config --cflags x11)
LDFLAGS_EXTRA := $(shell pkg-config --libs pugl-cairo-0 pugl-0 cairo) -Wl,-rpath,$(shell pkg-config --variable=libdir pugl-cairo-0),-rpath,$(shell pkg-config --variable=libdir pugl-0),-rpath,$(shell pkg-config --variable=libdir cairo) LDFLAGS_EXTRA := $(shell pkg-config --libs x11) -Wl,-rpath,$(shell pkg-config --variable=libdir x11)
endif endif
ifeq ($(TEMPLATE), vst3) ifeq ($(TEMPLATE), vst3)
RUTEX_DIR := ../../../rutex CFLAGS_EXTRA := $(shell pkg-config --cflags x11)
CFLAGS_EXTRA := -I../../../vst3_c_api $(shell pkg-config --cflags pugl-cairo-0) LDFLAGS_EXTRA := $(shell pkg-config --libs x11) -Wl,-rpath,$(shell pkg-config --variable=libdir x11)
LDFLAGS_EXTRA := $(shell pkg-config --libs pugl-cairo-0 pugl-0 cairo) -Wl,-rpath,$(shell pkg-config --variable=libdir pugl-cairo-0),-rpath,$(shell pkg-config --variable=libdir pugl-0),-rpath,$(shell pkg-config --variable=libdir cairo)
endif endif
ifeq ($(TEMPLATE), daisy-seed) ifeq ($(TEMPLATE), daisy-seed)