shorten enum/string for icons by avoiding Gtkmm2ext namespace
[ardour.git] / libs / plugins / a-comp.lv2 / a-comp.c
1 /* a-comp
2  * Copyright (C) 2016 Damien Zammit <damien@zamaudio.com>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #include <math.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <stdbool.h>
19
20 #ifdef LV2_EXTENDED
21 #include <cairo/cairo.h>
22 #include "ardour/lv2_extensions.h"
23 #endif
24
25 #include "lv2/lv2plug.in/ns/lv2core/lv2.h"
26
27 #define ACOMP_URI               "urn:ardour:a-comp"
28 #define ACOMP_STEREO_URI        "urn:ardour:a-comp#stereo"
29
30 #ifndef M_PI
31 #  define M_PI 3.14159265358979323846
32 #endif
33
34 #ifdef COMPILER_MSVC
35 #include <float.h>
36 #define isfinite_local(val) (bool)_finite((double)val)
37 #else
38 #define isfinite_local isfinite
39 #endif
40
41 typedef enum {
42         ACOMP_ATTACK = 0,
43         ACOMP_RELEASE,
44         ACOMP_KNEE,
45         ACOMP_RATIO,
46         ACOMP_THRESHOLD,
47         ACOMP_MAKEUP,
48
49         ACOMP_GAINR,
50         ACOMP_OUTLEVEL,
51         ACOMP_SIDECHAIN,
52         ACOMP_ENABLE,
53
54         ACOMP_A0,
55         ACOMP_A1,
56         ACOMP_A2,
57         ACOMP_A3,
58         ACOMP_A4,
59 } PortIndex;
60
61 typedef struct {
62         float* attack;
63         float* release;
64         float* knee;
65         float* ratio;
66         float* thresdb;
67         float* makeup;
68
69         float* gainr;
70         float* outlevel;
71         float* sidechain;
72         float* enable;
73
74         float* input0;
75         float* input1;
76         float* sc;
77         float* output0;
78         float* output1;
79
80         float srate;
81         float old_yl;
82         float old_y1;
83         float old_yg;
84
85         float makeup_gain;
86         float tau;
87
88 #ifdef LV2_EXTENDED
89         LV2_Inline_Display_Image_Surface surf;
90         bool                     need_expose;
91         cairo_surface_t*         display;
92         LV2_Inline_Display*      queue_draw;
93         uint32_t                 w, h;
94
95         /* ports pointers are only valid during run so we'll
96          * have to cache them for the display, besides
97          * we do want to check for changes
98          */
99         float v_knee;
100         float v_ratio;
101         float v_thresdb;
102         float v_lvl;
103         float v_lvl_in;
104         float v_lvl_out;
105 #endif
106 } AComp;
107
108 static LV2_Handle
109 instantiate(const LV2_Descriptor* descriptor,
110             double rate,
111             const char* bundle_path,
112             const LV2_Feature* const* features)
113 {
114         AComp* acomp = (AComp*)calloc(1, sizeof(AComp));
115
116         for (int i=0; features[i]; ++i) {
117 #ifdef LV2_EXTENDED
118                 if (!strcmp(features[i]->URI, LV2_INLINEDISPLAY__queue_draw)) {
119                         acomp->queue_draw = (LV2_Inline_Display*) features[i]->data;
120                 }
121 #endif
122         }
123
124         acomp->srate = rate;
125         acomp->old_yl=acomp->old_y1=acomp->old_yg=0.f;
126         acomp->tau = (1.0 - exp (-2.f * M_PI * 25.f / acomp->srate));
127 #ifdef LV2_EXTENDED
128         acomp->need_expose = true;
129 #endif
130
131         return (LV2_Handle)acomp;
132 }
133
134
135 static void
136 connect_port(LV2_Handle instance,
137              uint32_t port,
138              void* data)
139 {
140         AComp* acomp = (AComp*)instance;
141
142         switch ((PortIndex)port) {
143                 case ACOMP_ATTACK:
144                         acomp->attack = (float*)data;
145                         break;
146                 case ACOMP_RELEASE:
147                         acomp->release = (float*)data;
148                         break;
149                 case ACOMP_KNEE:
150                         acomp->knee = (float*)data;
151                         break;
152                 case ACOMP_RATIO:
153                         acomp->ratio = (float*)data;
154                         break;
155                 case ACOMP_THRESHOLD:
156                         acomp->thresdb = (float*)data;
157                         break;
158                 case ACOMP_MAKEUP:
159                         acomp->makeup = (float*)data;
160                         break;
161                 case ACOMP_GAINR:
162                         acomp->gainr = (float*)data;
163                         break;
164                 case ACOMP_OUTLEVEL:
165                         acomp->outlevel = (float*)data;
166                         break;
167                 case ACOMP_SIDECHAIN:
168                         acomp->sidechain = (float*)data;
169                         break;
170                 case ACOMP_ENABLE:
171                         acomp->enable = (float*)data;
172                         break;
173                 default:
174                         break;
175         }
176 }
177
178 static void
179 connect_mono(LV2_Handle instance,
180              uint32_t port,
181              void* data)
182 {
183         AComp* acomp = (AComp*)instance;
184         connect_port (instance, port, data);
185
186         switch ((PortIndex)port) {
187                 case ACOMP_A0:
188                         acomp->input0 = (float*)data;
189                         break;
190                 case ACOMP_A1:
191                         acomp->sc = (float*)data;
192                         break;
193                 case ACOMP_A2:
194                         acomp->output0 = (float*)data;
195                         break;
196         default:
197                 break;
198         }
199 }
200
201 static void
202 connect_stereo(LV2_Handle instance,
203                uint32_t port,
204                void* data)
205 {
206         AComp* acomp = (AComp*)instance;
207         connect_port (instance, port, data);
208
209         switch ((PortIndex)port) {
210                 case ACOMP_A0:
211                         acomp->input0 = (float*)data;
212                         break;
213                 case ACOMP_A1:
214                         acomp->input1 = (float*)data;
215                         break;
216                 case ACOMP_A2:
217                         acomp->sc = (float*)data;
218                         break;
219                 case ACOMP_A3:
220                         acomp->output0 = (float*)data;
221                         break;
222                 case ACOMP_A4:
223                         acomp->output1 = (float*)data;
224                         break;
225         default:
226                 break;
227         }
228 }
229
230 // Force already-denormal float value to zero
231 static inline float
232 sanitize_denormal(float value) {
233         if (!isnormal(value)) {
234                 value = 0.f;
235         }
236         return value;
237 }
238
239 static inline float
240 from_dB(float gdb) {
241         return (exp(gdb/20.f*log(10.f)));
242 }
243
244 static inline float
245 to_dB(float g) {
246         return (20.f*log10(g));
247 }
248
249 static void
250 activate(LV2_Handle instance)
251 {
252         AComp* acomp = (AComp*)instance;
253
254         *(acomp->gainr) = 0.0f;
255         *(acomp->outlevel) = -45.0f;
256         acomp->old_yl=acomp->old_y1=acomp->old_yg=0.f;
257 }
258
259 static void
260 run_mono(LV2_Handle instance, uint32_t n_samples)
261 {
262         AComp* acomp = (AComp*)instance;
263
264         const float* const input = acomp->input0;
265         const float* const sc = acomp->sc;
266         float* const output = acomp->output0;
267
268         float srate = acomp->srate;
269         float width = (6.f * *(acomp->knee)) + 0.01;
270         float cdb=0.f;
271         float attack_coeff = exp(-1000.f/(*(acomp->attack) * srate));
272         float release_coeff = exp(-1000.f/(*(acomp->release) * srate));
273
274         float max = 0.f;
275         float lgaininp = 0.f;
276         float Lgain = 1.f;
277         float Lxg, Lxl, Lyg, Lyl, Ly1;
278         int usesidechain = (*(acomp->sidechain) <= 0.f) ? 0 : 1;
279         uint32_t i;
280         float ingain;
281         float in0;
282         float sc0;
283
284         float ratio = *acomp->ratio;
285         float thresdb = *acomp->thresdb;
286         float makeup_target = from_dB(*acomp->makeup);
287         float makeup_gain = acomp->makeup_gain;
288
289         const const float tau = acomp->tau;
290
291         if (*acomp->enable <= 0) {
292                 ratio = 1.f;
293                 thresdb = 0.f;
294                 makeup_target = 1.f;
295         }
296
297 #ifdef LV2_EXTENDED
298         if (acomp->v_knee != *acomp->knee) {
299                 acomp->v_knee = *acomp->knee;
300                 acomp->need_expose = true;
301         }
302
303         if (acomp->v_ratio != ratio) {
304                 acomp->v_ratio = ratio;
305                 acomp->need_expose = true;
306         }
307
308         if (acomp->v_thresdb != thresdb) {
309                 acomp->v_thresdb = thresdb;
310                 acomp->need_expose = true;
311         }
312 #endif
313
314         float in_peak = 0;
315
316         for (i = 0; i < n_samples; i++) {
317                 in0 = input[i];
318                 sc0 = sc[i];
319                 ingain = usesidechain ? fabs(sc0) : fabs(in0);
320                 in_peak = fmaxf (in_peak, ingain);
321                 Lyg = 0.f;
322                 Lxg = (ingain==0.f) ? -160.f : to_dB(ingain);
323                 Lxg = sanitize_denormal(Lxg);
324
325
326                 if (2.f*(Lxg-thresdb) < -width) {
327                         Lyg = Lxg;
328                 } else if (2.f*(Lxg-thresdb) > width) {
329                         Lyg = thresdb + (Lxg-thresdb)/ratio;
330                         Lyg = sanitize_denormal(Lyg);
331                 } else {
332                         Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);
333                 }
334
335                 Lxl = Lxg - Lyg;
336
337                 acomp->old_y1 = sanitize_denormal(acomp->old_y1);
338                 acomp->old_yl = sanitize_denormal(acomp->old_yl);
339                 Ly1 = fmaxf(Lxl, release_coeff * acomp->old_y1+(1.f-release_coeff)*Lxl);
340                 Lyl = attack_coeff * acomp->old_yl+(1.f-attack_coeff)*Ly1;
341                 Ly1 = sanitize_denormal(Ly1);
342                 Lyl = sanitize_denormal(Lyl);
343
344                 cdb = -Lyl;
345                 Lgain = from_dB(cdb);
346
347                 *(acomp->gainr) = Lyl;
348
349                 lgaininp = in0 * Lgain;
350
351                 makeup_gain += tau * (makeup_target - makeup_gain) + 1e-12;
352                 output[i] = lgaininp * makeup_gain;
353
354                 max = (fabsf(output[i]) > max) ? fabsf(output[i]) : sanitize_denormal(max);
355
356                 // TODO re-use local variables on stack
357                 // store values back to acomp at the end of the inner-loop
358                 acomp->old_yl = Lyl;
359                 acomp->old_y1 = Ly1;
360                 acomp->old_yg = Lyg;
361         }
362
363         *(acomp->outlevel) = (max < 0.0056f) ? -45.f : to_dB(max);
364         acomp->makeup_gain = makeup_gain;
365
366 #ifdef LV2_EXTENDED
367         acomp->v_lvl += .1 * (in_peak - acomp->v_lvl) + 1e-12;  // crude LPF TODO use n_samples/rate TC
368         if (!isfinite_local (acomp->v_lvl)) {
369                 acomp->v_lvl = 0.f;
370         }
371         const float v_lvl_in = (acomp->v_lvl < 0.001f) ? -60.f : to_dB(acomp->v_lvl);
372         const float v_lvl_out = (max < 0.001f) ? -60.f : to_dB(max);
373         if (fabsf (acomp->v_lvl_out - v_lvl_out) >= 1 || fabsf (acomp->v_lvl_in - v_lvl_in) >= 1) {
374                 // >= 1dB difference
375                 acomp->need_expose = true;
376                 acomp->v_lvl_in = v_lvl_in;
377                 acomp->v_lvl_out = v_lvl_out - to_dB(makeup_gain);
378         }
379         if (acomp->need_expose && acomp->queue_draw) {
380                 acomp->need_expose = false;
381                 acomp->queue_draw->queue_draw (acomp->queue_draw->handle);
382         }
383 #endif
384 }
385
386 static void
387 run_stereo(LV2_Handle instance, uint32_t n_samples)
388 {
389         AComp* acomp = (AComp*)instance;
390
391         const float* const input0 = acomp->input0;
392         const float* const input1 = acomp->input1;
393         const float* const sc = acomp->sc;
394         float* const output0 = acomp->output0;
395         float* const output1 = acomp->output1;
396
397         float srate = acomp->srate;
398         float width = (6.f * *(acomp->knee)) + 0.01;
399         float cdb=0.f;
400         float attack_coeff = exp(-1000.f/(*(acomp->attack) * srate));
401         float release_coeff = exp(-1000.f/(*(acomp->release) * srate));
402
403         float max = 0.f;
404         float lgaininp = 0.f;
405         float rgaininp = 0.f;
406         float Lgain = 1.f;
407         float Lxg, Lxl, Lyg, Lyl, Ly1;
408         int usesidechain = (*(acomp->sidechain) <= 0.f) ? 0 : 1;
409         uint32_t i;
410         float ingain;
411         float in0;
412         float in1;
413         float sc0;
414         float maxabslr;
415
416         float ratio = *acomp->ratio;
417         float thresdb = *acomp->thresdb;
418         float makeup_target = from_dB(*acomp->makeup);
419         float makeup_gain = acomp->makeup_gain;
420
421         const const float tau = acomp->tau;
422
423         if (*acomp->enable <= 0) {
424                 ratio = 1.f;
425                 thresdb = 0.f;
426                 makeup_target = 1.f;
427         }
428
429 #ifdef LV2_EXTENDED
430         if (acomp->v_knee != *acomp->knee) {
431                 acomp->v_knee = *acomp->knee;
432                 acomp->need_expose = true;
433         }
434
435         if (acomp->v_ratio != ratio) {
436                 acomp->v_ratio = ratio;
437                 acomp->need_expose = true;
438         }
439
440         if (acomp->v_thresdb != thresdb) {
441                 acomp->v_thresdb = thresdb;
442                 acomp->need_expose = true;
443         }
444 #endif
445
446         float in_peak = 0;
447
448         for (i = 0; i < n_samples; i++) {
449                 in0 = input0[i];
450                 in1 = input1[i];
451                 sc0 = sc[i];
452                 maxabslr = fmaxf(fabs(in0), fabs(in1));
453                 ingain = usesidechain ? fabs(sc0) : maxabslr;
454                 in_peak = fmaxf (in_peak, ingain);
455                 Lyg = 0.f;
456                 Lxg = (ingain==0.f) ? -160.f : to_dB(ingain);
457                 Lxg = sanitize_denormal(Lxg);
458
459
460                 if (2.f*(Lxg-thresdb) < -width) {
461                         Lyg = Lxg;
462                 } else if (2.f*(Lxg-thresdb) > width) {
463                         Lyg = thresdb + (Lxg-thresdb)/ratio;
464                         Lyg = sanitize_denormal(Lyg);
465                 } else {
466                         Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);
467                 }
468
469                 Lxl = Lxg - Lyg;
470
471                 acomp->old_y1 = sanitize_denormal(acomp->old_y1);
472                 acomp->old_yl = sanitize_denormal(acomp->old_yl);
473                 Ly1 = fmaxf(Lxl, release_coeff * acomp->old_y1+(1.f-release_coeff)*Lxl);
474                 Lyl = attack_coeff * acomp->old_yl+(1.f-attack_coeff)*Ly1;
475                 Ly1 = sanitize_denormal(Ly1);
476                 Lyl = sanitize_denormal(Lyl);
477
478                 cdb = -Lyl;
479                 Lgain = from_dB(cdb);
480
481                 *(acomp->gainr) = Lyl;
482
483                 lgaininp = in0 * Lgain;
484                 rgaininp = in1 * Lgain;
485
486                 makeup_gain += tau * (makeup_target - makeup_gain) + 1e-12;
487
488                 output0[i] = lgaininp * makeup_gain;
489                 output1[i] = rgaininp * makeup_gain;
490
491                 max = (fmaxf(fabs(output0[i]), fabs(output1[i])) > max) ? fmaxf(fabs(output0[i]), fabs(output1[i])) : sanitize_denormal(max);
492
493                 // TODO re-use local variables on stack
494                 // store values back to acomp at the end of the inner-loop
495                 acomp->old_yl = Lyl;
496                 acomp->old_y1 = Ly1;
497                 acomp->old_yg = Lyg;
498         }
499
500         *(acomp->outlevel) = (max < 0.0056f) ? -45.f : to_dB(max);
501         acomp->makeup_gain = makeup_gain;
502
503 #ifdef LV2_EXTENDED
504         acomp->v_lvl += .1 * (in_peak - acomp->v_lvl) + 1e-12;  // crude LPF TODO use n_samples/rate TC
505         if (!isfinite_local (acomp->v_lvl)) {
506                 acomp->v_lvl = 0.f;
507         }
508         const float v_lvl_in = (acomp->v_lvl < 0.001f) ? -60.f : to_dB(acomp->v_lvl);
509         const float v_lvl_out = (max < 0.001f) ? -60.f : to_dB(max);
510         if (fabsf (acomp->v_lvl_out - v_lvl_out) >= 1 || fabsf (acomp->v_lvl_in - v_lvl_in) >= 1) {
511                 // >= 1dB difference
512                 acomp->need_expose = true;
513                 acomp->v_lvl_in = v_lvl_in;
514                 acomp->v_lvl_out = v_lvl_out - to_dB(makeup_gain);
515         }
516         if (acomp->need_expose && acomp->queue_draw) {
517                 acomp->need_expose = false;
518                 acomp->queue_draw->queue_draw (acomp->queue_draw->handle);
519         }
520 #endif
521 }
522
523 static void
524 deactivate(LV2_Handle instance)
525 {
526         activate(instance);
527 }
528
529 static void
530 cleanup(LV2_Handle instance)
531 {
532 #ifdef LV2_EXTENDED
533         AComp* acomp = (AComp*)instance;
534         if (acomp->display) {
535                 cairo_surface_destroy (acomp->display);
536         }
537 #endif
538
539         free(instance);
540 }
541
542
543 #ifndef MIN
544 #define MIN(A,B) ((A) < (B)) ? (A) : (B)
545 #endif
546
547 #ifdef LV2_EXTENDED
548 static float
549 comp_curve (AComp* self, float xg) {
550         const float knee = self->v_knee;
551         const float ratio = self->v_ratio;
552         const float thresdb = self->v_thresdb;
553
554         const float width = 6.f * knee + 0.01f;
555         float yg = 0.f;
556
557         if (2.f * (xg - thresdb) < -width) {
558                 yg = xg;
559         } else if (2.f * (xg - thresdb) > width) {
560                 yg = thresdb + (xg - thresdb) / ratio;
561         } else {
562                 yg = xg + (1.f / ratio - 1.f ) * (xg - thresdb + width / 2.f) * (xg - thresdb + width / 2.f) / (2.f * width);
563         }
564         return yg;
565 }
566
567 static LV2_Inline_Display_Image_Surface *
568 render_inline (LV2_Handle instance, uint32_t w, uint32_t max_h)
569 {
570         AComp* self = (AComp*)instance;
571         uint32_t h = MIN (w, max_h);
572
573         if (!self->display || self->w != w || self->h != h) {
574                 if (self->display) cairo_surface_destroy(self->display);
575                 self->display = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
576                 self->w = w;
577                 self->h = h;
578         }
579
580         cairo_t* cr = cairo_create (self->display);
581
582         // clear background
583         cairo_rectangle (cr, 0, 0, w, h);
584         cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
585         cairo_fill (cr);
586
587         cairo_set_line_width(cr, 1.0);
588
589         // draw grid 10dB steps
590         const double dash1[] = {1, 2};
591         const double dash2[] = {1, 3};
592         cairo_save (cr);
593         cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
594         cairo_set_dash(cr, dash2, 2, 2);
595         cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
596
597         for (uint32_t d = 1; d < 6; ++d) {
598                 const float x = -.5 + floorf (w * (d * 10.f / 60.f));
599                 const float y = -.5 + floorf (h * (d * 10.f / 60.f));
600
601                 cairo_move_to (cr, x, 0);
602                 cairo_line_to (cr, x, h);
603                 cairo_stroke (cr);
604
605                 cairo_move_to (cr, 0, y);
606                 cairo_line_to (cr, w, y);
607                 cairo_stroke (cr);
608         }
609         if (self->v_thresdb < 0) {
610                 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 1.0);
611                 const float y = -.5 + floorf (h * (self->v_thresdb / -60.f));
612                 cairo_set_dash(cr, dash1, 2, 2);
613                 cairo_move_to (cr, 0, y);
614                 cairo_line_to (cr, w, y);
615                 cairo_stroke (cr);
616                 cairo_move_to (cr, 0, h);
617                 cairo_line_to (cr, w, 0);
618                 cairo_stroke (cr);
619         }
620         cairo_restore (cr);
621
622
623         // draw curve
624         cairo_set_source_rgba (cr, .8, .8, .8, 1.0);
625         cairo_move_to (cr, 0, h);
626
627         for (uint32_t x = 0; x < w; ++x) {
628                 // plot -60..0  dB
629                 const float x_db = 60.f * (-1.f + x / (float)w);
630                 const float y_db = comp_curve (self, x_db);
631                 const float y = h * (y_db / -60.f);
632                 cairo_line_to (cr, x, y);
633         }
634         cairo_stroke_preserve (cr);
635
636         cairo_line_to (cr, w, h);
637         cairo_close_path (cr);
638         cairo_clip (cr);
639
640         // draw signal level & reduction/gradient
641         const float top = comp_curve (self, 0);
642         cairo_pattern_t* pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, h);
643         if (top > self->v_thresdb) {
644                 cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.8, 0.1, 0.1, 0.5);
645                 cairo_pattern_add_color_stop_rgba (pat, top / -60.f, 0.8, 0.1, 0.1, 0.5);
646         }
647         if (self->v_knee > 0) {
648                 cairo_pattern_add_color_stop_rgba (pat, (self->v_thresdb / -60.f), 0.7, 0.7, 0.2, 0.5);
649                 cairo_pattern_add_color_stop_rgba (pat, ((self->v_thresdb - self->v_knee) / -60.f), 0.5, 0.5, 0.5, 0.5);
650         } else {
651                 cairo_pattern_add_color_stop_rgba (pat, (self->v_thresdb / -60.f), 0.7, 0.7, 0.2, 0.5);
652                 cairo_pattern_add_color_stop_rgba (pat, ((self->v_thresdb - .01) / -60.f), 0.5, 0.5, 0.5, 0.5);
653         }
654         cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.5, 0.5, 0.5, 0.5);
655
656         // maybe cut off at x-position?
657         const float x = w * (self->v_lvl_in + 60) / 60.f;
658         //const float y = h * (self->v_lvl_out + 60) / 60.f;
659         cairo_rectangle (cr, 0, h - x, x, h);
660         if (self->v_ratio > 1.0) {
661                 cairo_set_source (cr, pat);
662         } else {
663                 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
664         }
665         cairo_fill (cr);
666
667         cairo_pattern_destroy (pat); // TODO cache pattern
668
669
670         // create RGBA surface
671         cairo_destroy (cr);
672         cairo_surface_flush (self->display);
673         self->surf.width = cairo_image_surface_get_width (self->display);
674         self->surf.height = cairo_image_surface_get_height (self->display);
675         self->surf.stride = cairo_image_surface_get_stride (self->display);
676         self->surf.data = cairo_image_surface_get_data  (self->display);
677
678         return &self->surf;
679 }
680 #endif
681
682 static const void*
683 extension_data(const char* uri)
684 {
685 #ifdef LV2_EXTENDED
686         static const LV2_Inline_Display_Interface display  = { render_inline };
687         if (!strcmp(uri, LV2_INLINEDISPLAY__interface)) {
688                 return &display;
689         }
690 #endif
691         return NULL;
692 }
693
694 static const LV2_Descriptor descriptor_mono = {
695         ACOMP_URI,
696         instantiate,
697         connect_mono,
698         activate,
699         run_mono,
700         deactivate,
701         cleanup,
702         extension_data
703 };
704
705 static const LV2_Descriptor descriptor_stereo = {
706         ACOMP_STEREO_URI,
707         instantiate,
708         connect_stereo,
709         activate,
710         run_stereo,
711         deactivate,
712         cleanup,
713         extension_data
714 };
715
716 LV2_SYMBOL_EXPORT
717 const LV2_Descriptor*
718 lv2_descriptor(uint32_t index)
719 {
720         switch (index) {
721         case 0:
722                 return &descriptor_mono;
723         case 1:
724                 return &descriptor_stereo;
725         default:
726                 return NULL;
727         }
728 }