aboutsummaryrefslogtreecommitdiff
path: root/monitors_midi_pianoroll.c
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2019-04-06 21:34:34 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2019-04-06 21:34:34 +0200
commit4258e0f80a6ece809ecdbee6d3ca47be1ed6b9a7 (patch)
treeb17bee473b3dd839797dff69a82197bd51786262 /monitors_midi_pianoroll.c
parentefb8123e89614c6c3739027306cac2fdc473681b (diff)
downloadmonitors.lv2-4258e0f80a6ece809ecdbee6d3ca47be1ed6b9a7.tar.xz
add optional support for inline display.
Diffstat (limited to 'monitors_midi_pianoroll.c')
-rw-r--r--monitors_midi_pianoroll.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/monitors_midi_pianoroll.c b/monitors_midi_pianoroll.c
index f1b225d..0df1f85 100644
--- a/monitors_midi_pianoroll.c
+++ b/monitors_midi_pianoroll.c
@@ -25,6 +25,10 @@
#include <canvas.lv2/canvas.h>
#include <canvas.lv2/forge.h>
+#ifdef BUILD_IDISP
+# include <canvas.lv2/idisp.h>
+#endif
+
#define MAX_GRAPH 0x20000 //FIXME actually measure this
#define MAX_NPROPS 7
#define MAX_KEYS 0x80
@@ -70,6 +74,9 @@ struct _plughandle_t {
LV2_URID midi_MidiEvent;
+#ifdef BUILD_IDISP
+ LV2_Canvas_Idisp idisp;
+#endif
LV2_Canvas_URID urid;
double sample_rate;
float update_rate;
@@ -261,6 +268,10 @@ _render(plughandle_t *handle, int64_t frames)
_props_impl_set(&handle->props, impl, value->type, value->size,
LV2_ATOM_BODY_CONST(value));
}
+
+#ifdef BUILD_IDISP
+ lv2_canvas_idisp_queue_draw(&handle->idisp);
+#endif
}
static void
@@ -379,6 +390,9 @@ instantiate(const LV2_Descriptor* descriptor, double rate,
mlock(handle, sizeof(plughandle_t));
LV2_Options_Option *opts = NULL;
+#ifdef BUILD_IDISP
+ LV2_Inline_Display *queue_draw = NULL;
+#endif
for(unsigned i=0; features[i]; i++)
{
if(!strcmp(features[i]->URI, LV2_URID__map))
@@ -387,6 +401,10 @@ instantiate(const LV2_Descriptor* descriptor, double rate,
opts = features[i]->data;
else if(!strcmp(features[i]->URI, LV2_LOG__log))
handle->log = features[i]->data;
+#ifdef BUILD_IDISP
+ else if(!strcmp(features[i]->URI, LV2_INLINEDISPLAY__queue_draw))
+ queue_draw = features[i]->data;
+#endif
}
if(!handle->map)
@@ -412,6 +430,9 @@ instantiate(const LV2_Descriptor* descriptor, double rate,
_craft_init(&handle->notify, handle->map);
lv2_canvas_urid_init(&handle->urid, handle->map);
+#ifdef BUILD_IDISP
+ lv2_canvas_idisp_init(&handle->idisp, queue_draw, handle->map);
+#endif
handle->midi_MidiEvent = handle->map->map(handle->map->handle, LV2_MIDI__MidiEvent);
@@ -592,12 +613,64 @@ run(LV2_Handle instance, uint32_t nsamples)
_craft_out(&handle->notify);
}
+#ifdef BUILD_IDISP
+static LV2_Inline_Display_Image_Surface *
+_idisp_render(LV2_Handle instance, uint32_t w, uint32_t h)
+{
+ plughandle_t *handle = instance;
+
+ float aspect_ratio = 1.f;
+
+ {
+ props_impl_t *impl = _props_impl_get(&handle->props,
+ handle->urid.Canvas_aspectRatio);
+
+ if(impl)
+ {
+ _props_impl_spin_lock(impl, PROP_STATE_NONE, PROP_STATE_LOCK);
+
+ memcpy(&aspect_ratio, impl->stash.body, impl->stash.size);
+
+ _props_impl_unlock(impl, PROP_STATE_NONE);
+ }
+ }
+
+ LV2_Inline_Display_Image_Surface *surf =
+ lv2_canvas_idisp_surf_configure(&handle->idisp, w, h, aspect_ratio);
+
+ if(surf)
+ {
+ props_impl_t *impl = _props_impl_get(&handle->props,
+ handle->urid.Canvas_graph);
+
+ if(impl)
+ {
+ _props_impl_spin_lock(impl, PROP_STATE_NONE, PROP_STATE_LOCK);
+
+ lv2_canvas_idisp_render_body(&handle->idisp, impl->type, impl->stash.size,
+ impl->stash.body);
+
+ _props_impl_unlock(impl, PROP_STATE_NONE);
+ }
+ }
+
+ return surf;
+}
+
+static const LV2_Inline_Display_Interface idisp_iface = {
+ .render = _idisp_render
+};
+#endif
+
static void
cleanup(LV2_Handle instance)
{
plughandle_t *handle = instance;
munlock(handle, sizeof(plughandle_t));
+#ifdef BUILD_IDISP
+ lv2_canvas_idisp_deinit(&handle->idisp);
+#endif
free(handle);
}
@@ -631,6 +704,10 @@ extension_data(const char* uri)
{
if(!strcmp(uri, LV2_STATE__interface))
return &state_iface;
+#ifdef BUILD_IDISP
+ else if(!strcmp(uri, LV2_INLINEDISPLAY__interface))
+ return &idisp_iface;
+#endif
return NULL;
}