2 * Copyright (C) 2016 Damien Zammit <damien@zamaudio.com>
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.
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.
21 #include <cairo/cairo.h>
22 #include "ardour/lv2_extensions.h"
25 #include "lv2/lv2plug.in/ns/lv2core/lv2.h"
27 #define ACOMP_URI "urn:ardour:a-comp"
28 #define ACOMP_STEREO_URI "urn:ardour:a-comp#stereo"
30 #define RESET_PEAK_AFTER_SECONDS 3
33 # define M_PI 3.14159265358979323846
38 #define isfinite_local(val) (bool)_finite((double)val)
40 #define isfinite_local isfinite
89 LV2_Inline_Display_Image_Surface surf;
91 cairo_surface_t* display;
92 LV2_Inline_Display* queue_draw;
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
109 uint32_t peakdb_samples;
114 instantiate(const LV2_Descriptor* descriptor,
116 const char* bundle_path,
117 const LV2_Feature* const* features)
119 AComp* acomp = (AComp*)calloc(1, sizeof(AComp));
121 for (int i=0; features[i]; ++i) {
123 if (!strcmp(features[i]->URI, LV2_INLINEDISPLAY__queue_draw)) {
124 acomp->queue_draw = (LV2_Inline_Display*) features[i]->data;
130 acomp->makeup_gain = 1.f;
132 acomp->need_expose = true;
133 acomp->v_lvl_out = -70.f;
136 return (LV2_Handle)acomp;
140 connect_port(LV2_Handle instance,
144 AComp* acomp = (AComp*)instance;
146 switch ((PortIndex)port) {
148 acomp->attack = (float*)data;
151 acomp->release = (float*)data;
154 acomp->knee = (float*)data;
157 acomp->ratio = (float*)data;
159 case ACOMP_THRESHOLD:
160 acomp->thresdb = (float*)data;
163 acomp->makeup = (float*)data;
166 acomp->gainr = (float*)data;
169 acomp->outlevel = (float*)data;
172 acomp->inlevel = (float*)data;
174 case ACOMP_SIDECHAIN:
175 acomp->sidechain = (float*)data;
178 acomp->enable = (float*)data;
186 connect_mono(LV2_Handle instance,
190 AComp* acomp = (AComp*)instance;
191 connect_port (instance, port, data);
193 switch ((PortIndex)port) {
195 acomp->input0 = (float*)data;
198 acomp->sc = (float*)data;
201 acomp->output0 = (float*)data;
209 connect_stereo(LV2_Handle instance,
213 AComp* acomp = (AComp*)instance;
214 connect_port (instance, port, data);
216 switch ((PortIndex)port) {
218 acomp->input0 = (float*)data;
221 acomp->input1 = (float*)data;
224 acomp->sc = (float*)data;
227 acomp->output0 = (float*)data;
230 acomp->output1 = (float*)data;
237 // Force already-denormal float value to zero
239 sanitize_denormal(float value) {
240 if (!isnormal(value)) {
248 return (exp(gdb/20.f*log(10.f)));
253 return (20.f*log10(g));
257 activate(LV2_Handle instance)
259 AComp* acomp = (AComp*)instance;
261 *(acomp->gainr) = 0.0f;
262 *(acomp->outlevel) = -70.0f;
263 *(acomp->inlevel) = -160.f;
266 acomp->v_peakdb = -160.f;
267 acomp->peakdb_samples = 0;
272 run_mono(LV2_Handle instance, uint32_t n_samples)
274 AComp* acomp = (AComp*)instance;
276 const float* const input = acomp->input0;
277 const float* const sc = acomp->sc;
278 float* const output = acomp->output0;
280 float srate = acomp->srate;
281 float width = (6.f * *(acomp->knee)) + 0.01;
282 float attack_coeff = exp(-1000.f/(*(acomp->attack) * srate));
283 float release_coeff = exp(-1000.f/(*(acomp->release) * srate));
286 float lgaininp = 0.f;
290 float old_gainr = *acomp->gainr;
292 int usesidechain = (*(acomp->sidechain) <= 0.f) ? 0 : 1;
298 float ratio = *acomp->ratio;
299 float thresdb = *acomp->thresdb;
300 float makeup = *acomp->makeup;
301 float makeup_target = from_dB(makeup);
302 float makeup_gain = acomp->makeup_gain;
304 const float tau = (1.0 - exp (-2.f * M_PI * n_samples * 25.f / acomp->srate));
306 if (*acomp->enable <= 0) {
314 if (acomp->v_knee != *acomp->knee) {
315 acomp->v_knee = *acomp->knee;
316 acomp->need_expose = true;
319 if (acomp->v_ratio != ratio) {
320 acomp->v_ratio = ratio;
321 acomp->need_expose = true;
324 if (acomp->v_thresdb != thresdb) {
325 acomp->v_thresdb = thresdb;
326 acomp->need_expose = true;
329 if (acomp->v_makeup != makeup) {
330 acomp->v_makeup = makeup;
331 acomp->need_expose = true;
335 float in_peak_db = -160.f;
336 float max_gainr = 0.f;
338 for (i = 0; i < n_samples; i++) {
341 ingain = usesidechain ? fabs(sc0) : fabs(in0);
343 Lxg = (ingain==0.f) ? -160.f : to_dB(ingain);
344 Lxg = sanitize_denormal(Lxg);
346 if (Lxg > in_peak_db) {
350 if (2.f*(Lxg-thresdb) < -width) {
352 } else if (2.f*(Lxg-thresdb) > width) {
353 Lyg = thresdb + (Lxg-thresdb)/ratio;
354 Lyg = sanitize_denormal(Lyg);
356 Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);
359 current_gainr = Lxg - Lyg;
361 if (current_gainr < old_gainr) {
362 current_gainr = release_coeff*old_gainr + (1.f-release_coeff)*current_gainr;
363 } else if (current_gainr > old_gainr) {
364 current_gainr = attack_coeff*old_gainr + (1.f-attack_coeff)*current_gainr;
367 current_gainr = sanitize_denormal(current_gainr);
369 Lgain = from_dB(-current_gainr);
371 old_gainr = current_gainr;
373 *(acomp->gainr) = current_gainr;
374 if (current_gainr > max_gainr) {
375 max_gainr = current_gainr;
378 lgaininp = in0 * Lgain;
380 output[i] = lgaininp * makeup_gain;
382 max = (fabsf(output[i]) > max) ? fabsf(output[i]) : sanitize_denormal(max);
385 if ( fabsf(makeup_target - makeup_gain) < 1e-6 ) {
386 makeup_gain = makeup_target;
388 makeup_gain += tau * (makeup_target - makeup_gain) + 1e-12;
391 *(acomp->outlevel) = (max < 0.0056f) ? -70.f : to_dB(max);
392 *(acomp->inlevel) = in_peak_db;
393 acomp->makeup_gain = makeup_gain;
396 acomp->v_gainr = max_gainr;
398 if (in_peak_db > acomp->v_peakdb) {
399 acomp->v_peakdb = in_peak_db;
400 acomp->peakdb_samples = 0;
402 acomp->peakdb_samples += n_samples;
403 if ((float)acomp->peakdb_samples/acomp->srate > RESET_PEAK_AFTER_SECONDS) {
404 acomp->v_peakdb = in_peak_db;
405 acomp->peakdb_samples = 0;
406 acomp->need_expose = true;
410 const float v_lvl_in = in_peak_db;
411 const float v_lvl_out = *acomp->outlevel;
415 const float knee_lim_gr = (1.f - 1.f/ratio) * width/2.f;
417 if (acomp->v_gainr > knee_lim_gr) {
418 state_x = acomp->v_gainr / (1.f - 1.f/ratio) + thresdb;
420 state_x = sqrt ( (2.f*width*acomp->v_gainr) / (1.f-1.f/ratio) ) + thresdb - width/2.f;
423 if (fabsf (acomp->v_lvl_out - v_lvl_out) >= .1f ||
424 fabsf (acomp->v_lvl_in - v_lvl_in) >= .1f ||
425 fabsf (acomp->v_state_x - state_x) >= .1f ) {
426 // >= 0.1dB difference
427 acomp->need_expose = true;
428 acomp->v_lvl_in = v_lvl_in;
429 acomp->v_lvl_out = v_lvl_out;
430 acomp->v_state_x = state_x;
432 if (acomp->need_expose && acomp->queue_draw) {
433 acomp->need_expose = false;
434 acomp->queue_draw->queue_draw (acomp->queue_draw->handle);
440 run_stereo(LV2_Handle instance, uint32_t n_samples)
442 AComp* acomp = (AComp*)instance;
444 const float* const input0 = acomp->input0;
445 const float* const input1 = acomp->input1;
446 const float* const sc = acomp->sc;
447 float* const output0 = acomp->output0;
448 float* const output1 = acomp->output1;
450 float srate = acomp->srate;
451 float width = (6.f * *(acomp->knee)) + 0.01;
452 float attack_coeff = exp(-1000.f/(*(acomp->attack) * srate));
453 float release_coeff = exp(-1000.f/(*(acomp->release) * srate));
456 float lgaininp = 0.f;
457 float rgaininp = 0.f;
461 float old_gainr = *acomp->gainr;
463 int usesidechain = (*(acomp->sidechain) <= 0.f) ? 0 : 1;
471 float ratio = *acomp->ratio;
472 float thresdb = *acomp->thresdb;
473 float makeup = *acomp->makeup;
474 float makeup_target = from_dB(makeup);
475 float makeup_gain = acomp->makeup_gain;
477 const float tau = (1.0 - exp (-2.f * M_PI * n_samples * 25.f / acomp->srate));
479 if (*acomp->enable <= 0) {
487 if (acomp->v_knee != *acomp->knee) {
488 acomp->v_knee = *acomp->knee;
489 acomp->need_expose = true;
492 if (acomp->v_ratio != ratio) {
493 acomp->v_ratio = ratio;
494 acomp->need_expose = true;
497 if (acomp->v_thresdb != thresdb) {
498 acomp->v_thresdb = thresdb;
499 acomp->need_expose = true;
502 if (acomp->v_makeup != makeup) {
503 acomp->v_makeup = makeup;
504 acomp->need_expose = true;
508 float in_peak_db = -160.f;
509 float max_gainr = 0.f;
511 for (i = 0; i < n_samples; i++) {
515 maxabslr = fmaxf(fabs(in0), fabs(in1));
516 ingain = usesidechain ? fabs(sc0) : maxabslr;
518 Lxg = (ingain==0.f) ? -160.f : to_dB(ingain);
519 Lxg = sanitize_denormal(Lxg);
520 if (Lxg > in_peak_db) {
524 if (2.f*(Lxg-thresdb) < -width) {
526 } else if (2.f*(Lxg-thresdb) > width) {
527 Lyg = thresdb + (Lxg-thresdb)/ratio;
528 Lyg = sanitize_denormal(Lyg);
530 Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);
533 current_gainr = Lxg - Lyg;
535 if (current_gainr < old_gainr) {
536 current_gainr = release_coeff*old_gainr + (1.f-release_coeff)*current_gainr;
537 } else if (current_gainr > old_gainr) {
538 current_gainr = attack_coeff*old_gainr + (1.f-attack_coeff)*current_gainr;
541 current_gainr = sanitize_denormal(current_gainr);
543 Lgain = from_dB(-current_gainr);
545 old_gainr = current_gainr;
547 *(acomp->gainr) = current_gainr;
548 if (current_gainr > max_gainr) {
549 max_gainr = current_gainr;
552 lgaininp = in0 * Lgain;
553 rgaininp = in1 * Lgain;
555 output0[i] = lgaininp * makeup_gain;
556 output1[i] = rgaininp * makeup_gain;
558 max = (fmaxf(fabs(output0[i]), fabs(output1[i])) > max) ? fmaxf(fabs(output0[i]), fabs(output1[i])) : sanitize_denormal(max);
561 if ( fabsf(makeup_target - makeup_gain) < 1e-6 ) {
562 makeup_gain = makeup_target;
564 makeup_gain += tau * (makeup_target - makeup_gain) + 1e-12;
567 *(acomp->outlevel) = (max < 0.0056f) ? -70.f : to_dB(max);
568 *(acomp->inlevel) = in_peak_db;
569 acomp->makeup_gain = makeup_gain;
572 acomp->v_gainr = max_gainr;
574 if (in_peak_db > acomp->v_peakdb) {
575 acomp->v_peakdb = in_peak_db;
576 acomp->peakdb_samples = 0;
578 acomp->peakdb_samples += n_samples;
579 if ((float)acomp->peakdb_samples/acomp->srate > RESET_PEAK_AFTER_SECONDS) {
580 acomp->v_peakdb = in_peak_db;
581 acomp->peakdb_samples = 0;
582 acomp->need_expose = true;
586 const float v_lvl_in = in_peak_db;
587 const float v_lvl_out = *acomp->outlevel;
591 const float knee_lim_gr = (1.f - 1.f/ratio) * width/2.f;
593 if (acomp->v_gainr > knee_lim_gr) {
594 state_x = acomp->v_gainr / (1.f - 1.f/ratio) + thresdb;
596 state_x = sqrt ( (2.f*width*acomp->v_gainr) / (1.f-1.f/ratio) ) + thresdb - width/2.f;
599 if (fabsf (acomp->v_lvl_out - v_lvl_out) >= .1f ||
600 fabsf (acomp->v_lvl_in - v_lvl_in) >= .1f ||
601 fabsf (acomp->v_state_x - state_x) >= .1f ) {
602 // >= 0.1dB difference
603 acomp->need_expose = true;
604 acomp->v_lvl_in = v_lvl_in;
605 acomp->v_lvl_out = v_lvl_out;
606 acomp->v_state_x = state_x;
608 if (acomp->need_expose && acomp->queue_draw) {
609 acomp->need_expose = false;
610 acomp->queue_draw->queue_draw (acomp->queue_draw->handle);
616 deactivate(LV2_Handle instance)
622 cleanup(LV2_Handle instance)
625 AComp* acomp = (AComp*)instance;
626 if (acomp->display) {
627 cairo_surface_destroy (acomp->display);
636 #define MIN(A,B) ((A) < (B)) ? (A) : (B)
641 comp_curve (const AComp* self, float xg) {
642 const float knee = self->v_knee;
643 const float ratio = self->v_ratio;
644 const float thresdb = self->v_thresdb;
645 const float makeup = self->v_makeup;
647 const float width = 6.f * knee + 0.01f;
650 if (2.f * (xg - thresdb) < -width) {
652 } else if (2.f * (xg - thresdb) > width) {
653 yg = thresdb + (xg - thresdb) / ratio;
655 yg = xg + (1.f / ratio - 1.f ) * (xg - thresdb + width / 2.f) * (xg - thresdb + width / 2.f) / (2.f * width);
664 render_inline_full (cairo_t* cr, const AComp* self)
666 const float w = self->w;
667 const float h = self->h;
669 const float makeup_thres = self->v_thresdb + self->v_makeup;
672 cairo_rectangle (cr, 0, 0, w, h);
673 cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
676 cairo_set_line_width(cr, 1.0);
678 // draw grid 10dB steps
679 const double dash1[] = {1, 2};
680 const double dash2[] = {1, 3};
682 cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
683 cairo_set_dash(cr, dash2, 2, 2);
684 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
686 for (uint32_t d = 1; d < 7; ++d) {
687 const float x = -.5 + floorf (w * (d * 10.f / 70.f));
688 const float y = -.5 + floorf (h * (d * 10.f / 70.f));
690 cairo_move_to (cr, x, 0);
691 cairo_line_to (cr, x, h);
694 cairo_move_to (cr, 0, y);
695 cairo_line_to (cr, w, y);
698 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 1.0);
699 cairo_set_dash(cr, dash1, 2, 2);
700 if (self->v_thresdb < 0) {
701 const float y = -.5 + floorf (h * ((makeup_thres - 10.f) / -70.f));
702 cairo_move_to (cr, 0, y);
703 cairo_line_to (cr, w, y);
707 cairo_move_to (cr, 0, h);
708 cairo_line_to (cr, w, 0);
713 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
714 const float x = -.5 + floorf (w * (60.f / 70.f));
715 const float y = -.5 + floorf (h * (10.f / 70.f));
716 cairo_move_to (cr, x, 0);
717 cairo_line_to (cr, x, h);
719 cairo_move_to (cr, 0, y);
720 cairo_line_to (cr, w, y);
725 const float x = -.5 + floorf (w * (62.5f / 70.f));
726 const float y = -.5 + floorf (h * (10.0f / 70.f));
727 const float wd = floorf (w * (5.f / 70.f));
728 const float ht = floorf (h * (55.f / 70.f));
729 cairo_rectangle (cr, x, y, wd, ht);
732 const float h_gr = fminf (ht, floorf (h * self->v_gainr / 70.f));
733 cairo_set_source_rgba (cr, 0.95, 0.0, 0.0, 1.0);
734 cairo_rectangle (cr, x, y, wd, h_gr);
736 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
737 cairo_rectangle (cr, x, y, wd, ht);
738 cairo_set_source_rgba (cr, 0.75, 0.75, 0.75, 1.0);
743 cairo_set_source_rgba (cr, .8, .8, .8, 1.0);
745 const float state_x = w * (1.f - (10.f-self->v_state_x)/70.f);
746 const float state_y = h * (comp_curve (self, self->v_state_x) - 10.f) / -70.f;
748 cairo_arc (cr, state_x, state_y, 3.f, 0.f, 2.f*M_PI);
752 cairo_set_source_rgba (cr, .8, .8, .8, 1.0);
753 cairo_move_to (cr, 0, h);
755 for (uint32_t x = 0; x < w; ++x) {
757 const float x_db = 70.f * (-1.f + x / (float)w) + 10.f;
758 const float y_db = comp_curve (self, x_db) - 10.f;
759 const float y = h * (y_db / -70.f);
760 cairo_line_to (cr, x, y);
762 cairo_stroke_preserve (cr);
764 cairo_line_to (cr, w, h);
765 cairo_close_path (cr);
768 // draw signal level & reduction/gradient
769 const float top = comp_curve (self, 0) - 10.f;
770 cairo_pattern_t* pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, h);
771 if (top > makeup_thres - 10.f) {
772 cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.8, 0.1, 0.1, 0.5);
773 cairo_pattern_add_color_stop_rgba (pat, top / -70.f, 0.8, 0.1, 0.1, 0.5);
775 if (self->v_knee > 0) {
776 cairo_pattern_add_color_stop_rgba (pat, ((makeup_thres -10.f) / -70.f), 0.7, 0.7, 0.2, 0.5);
777 cairo_pattern_add_color_stop_rgba (pat, ((makeup_thres - self->v_knee - 10.f) / -70.f), 0.5, 0.5, 0.5, 0.5);
779 cairo_pattern_add_color_stop_rgba (pat, ((makeup_thres - 10.f)/ -70.f), 0.7, 0.7, 0.2, 0.5);
780 cairo_pattern_add_color_stop_rgba (pat, ((makeup_thres - 10.01f) / -70.f), 0.5, 0.5, 0.5, 0.5);
782 cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.5, 0.5, 0.5, 0.5);
784 // maybe cut off at x-position?
785 const float x = w * (self->v_lvl_in + 60) / 70.f;
786 const float y = x + h*self->v_makeup;
787 cairo_rectangle (cr, 0, h - y, x, y);
788 if (self->v_ratio > 1.0) {
789 cairo_set_source (cr, pat);
791 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
795 cairo_pattern_destroy (pat); // TODO cache pattern
799 render_inline_only_bars (cairo_t* cr, const AComp* self)
801 const float w = self->w;
802 const float h = self->h;
804 cairo_rectangle (cr, 0, 0, w, h);
805 cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
811 const float ht = 0.25f * h;
813 const float x1 = w*0.05;
814 const float wd = w - 2.0f*x1;
816 const float y1 = 0.17*h;
817 const float y2 = h - y1 - ht;
819 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
821 cairo_rectangle (cr, x1, y1, wd, ht);
824 cairo_rectangle (cr, x1, y2, wd, ht);
827 cairo_set_source_rgba (cr, 0.75, 0.0, 0.0, 1.0);
828 const float w_gr = (self->v_gainr > 60.f) ? wd : wd * self->v_gainr * (1.f/60.f);
829 cairo_rectangle (cr, x1+wd-w_gr, y2, w_gr, ht);
832 if (self->v_lvl_in > -60.f) {
833 if (self->v_lvl_out > 6.f) {
834 cairo_set_source_rgba (cr, 0.75, 0.0, 0.0, 1.0);
835 } else if (self->v_lvl_out > 0.f) {
836 cairo_set_source_rgba (cr, 0.66, 0.66, 0.0, 1.0);
838 cairo_set_source_rgba (cr, 0.0, 0.66, 0.0, 1.0);
840 const float w_g = (self->v_lvl_in > 10.f) ? wd : wd * (60.f+self->v_lvl_in) / 70.f;
841 cairo_rectangle (cr, x1, y1, w_g, ht);
845 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
847 const float tck = 0.33*ht;
849 cairo_set_line_width (cr, .5);
851 for (uint32_t d = 1; d < 7; ++d) {
852 const float x = x1 + (d * wd * (10.f / 70.f));
854 cairo_move_to (cr, x, y1);
855 cairo_line_to (cr, x, y1+tck);
857 cairo_move_to (cr, x, y1+ht);
858 cairo_line_to (cr, x, y1+ht-tck);
860 cairo_move_to (cr, x, y2);
861 cairo_line_to (cr, x, y2+tck);
863 cairo_move_to (cr, x, y2+ht);
864 cairo_line_to (cr, x, y2+ht-tck);
869 const float x_0dB = x1 + wd*(60.f/70.f);
871 cairo_move_to (cr, x_0dB, y1);
872 cairo_line_to (cr, x_0dB, y1+ht);
874 cairo_rectangle (cr, x1, y1, wd, ht);
875 cairo_rectangle (cr, x1, y2, wd, ht);
878 cairo_set_line_width (cr, 2.0);
880 // visualize threshold
881 const float tr = x1 + wd * (60.f+self->v_thresdb) / 70.f;
882 cairo_set_source_rgba (cr, 0.95, 0.95, 0.0, 1.0);
883 cairo_move_to (cr, tr, y1);
884 cairo_line_to (cr, tr, y1+ht);
888 const float reduced_0dB = self->v_thresdb * (1.f - 1.f/self->v_ratio);
889 const float rt = x1 + wd * (60.f+reduced_0dB) / 70.f;
890 cairo_set_source_rgba (cr, 0.95, 0.0, 0.0, 1.0);
891 cairo_move_to (cr, rt, y1);
892 cairo_line_to (cr, rt, y1+ht);
896 if (self->v_peakdb > -60.f) {
897 cairo_set_source_rgba (cr, 0.0, 1.0, 0.0, 1.0);
898 const float pk = (self->v_peakdb > 10.f) ? x1+wd : wd * (60.f+self->v_peakdb) / 70.f;
899 cairo_move_to (cr, pk, y1);
900 cairo_line_to (cr, pk, y1+ht);
905 static LV2_Inline_Display_Image_Surface *
906 render_inline (LV2_Handle instance, uint32_t w, uint32_t max_h)
908 AComp* self = (AComp*)instance;
910 uint32_t h = MIN (w, max_h);
915 if (!self->display || self->w != w || self->h != h) {
916 if (self->display) cairo_surface_destroy(self->display);
917 self->display = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
922 cairo_t* cr = cairo_create (self->display);
925 render_inline_full (cr, self);
927 render_inline_only_bars (cr, self);
932 cairo_surface_flush (self->display);
933 self->surf.width = cairo_image_surface_get_width (self->display);
934 self->surf.height = cairo_image_surface_get_height (self->display);
935 self->surf.stride = cairo_image_surface_get_stride (self->display);
936 self->surf.data = cairo_image_surface_get_data (self->display);
943 extension_data(const char* uri)
946 static const LV2_Inline_Display_Interface display = { render_inline };
947 if (!strcmp(uri, LV2_INLINEDISPLAY__interface)) {
954 static const LV2_Descriptor descriptor_mono = {
965 static const LV2_Descriptor descriptor_stereo = {
977 const LV2_Descriptor*
978 lv2_descriptor(uint32_t index)
982 return &descriptor_mono;
984 return &descriptor_stereo;