split plugin ui from plugin

This commit is contained in:
Stefano D'Angelo 2024-05-21 08:50:28 +02:00
parent 7b19769a65
commit 39d3bf9e41
7 changed files with 271 additions and 251 deletions

View File

@ -66,6 +66,7 @@ static uint32_t param_out_index[DATA_PRODUCT_CONTROL_OUTPUTS_N] = {
#endif
{{?it.lv2.ui}}
#define DATA_UI
#define DATA_LV2_UI_URI "{{=it.tibia.CGetUTF8StringLiteral(it.tibia.lv2.expandURI(it.lv2.ui.uri))}}"
#define DATA_UI_USER_RESIZABLE {{=it.product.ui.userResizable ? 1 : 0}}

View File

@ -29,8 +29,10 @@ typedef struct {
#include "data.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#define TEMPLATE_HAS_UI
#include "plugin.h"
#ifdef DATA_UI
# include "plugin_ui.h"
#endif
#pragma GCC diagnostic pop
#include "lv2/core/lv2.h"
@ -43,7 +45,7 @@ typedef struct {
#include "lv2/midi/midi.h"
#include "lv2/urid/urid.h"
#endif
#ifdef PLUGIN_UI
#ifdef DATA_UI
#include "lv2/ui/ui.h"
#endif
@ -300,7 +302,7 @@ LV2_SYMBOL_EXPORT const LV2_Descriptor * lv2_descriptor(uint32_t index) {
return index == 0 ? &descriptor : NULL;
}
#ifdef PLUGIN_UI
#ifdef DATA_UI
typedef struct {
plugin_ui * ui;
# if DATA_PRODUCT_CONTROL_INPUTS_N > 0

View File

@ -220,5 +220,6 @@ static struct {
{{?}}
{{?it.product.ui}}
#define DATA_UI
#define DATA_UI_USER_RESIZABLE {{=it.product.ui.userResizable ? 1 : 0}}
{{?}}

View File

@ -33,8 +33,10 @@ typedef struct {
} plugin_ui_callbacks;
#include "data.h"
#define TEMPLATE_HAS_UI
#include "plugin.h"
#ifdef DATA_UI
# include "plugin_ui.h"
#endif
#if defined(__i386__) || defined(__x86_64__)
#include <xmmintrin.h>
@ -57,7 +59,7 @@ typedef struct {
#include <pmmintrin.h>
#endif
#ifdef PLUGIN_UI
#ifdef DATA_UI
# ifdef __linux__
// Why generate the C interface when you can just not give a fuck? Thank you Steinberg!
@ -847,7 +849,7 @@ typedef struct plugView plugView;
typedef struct controller {
Steinberg_Vst_IEditControllerVtbl * vtblIEditController;
Steinberg_Vst_IMidiMappingVtbl * vtblIMidiMapping;
#ifdef PLUGIN_UI
#ifdef DATA_UI
//Steinberg_Vst_IConnectionPointVtbl * vtblIConnectionPoint;
#endif
Steinberg_uint32 refs;
@ -856,14 +858,14 @@ typedef struct controller {
double parameters[DATA_PRODUCT_PARAMETERS_N + 3 * DATA_PRODUCT_BUSES_MIDI_INPUT_N];
#endif
struct Steinberg_Vst_IComponentHandler * componentHandler;
#ifdef PLUGIN_UI
#ifdef DATA_UI
plugView ** views;
size_t viewsCount;
#endif
} controller;
static Steinberg_Vst_IEditControllerVtbl controllerVtblIEditController;
#ifdef PLUGIN_UI
#ifdef DATA_UI
# ifdef __linux__
# include <X11/Xlib.h>
@ -1210,7 +1212,7 @@ static Steinberg_IPlugViewVtbl plugViewVtblIPlugView = {
#endif
static Steinberg_Vst_IMidiMappingVtbl controllerVtblIMidiMapping;
#ifdef PLUGIN_UI
#ifdef DATA_UI
//static Steinberg_Vst_IConnectionPointVtbl controllerVtblIConnectionPoint;
#endif
@ -1223,7 +1225,7 @@ static Steinberg_tresult controllerQueryInterface(controller *c, const Steinberg
offset = offsetof(controller, vtblIEditController);
else if (memcmp(iid, Steinberg_Vst_IMidiMapping_iid, sizeof(Steinberg_TUID)) == 0)
offset = offsetof(controller, vtblIMidiMapping);
#ifdef PLUGIN_UI
#ifdef DATA_UI
/*else if (memcmp(iid, Steinberg_Vst_IConnectionPoint_iid, sizeof(Steinberg_TUID)) == 0)
offset = offsetof(controller, vtblIConnectionPoint);*/
#endif
@ -1249,7 +1251,7 @@ static Steinberg_uint32 controllerRelease(controller *c) {
c->refs--;
if (c->refs == 0) {
TRACE(" free %p\n", (void *)c);
#ifdef PLUGIN_UI
#ifdef DATA_UI
if (c->views) {
for (size_t i = 0; i < c->viewsCount; i++)
if (c->views[i]) // this should not happen but you never know
@ -1496,7 +1498,7 @@ static Steinberg_tresult controllerSetParamNormalized(void* thisInterface, Stein
return Steinberg_kResultFalse;
controller *c = (controller *)((char *)thisInterface - offsetof(controller, vtblIEditController));
c->parameters[pi] = pi >= DATA_PRODUCT_PARAMETERS_N ? value : parameterAdjust(pi, parameterMap(pi, value));
# ifdef PLUGIN_UI
# ifdef DATA_UI
for (size_t i = 0; i < c->viewsCount; i++)
if(c->views[i])
plugViewUpdateParameter(c->views[i], pi);
@ -1526,7 +1528,7 @@ static Steinberg_tresult controllerSetComponentHandler(void* thisInterface, stru
static struct Steinberg_IPlugView* controllerCreateView(void* thisInterface, Steinberg_FIDString name) {
TRACE("controller create view %s\n", name);
#ifdef PLUGIN_UI
#ifdef DATA_UI
if (strcmp(name, "editor"))
return NULL;
@ -1649,7 +1651,7 @@ static Steinberg_Vst_IMidiMappingVtbl controllerVtblIMidiMapping = {
/* .getMidiControllerAssignment = */ controllerGetMidiControllerAssignment
};
#ifdef PLUGIN_UI
#ifdef DATA_UI
# if 0
static Steinberg_tresult controllerIConnectionPointQueryInterface(void* thisInterface, const Steinberg_TUID iid, void** obj) {
TRACE("controller IConnectionPoint queryInterface %p\n", thisInterface);
@ -1818,13 +1820,13 @@ static Steinberg_tresult factoryCreateInstance(void *thisInterface, Steinberg_FI
return Steinberg_kOutOfMemory;
c->vtblIEditController = &controllerVtblIEditController;
c->vtblIMidiMapping = &controllerVtblIMidiMapping;
#ifdef PLUGIN_UI
#ifdef DATA_UI
//c->vtblIConnectionPoint = &controllerVtblIConnectionPoint;
#endif
c->refs = 1;
c->context = NULL;
c->componentHandler = NULL;
#ifdef PLUGIN_UI
#ifdef DATA_UI
c->views = NULL;
c->viewsCount = 0;
#endif

View File

@ -115,236 +115,3 @@ static void plugin_midi_msg_in(plugin *instance, size_t index, const uint8_t * d
//approx instance->cutoff_k = powf(2.f, (1.f / 12.f) * (note - 60));
instance->cutoff_k = data[1] < 64 ? (-0.19558034980097166f * data[1] - 2.361735109225749f) / (data[1] - 75.57552349522389f) : (393.95397927344214f - 7.660826245588588f * data[1]) / (data[1] - 139.0755234952239f);
}
#ifdef TEMPLATE_HAS_UI
# define PLUGIN_UI
# 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;
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;
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);
}
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 (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->gain = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter(instance->cbs.handle, 0, -60.f + 80.f * instance->gain);
puglPostRedisplay(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->delay = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter(instance->cbs.handle, 1, 1000.f * instance->delay);
puglPostRedisplay(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->cutoff = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff));
puglPostRedisplay(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->bypass = !instance->bypass;
instance->cbs.set_parameter(instance->cbs.handle, 3, instance->bypass ? 1.f : 0.f);
puglPostRedisplay(instance->view);
}
}
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->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);
puglSetBackend(instance->view, puglCairoBackend());
PuglRect frame = { 0, 0, WIDTH, HEIGHT };
puglSetFrame(instance->view, frame);
puglSetEventFunc(instance->view, plugin_ui_on_event);
if (has_parent)
puglSetParentWindow(instance->view, (PuglNativeView)parent);
if (puglRealize(instance->view)) {
puglFreeView(instance->view);
puglFreeWorld(instance->world);
return NULL;
}
puglShow(instance->view, PUGL_SHOW_RAISE);
puglSetHandle(instance->view, instance);
instance->widget = (void *)puglGetNativeView(instance->view);
instance->cbs = *cbs;
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;
}
puglPostRedisplay(instance->view);
}
#endif

247
test/plugin_ui.h Normal file
View File

@ -0,0 +1,247 @@
/*
* 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
*/
#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;
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;
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);
}
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 (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->gain = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter(instance->cbs.handle, 0, -60.f + 80.f * instance->gain);
puglPostRedisplay(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->delay = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter(instance->cbs.handle, 1, 1000.f * instance->delay);
puglPostRedisplay(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->cutoff = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w));
instance->cbs.set_parameter(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff));
puglPostRedisplay(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->bypass = !instance->bypass;
instance->cbs.set_parameter(instance->cbs.handle, 3, instance->bypass ? 1.f : 0.f);
puglPostRedisplay(instance->view);
}
}
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->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);
puglSetBackend(instance->view, puglCairoBackend());
PuglRect frame = { 0, 0, WIDTH, HEIGHT };
puglSetFrame(instance->view, frame);
puglSetEventFunc(instance->view, plugin_ui_on_event);
if (has_parent)
puglSetParentWindow(instance->view, (PuglNativeView)parent);
if (puglRealize(instance->view)) {
puglFreeView(instance->view);
puglFreeWorld(instance->world);
return NULL;
}
puglShow(instance->view, PUGL_SHOW_RAISE);
puglSetHandle(instance->view, instance);
instance->widget = (void *)puglGetNativeView(instance->view);
instance->cbs = *cbs;
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;
}
puglPostRedisplay(instance->view);
}

View File

@ -3,11 +3,11 @@
dir=`dirname $0`
$dir/../tibia $dir/product.json,$dir/company.json,$dir/vst3.json $dir/../templates/vst3 $dir/../out/vst3
$dir/../tibia $dir/product.json,$dir/company.json,$dir/vst3.json,$dir/vst3-make.json $dir/../templates/vst3-make $dir/../out/vst3
cp $dir/plugin.h $dir/../out/vst3/src
cp $dir/plugin.h $dir/plugin_ui.h $dir/../out/vst3/src
$dir/../tibia $dir/product.json,$dir/company.json,$dir/lv2.json $dir/../templates/lv2 $dir/../out/lv2
$dir/../tibia $dir/product.json,$dir/company.json,$dir/lv2.json,$dir/lv2-make.json $dir/../templates/lv2-make $dir/../out/lv2
cp $dir/plugin.h $dir/../out/lv2/src
cp $dir/plugin.h $dir/plugin_ui.h $dir/../out/lv2/src
$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/web $dir/../out/web
$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/web-make $dir/../out/web