aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2018-04-02 09:50:35 +0200
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2018-04-02 09:50:35 +0200
commit0f2dae056ca94b79813c51f16e33840f5d425b49 (patch)
tree8af1a0a5d461be897928f549432763800497a6dc
parent7bb62715125ee4f562d9407ff124b2a6a7666be4 (diff)
downloadcanvas.lv2-0f2dae056ca94b79813c51f16e33840f5d425b49.zip
canvas.lv2-0f2dae056ca94b79813c51f16e33840f5d425b49.tar.gz
canvas.lv2-0f2dae056ca94b79813c51f16e33840f5d425b49.tar.bz2
canvas.lv2-0f2dae056ca94b79813c51f16e33840f5d425b49.tar.xz
add canvas:aspectRatio parameter.
-rw-r--r--VERSION2
-rw-r--r--canvas.lv2/canvas.h3
-rw-r--r--test/canvas.c80
-rw-r--r--test/canvas_ui.c79
4 files changed, 147 insertions, 17 deletions
diff --git a/VERSION b/VERSION
index 9ec8136..dfdc368 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.3.19
+0.3.21
diff --git a/canvas.lv2/canvas.h b/canvas.lv2/canvas.h
index 56e6fb7..24f753e 100644
--- a/canvas.lv2/canvas.h
+++ b/canvas.lv2/canvas.h
@@ -31,6 +31,7 @@ extern "C" {
#define CANVAS__graph CANVAS_PREFIX"graph"
#define CANVAS__body CANVAS_PREFIX"body"
+#define CANVAS__aspectRatio CANVAS_PREFIX"aspectRatio"
// Graph properties and attributes
#define CANVAS__BeginPath CANVAS_PREFIX"BeginPath"
@@ -82,6 +83,7 @@ typedef struct _LV2_Canvas_URID LV2_Canvas_URID;
struct _LV2_Canvas_URID {
LV2_URID Canvas_graph;
LV2_URID Canvas_body;
+ LV2_URID Canvas_aspectRatio;
LV2_URID Canvas_BeginPath;
LV2_URID Canvas_ClosePath;
@@ -133,6 +135,7 @@ lv2_canvas_urid_init(LV2_Canvas_URID *urid, LV2_URID_Map *map)
{
urid->Canvas_graph = map->map(map->handle, CANVAS__graph);
urid->Canvas_body = map->map(map->handle, CANVAS__body);
+ urid->Canvas_aspectRatio = map->map(map->handle, CANVAS__aspectRatio);
urid->Canvas_BeginPath = map->map(map->handle, CANVAS__BeginPath);
urid->Canvas_ClosePath = map->map(map->handle, CANVAS__ClosePath);
diff --git a/test/canvas.c b/test/canvas.c
index 4885a0c..730549f 100644
--- a/test/canvas.c
+++ b/test/canvas.c
@@ -31,6 +31,7 @@
#include <cairo/cairo.h>
+//#define DEBUG
#define MAX_GRAPH_BUF 0x10000
typedef struct _plughandle_t plughandle_t;
@@ -65,6 +66,7 @@ struct _plughandle_t {
LV2_Canvas canvas;
bool dirty;
+ float aspect_ratio;
union {
LV2_Atom_Tuple graph;
uint8_t buf [MAX_GRAPH_BUF];
@@ -191,6 +193,8 @@ instantiate(const LV2_Descriptor* descriptor, double rate,
lv2_canvas_init(&handle->canvas, handle->map);
+ handle->aspect_ratio = 1.f;
+
LV2_Atom_Forge_Frame frame;
lv2_atom_forge_set_buffer(&handle->forge, handle->buf, MAX_GRAPH_BUF);
LV2_Atom_Forge_Ref ref = lv2_atom_forge_tuple(&handle->forge, &frame);
@@ -276,6 +280,26 @@ run(LV2_Handle instance, uint32_t nsamples)
if(ref)
lv2_atom_forge_pop(&handle->forge, &obj_frame);
}
+ else if( property
+ && (property->atom.type == handle->forge.URID)
+ && (property->body == handle->canvas.urid.Canvas_aspectRatio) )
+ {
+ LV2_Atom_Forge_Frame obj_frame;
+ if(ref)
+ ref = lv2_atom_forge_frame_time(&handle->forge, ev->time.frames);
+ if(ref)
+ ref = lv2_atom_forge_object(&handle->forge, &obj_frame, 0, handle->patch_Set);
+ if(ref)
+ ref = lv2_atom_forge_key(&handle->forge, handle->patch_property);
+ if(ref)
+ ref = lv2_atom_forge_urid(&handle->forge, handle->canvas.urid.Canvas_aspectRatio);
+ if(ref)
+ ref = lv2_atom_forge_key(&handle->forge, handle->patch_value);
+ if(ref)
+ ref = lv2_atom_forge_float(&handle->forge, handle->aspect_ratio);
+ if(ref)
+ lv2_atom_forge_pop(&handle->forge, &obj_frame);
+ }
}
else if(obj->body.otype == handle->patch_Set)
{
@@ -309,91 +333,122 @@ run(LV2_Handle instance, uint32_t nsamples)
route = true;
}
+ else if( (property->body == handle->canvas.urid.Canvas_aspectRatio)
+ && (value->type == handle->forge.Float) )
+ {
+ if( _try_lock(&handle->lock) )
+ {
+ handle->aspect_ratio = ((const LV2_Atom_Float *)value)->body;
+
+ _unlock(&handle->lock);
+
+ if(handle->queue_draw)
+ handle->queue_draw->queue_draw(handle->queue_draw->handle);
+ }
+
+ route = true;
+ }
else if( (property->body == handle->canvas.urid.Canvas_mouseButtonLeft)
&& (value->type == handle->forge.Bool) )
{
+#ifdef DEBUG
if(handle->log)
{
lv2_log_trace(&handle->logger, "\tcanvas:mouseButtonLeft: %"PRIi32"\n",
((const LV2_Atom_Bool *)value)->body);
}
+#endif
route = true;
}
else if( (property->body == handle->canvas.urid.Canvas_mouseButtonMiddle)
&& (value->type == handle->forge.Bool) )
{
+#ifdef DEBUG
if(handle->log)
{
lv2_log_trace(&handle->logger, "\tcanvas:mouseButtonMiddle: %"PRIi32"\n",
((const LV2_Atom_Bool *)value)->body);
}
+#endif
route = true;
}
else if( (property->body == handle->canvas.urid.Canvas_mouseButtonRight)
&& (value->type == handle->forge.Bool) )
{
+#ifdef DEBUG
if(handle->log)
{
lv2_log_trace(&handle->logger, "\tcanvas:mouseButtonRight: %"PRIi32"\n",
((const LV2_Atom_Bool *)value)->body);
}
+#endif
route = true;
}
else if( (property->body == handle->canvas.urid.Canvas_mousePositionX)
&& (value->type == handle->forge.Double) )
{
+#ifdef DEBUG
if(handle->log)
{
lv2_log_trace(&handle->logger, "\tcanvas:mousePositionX: %lf\n",
((const LV2_Atom_Double *)value)->body);
}
+#endif
route = true;
}
else if( (property->body == handle->canvas.urid.Canvas_mousePositionY)
&& (value->type == handle->forge.Double) )
{
+#ifdef DEBUG
if(handle->log)
{
lv2_log_trace(&handle->logger, "\tcanvas:mousePositionY: %lf\n",
((const LV2_Atom_Double *)value)->body);
}
+#endif
route = true;
}
else if( (property->body == handle->canvas.urid.Canvas_mouseWheelX)
&& (value->type == handle->forge.Double) )
{
+#ifdef DEBUG
if(handle->log)
{
lv2_log_trace(&handle->logger, "\tcanvas:mouseWheelX: %lf\n",
((const LV2_Atom_Double *)value)->body);
}
+#endif
route = true;
}
else if( (property->body == handle->canvas.urid.Canvas_mouseWheelY)
&& (value->type == handle->forge.Double) )
{
+#ifdef DEBUG
if(handle->log)
{
lv2_log_trace(&handle->logger, "\tcanvas:mouseWheelY: %lf\n",
((const LV2_Atom_Double *)value)->body);
}
+#endif
route = true;
}
else if( (property->body == handle->canvas.urid.Canvas_mouseFocus)
&& (value->type == handle->forge.Bool) )
{
+#ifdef DEBUG
if(handle->log)
{
lv2_log_trace(&handle->logger, "\tcanvas:mouseFocus: %"PRIi32"\n",
((const LV2_Atom_Bool *)value)->body);
}
+#endif
route = true;
}
@@ -429,6 +484,7 @@ run(LV2_Handle instance, uint32_t nsamples)
handle->canvas.urid.Canvas_mouseFocus, &f,
0);
+#ifdef DEBUG
if(handle->log)
{
lv2_log_trace(&handle->logger, "{\n");
@@ -450,6 +506,7 @@ run(LV2_Handle instance, uint32_t nsamples)
lv2_log_trace(&handle->logger, "\tcanvas:mouseFocus: %"PRIi32"\n", f->body);
lv2_log_trace(&handle->logger, "}\n");
}
+#endif
if( x && (x->atom.type == handle->forge.Double)
&& y && (y->atom.type == handle->forge.Double) )
@@ -534,10 +591,29 @@ _render(LV2_Handle instance, uint32_t w, uint32_t h)
plughandle_t *handle = instance;
LV2_Inline_Display_Image_Surface *surf = &handle->image_surface;
- if( (surf->width != (int)w) || (surf->height != (int)h) || !surf->data)
+ int W;
+ int H;
+
+ if(handle->aspect_ratio == 0.f)
+ {
+ W = w;
+ H = h;
+ }
+ else if(handle->aspect_ratio <= 1.f)
+ {
+ W = h * handle->aspect_ratio;
+ H = h;
+ }
+ else if(handle->aspect_ratio > 1.f)
+ {
+ W = w;
+ H = w / handle->aspect_ratio;
+ }
+
+ if( (surf->width != W) || (surf->height != H) || !surf->data)
{
_cairo_deinit(handle);
- surf = _cairo_init(handle, w, h);
+ surf = _cairo_init(handle, W, H);
}
if(!surf)
diff --git a/test/canvas_ui.c b/test/canvas_ui.c
index e99c368..d178f77 100644
--- a/test/canvas_ui.c
+++ b/test/canvas_ui.c
@@ -34,6 +34,7 @@ typedef struct _plughandle_t plughandle_t;
struct _plughandle_t {
LV2_URID_Map *map;
LV2_Atom_Forge forge;
+ LV2UI_Resize *host_resize;
PuglView *view;
int done;
@@ -48,6 +49,7 @@ struct _plughandle_t {
LV2_URID patch_body;
LV2_URID atom_eventTransfer;
+ float aspect_ratio;
LV2_Atom_Tuple *graph;
LV2UI_Write_Function writer;
@@ -84,6 +86,19 @@ _refresh(plughandle_t *handle)
if(ref)
ref = lv2_atom_forge_key(&handle->forge, handle->patch_property);
if(ref)
+ ref = lv2_atom_forge_urid(&handle->forge, handle->canvas.urid.Canvas_aspectRatio);
+ if(ref)
+ lv2_atom_forge_pop(&handle->forge, &obj_frame);
+
+ if(ref)
+ _event_commit(handle);
+
+ _event_request(handle);
+
+ ref = lv2_atom_forge_object(&handle->forge, &obj_frame, 0, handle->patch_Get);
+ if(ref)
+ ref = lv2_atom_forge_key(&handle->forge, handle->patch_property);
+ if(ref)
ref = lv2_atom_forge_urid(&handle->forge, handle->canvas.urid.Canvas_graph);
if(ref)
lv2_atom_forge_pop(&handle->forge, &obj_frame);
@@ -322,13 +337,12 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
return NULL;
void *parent = NULL;
- LV2UI_Resize *host_resize = NULL;
for(int i=0; features[i]; i++)
{
if(!strcmp(features[i]->URI, LV2_UI__parent))
parent = features[i]->data;
else if(!strcmp(features[i]->URI, LV2_UI__resize))
- host_resize = features[i]->data;
+ handle->host_resize = features[i]->data;
else if(!strcmp(features[i]->URI, LV2_URID__map))
handle->map = features[i]->data;
}
@@ -365,13 +379,13 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
return NULL;
}
- const unsigned w = 400;
- const unsigned h = 400;;
+ const unsigned w = 640;
+ const unsigned h = 640;;
puglInitWindowClass(handle->view, "canvas");
puglInitWindowParent(handle->view, (intptr_t)parent);
puglInitWindowSize(handle->view, w, h);
- puglInitWindowMinSize(handle->view, w, h);
- puglInitWindowAspectRatio(handle->view, 1, 1, 1, 1);
+ puglInitWindowMinSize(handle->view, w/8, h/8);
+ //puglInitWindowAspectRatio(handle->view, 1, 1, 1, 1);
puglInitResizable(handle->view, true);
puglInitTransientFor(handle->view, (intptr_t)parent);
puglSetHandle(handle->view, handle);
@@ -406,8 +420,8 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
const intptr_t child = puglGetNativeWindow(handle->view);
*(intptr_t *)widget = child;
- if(host_resize)
- host_resize->ui_resize(host_resize->handle, w, h);
+ if(handle->host_resize)
+ handle->host_resize->ui_resize(handle->host_resize->handle, w, h);
lv2_canvas_init(&handle->canvas, handle->map);
@@ -451,26 +465,63 @@ port_event(LV2UI_Handle instance, uint32_t index, uint32_t size,
if(obj->body.otype == handle->patch_Set)
{
const LV2_Atom_URID *property = NULL;
- const LV2_Atom_Tuple *graph = NULL;
+ const LV2_Atom *value = NULL;
lv2_atom_object_get(obj,
handle->patch_property, &property,
- handle->patch_value, &graph,
+ handle->patch_value, &value,
0);
if( property
&& (property->atom.type == handle->forge.URID)
&& (property->body == handle->canvas.urid.Canvas_graph)
- && graph
- && (graph->atom.type == handle->forge.Tuple) )
+ && value
+ && (value->type == handle->forge.Tuple) )
{
if(handle->graph)
free(handle->graph);
- const size_t sz = lv2_atom_total_size(&graph->atom);
+ const size_t sz = lv2_atom_total_size(value);
handle->graph = malloc(sz);
if(handle->graph)
- memcpy(handle->graph, graph, sz);
+ memcpy(handle->graph, value, sz);
+
+ puglPostRedisplay(handle->view);
+ }
+ else if( property
+ && (property->atom.type == handle->forge.URID)
+ && (property->body == handle->canvas.urid.Canvas_aspectRatio)
+ && value
+ && (value->type == handle->forge.Float) )
+ {
+ handle->aspect_ratio = ((const LV2_Atom_Float *)value)->body;
+
+ int w;
+ int h;
+
+ puglGetSize(handle->view, &w, &h);
+
+ int W;
+ int H;
+
+ if(handle->aspect_ratio == 0.f)
+ {
+ W = w;
+ H = h;
+ }
+ else if(handle->aspect_ratio <= 1.f)
+ {
+ W = h * handle->aspect_ratio;
+ H = h;
+ }
+ else if(handle->aspect_ratio > 1.f)
+ {
+ W = w;
+ H = w / handle->aspect_ratio;
+ }
+
+ if(handle->host_resize && ( (W != w) || (H != h) ) )
+ handle->host_resize->ui_resize(handle->host_resize->handle, W, H);
puglPostRedisplay(handle->view);
}