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
57 ACOMP_FULL_INLINEDISP,
80 float* full_inline_display;
93 LV2_Inline_Display_Image_Surface surf;
95 cairo_surface_t* display;
96 LV2_Inline_Display* queue_draw;
99 /* ports pointers are only valid during run so we'll
100 * have to cache them for the display, besides
101 * we do want to check for changes
112 bool v_full_inline_display;
115 uint32_t peakdb_samples;
120 instantiate(const LV2_Descriptor* descriptor,
122 const char* bundle_path,
123 const LV2_Feature* const* features)
125 AComp* acomp = (AComp*)calloc(1, sizeof(AComp));
127 for (int i=0; features[i]; ++i) {
129 if (!strcmp(features[i]->URI, LV2_INLINEDISPLAY__queue_draw)) {
130 acomp->queue_draw = (LV2_Inline_Display*) features[i]->data;
136 acomp->makeup_gain = 1.f;
138 acomp->need_expose = true;
139 acomp->v_lvl_out = -70.f;
142 return (LV2_Handle)acomp;
146 connect_port(LV2_Handle instance,
150 AComp* acomp = (AComp*)instance;
152 switch ((PortIndex)port) {
154 acomp->attack = (float*)data;
157 acomp->release = (float*)data;
160 acomp->knee = (float*)data;
163 acomp->ratio = (float*)data;
165 case ACOMP_THRESHOLD:
166 acomp->thresdb = (float*)data;
169 acomp->makeup = (float*)data;
172 acomp->gainr = (float*)data;
175 acomp->outlevel = (float*)data;
178 acomp->inlevel = (float*)data;
180 case ACOMP_SIDECHAIN:
181 acomp->sidechain = (float*)data;
184 acomp->enable = (float*)data;
186 case ACOMP_FULL_INLINEDISP:
187 acomp->full_inline_display = (float*)data;
195 connect_mono(LV2_Handle instance,
199 AComp* acomp = (AComp*)instance;
200 connect_port (instance, port, data);
202 switch ((PortIndex)port) {
204 acomp->input0 = (float*)data;
207 acomp->sc = (float*)data;
210 acomp->output0 = (float*)data;
218 connect_stereo(LV2_Handle instance,
222 AComp* acomp = (AComp*)instance;
223 connect_port (instance, port, data);
225 switch ((PortIndex)port) {
227 acomp->input0 = (float*)data;
230 acomp->input1 = (float*)data;
233 acomp->sc = (float*)data;
236 acomp->output0 = (float*)data;
239 acomp->output1 = (float*)data;
246 // Force already-denormal float value to zero
248 sanitize_denormal(float value) {
249 if (!isnormal(value)) {
257 return (exp(gdb/20.f*log(10.f)));
262 return (20.f*log10(g));
266 activate(LV2_Handle instance)
268 AComp* acomp = (AComp*)instance;
270 *(acomp->gainr) = 0.0f;
271 *(acomp->outlevel) = -70.0f;
272 *(acomp->inlevel) = -160.f;
275 acomp->v_peakdb = -160.f;
276 acomp->peakdb_samples = 0;
281 run_mono(LV2_Handle instance, uint32_t n_samples)
283 AComp* acomp = (AComp*)instance;
285 const float* const input = acomp->input0;
286 const float* const sc = acomp->sc;
287 float* const output = acomp->output0;
289 float srate = acomp->srate;
290 float width = (6.f * *(acomp->knee)) + 0.01;
291 float attack_coeff = exp(-1000.f/(*(acomp->attack) * srate));
292 float release_coeff = exp(-1000.f/(*(acomp->release) * srate));
295 float lgaininp = 0.f;
299 float old_gainr = *acomp->gainr;
301 int usesidechain = (*(acomp->sidechain) <= 0.f) ? 0 : 1;
307 float ratio = *acomp->ratio;
308 float thresdb = *acomp->thresdb;
309 float makeup = *acomp->makeup;
310 float makeup_target = from_dB(makeup);
311 float makeup_gain = acomp->makeup_gain;
313 const float tau = (1.0 - exp (-2.f * M_PI * n_samples * 25.f / acomp->srate));
315 if (*acomp->enable <= 0) {
323 if (acomp->v_knee != *acomp->knee) {
324 acomp->v_knee = *acomp->knee;
325 acomp->need_expose = true;
328 if (acomp->v_ratio != ratio) {
329 acomp->v_ratio = ratio;
330 acomp->need_expose = true;
333 if (acomp->v_thresdb != thresdb) {
334 acomp->v_thresdb = thresdb;
335 acomp->need_expose = true;
338 if (acomp->v_makeup != makeup) {
339 acomp->v_makeup = makeup;
340 acomp->need_expose = true;
343 bool full_inline = *acomp->full_inline_display > 0.5;
344 if (full_inline != acomp->v_full_inline_display) {
345 acomp->v_full_inline_display = full_inline;
346 acomp->need_expose = true;
350 float in_peak_db = -160.f;
351 float max_gainr = 0.f;
353 for (i = 0; i < n_samples; i++) {
356 ingain = usesidechain ? fabs(sc0) : fabs(in0);
358 Lxg = (ingain==0.f) ? -160.f : to_dB(ingain);
359 Lxg = sanitize_denormal(Lxg);
361 if (Lxg > in_peak_db) {
365 if (2.f*(Lxg-thresdb) < -width) {
367 } else if (2.f*(Lxg-thresdb) > width) {
368 Lyg = thresdb + (Lxg-thresdb)/ratio;
369 Lyg = sanitize_denormal(Lyg);
371 Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);
374 current_gainr = Lxg - Lyg;
376 if (current_gainr < old_gainr) {
377 current_gainr = release_coeff*old_gainr + (1.f-release_coeff)*current_gainr;
378 } else if (current_gainr > old_gainr) {
379 current_gainr = attack_coeff*old_gainr + (1.f-attack_coeff)*current_gainr;
382 current_gainr = sanitize_denormal(current_gainr);
384 Lgain = from_dB(-current_gainr);
386 old_gainr = current_gainr;
388 *(acomp->gainr) = current_gainr;
389 if (current_gainr > max_gainr) {
390 max_gainr = current_gainr;
393 lgaininp = in0 * Lgain;
395 output[i] = lgaininp * makeup_gain;
397 max = (fabsf(output[i]) > max) ? fabsf(output[i]) : sanitize_denormal(max);
400 if ( fabsf(makeup_target - makeup_gain) < 1e-6 ) {
401 makeup_gain = makeup_target;
403 makeup_gain += tau * (makeup_target - makeup_gain) + 1e-12;
406 *(acomp->outlevel) = (max < 0.0056f) ? -70.f : to_dB(max);
407 *(acomp->inlevel) = in_peak_db;
408 acomp->makeup_gain = makeup_gain;
411 acomp->v_gainr = max_gainr;
413 if (in_peak_db > acomp->v_peakdb) {
414 acomp->v_peakdb = in_peak_db;
415 acomp->peakdb_samples = 0;
417 acomp->peakdb_samples += n_samples;
418 if ((float)acomp->peakdb_samples/acomp->srate > RESET_PEAK_AFTER_SECONDS) {
419 acomp->v_peakdb = in_peak_db;
420 acomp->peakdb_samples = 0;
421 acomp->need_expose = true;
425 const float v_lvl_in = in_peak_db;
426 const float v_lvl_out = *acomp->outlevel;
430 const float knee_lim_gr = (1.f - 1.f/ratio) * width/2.f;
432 if (acomp->v_gainr > knee_lim_gr) {
433 state_x = acomp->v_gainr / (1.f - 1.f/ratio) + thresdb;
435 state_x = sqrt ( (2.f*width*acomp->v_gainr) / (1.f-1.f/ratio) ) + thresdb - width/2.f;
438 if (fabsf (acomp->v_lvl_out - v_lvl_out) >= .1f ||
439 fabsf (acomp->v_lvl_in - v_lvl_in) >= .1f ||
440 fabsf (acomp->v_state_x - state_x) >= .1f ) {
441 // >= 0.1dB difference
442 acomp->need_expose = true;
443 acomp->v_lvl_in = v_lvl_in;
444 acomp->v_lvl_out = v_lvl_out;
445 acomp->v_state_x = state_x;
447 if (acomp->need_expose && acomp->queue_draw) {
448 acomp->need_expose = false;
449 acomp->queue_draw->queue_draw (acomp->queue_draw->handle);
455 run_stereo(LV2_Handle instance, uint32_t n_samples)
457 AComp* acomp = (AComp*)instance;
459 const float* const input0 = acomp->input0;
460 const float* const input1 = acomp->input1;
461 const float* const sc = acomp->sc;
462 float* const output0 = acomp->output0;
463 float* const output1 = acomp->output1;
465 float srate = acomp->srate;
466 float width = (6.f * *(acomp->knee)) + 0.01;
467 float attack_coeff = exp(-1000.f/(*(acomp->attack) * srate));
468 float release_coeff = exp(-1000.f/(*(acomp->release) * srate));
471 float lgaininp = 0.f;
472 float rgaininp = 0.f;
476 float old_gainr = *acomp->gainr;
478 int usesidechain = (*(acomp->sidechain) <= 0.f) ? 0 : 1;
486 float ratio = *acomp->ratio;
487 float thresdb = *acomp->thresdb;
488 float makeup = *acomp->makeup;
489 float makeup_target = from_dB(makeup);
490 float makeup_gain = acomp->makeup_gain;
492 const float tau = (1.0 - exp (-2.f * M_PI * n_samples * 25.f / acomp->srate));
494 if (*acomp->enable <= 0) {
502 if (acomp->v_knee != *acomp->knee) {
503 acomp->v_knee = *acomp->knee;
504 acomp->need_expose = true;
507 if (acomp->v_ratio != ratio) {
508 acomp->v_ratio = ratio;
509 acomp->need_expose = true;
512 if (acomp->v_thresdb != thresdb) {
513 acomp->v_thresdb = thresdb;
514 acomp->need_expose = true;
517 if (acomp->v_makeup != makeup) {
518 acomp->v_makeup = makeup;
519 acomp->need_expose = true;
522 bool full_inline = *acomp->full_inline_display > 0.5;
523 if (full_inline != acomp->v_full_inline_display) {
524 acomp->v_full_inline_display = full_inline;
525 acomp->need_expose = true;
529 float in_peak_db = -160.f;
530 float max_gainr = 0.f;
532 for (i = 0; i < n_samples; i++) {
536 maxabslr = fmaxf(fabs(in0), fabs(in1));
537 ingain = usesidechain ? fabs(sc0) : maxabslr;
539 Lxg = (ingain==0.f) ? -160.f : to_dB(ingain);
540 Lxg = sanitize_denormal(Lxg);
541 if (Lxg > in_peak_db) {
545 if (2.f*(Lxg-thresdb) < -width) {
547 } else if (2.f*(Lxg-thresdb) > width) {
548 Lyg = thresdb + (Lxg-thresdb)/ratio;
549 Lyg = sanitize_denormal(Lyg);
551 Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);
554 current_gainr = Lxg - Lyg;
556 if (current_gainr < old_gainr) {
557 current_gainr = release_coeff*old_gainr + (1.f-release_coeff)*current_gainr;
558 } else if (current_gainr > old_gainr) {
559 current_gainr = attack_coeff*old_gainr + (1.f-attack_coeff)*current_gainr;
562 current_gainr = sanitize_denormal(current_gainr);
564 Lgain = from_dB(-current_gainr);
566 old_gainr = current_gainr;
568 *(acomp->gainr) = current_gainr;
569 if (current_gainr > max_gainr) {
570 max_gainr = current_gainr;
573 lgaininp = in0 * Lgain;
574 rgaininp = in1 * Lgain;
576 output0[i] = lgaininp * makeup_gain;
577 output1[i] = rgaininp * makeup_gain;
579 max = (fmaxf(fabs(output0[i]), fabs(output1[i])) > max) ? fmaxf(fabs(output0[i]), fabs(output1[i])) : sanitize_denormal(max);
582 if ( fabsf(makeup_target - makeup_gain) < 1e-6 ) {
583 makeup_gain = makeup_target;
585 makeup_gain += tau * (makeup_target - makeup_gain) + 1e-12;
588 *(acomp->outlevel) = (max < 0.0056f) ? -70.f : to_dB(max);
589 *(acomp->inlevel) = in_peak_db;
590 acomp->makeup_gain = makeup_gain;
593 acomp->v_gainr = max_gainr;
595 if (in_peak_db > acomp->v_peakdb) {
596 acomp->v_peakdb = in_peak_db;
597 acomp->peakdb_samples = 0;
599 acomp->peakdb_samples += n_samples;
600 if ((float)acomp->peakdb_samples/acomp->srate > RESET_PEAK_AFTER_SECONDS) {
601 acomp->v_peakdb = in_peak_db;
602 acomp->peakdb_samples = 0;
603 acomp->need_expose = true;
607 const float v_lvl_in = in_peak_db;
608 const float v_lvl_out = *acomp->outlevel;
612 const float knee_lim_gr = (1.f - 1.f/ratio) * width/2.f;
614 if (acomp->v_gainr > knee_lim_gr) {
615 state_x = acomp->v_gainr / (1.f - 1.f/ratio) + thresdb;
617 state_x = sqrt ( (2.f*width*acomp->v_gainr) / (1.f-1.f/ratio) ) + thresdb - width/2.f;
620 if (fabsf (acomp->v_lvl_out - v_lvl_out) >= .1f ||
621 fabsf (acomp->v_lvl_in - v_lvl_in) >= .1f ||
622 fabsf (acomp->v_state_x - state_x) >= .1f ) {
623 // >= 0.1dB difference
624 acomp->need_expose = true;
625 acomp->v_lvl_in = v_lvl_in;
626 acomp->v_lvl_out = v_lvl_out;
627 acomp->v_state_x = state_x;
629 if (acomp->need_expose && acomp->queue_draw) {
630 acomp->need_expose = false;
631 acomp->queue_draw->queue_draw (acomp->queue_draw->handle);
637 deactivate(LV2_Handle instance)
643 cleanup(LV2_Handle instance)
646 AComp* acomp = (AComp*)instance;
647 if (acomp->display) {
648 cairo_surface_destroy (acomp->display);
657 #define MIN(A,B) ((A) < (B)) ? (A) : (B)
662 comp_curve (const AComp* self, float xg) {
663 const float knee = self->v_knee;
664 const float ratio = self->v_ratio;
665 const float thresdb = self->v_thresdb;
666 const float makeup = self->v_makeup;
668 const float width = 6.f * knee + 0.01f;
671 if (2.f * (xg - thresdb) < -width) {
673 } else if (2.f * (xg - thresdb) > width) {
674 yg = thresdb + (xg - thresdb) / ratio;
676 yg = xg + (1.f / ratio - 1.f ) * (xg - thresdb + width / 2.f) * (xg - thresdb + width / 2.f) / (2.f * width);
685 render_inline_full (cairo_t* cr, const AComp* self)
687 const float w = self->w;
688 const float h = self->h;
690 const float makeup_thres = self->v_thresdb + self->v_makeup;
693 cairo_rectangle (cr, 0, 0, w, h);
694 cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
697 cairo_set_line_width(cr, 1.0);
699 // draw grid 10dB steps
700 const double dash1[] = {1, 2};
701 const double dash2[] = {1, 3};
703 cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
704 cairo_set_dash(cr, dash2, 2, 2);
705 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
707 for (uint32_t d = 1; d < 7; ++d) {
708 const float x = -.5 + floorf (w * (d * 10.f / 70.f));
709 const float y = -.5 + floorf (h * (d * 10.f / 70.f));
711 cairo_move_to (cr, x, 0);
712 cairo_line_to (cr, x, h);
715 cairo_move_to (cr, 0, y);
716 cairo_line_to (cr, w, y);
719 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 1.0);
720 cairo_set_dash(cr, dash1, 2, 2);
721 if (self->v_thresdb < 0) {
722 const float y = -.5 + floorf (h * ((makeup_thres - 10.f) / -70.f));
723 cairo_move_to (cr, 0, y);
724 cairo_line_to (cr, w, y);
728 cairo_move_to (cr, 0, h);
729 cairo_line_to (cr, w, 0);
734 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
735 const float x = -.5 + floorf (w * (60.f / 70.f));
736 const float y = -.5 + floorf (h * (10.f / 70.f));
737 cairo_move_to (cr, x, 0);
738 cairo_line_to (cr, x, h);
740 cairo_move_to (cr, 0, y);
741 cairo_line_to (cr, w, y);
746 const float x = -.5 + floorf (w * (62.5f / 70.f));
747 const float y = -.5 + floorf (h * (10.0f / 70.f));
748 const float wd = floorf (w * (5.f / 70.f));
749 const float ht = floorf (h * (55.f / 70.f));
750 cairo_rectangle (cr, x, y, wd, ht);
753 const float h_gr = fminf (ht, floorf (h * self->v_gainr / 70.f));
754 cairo_set_source_rgba (cr, 0.95, 0.0, 0.0, 1.0);
755 cairo_rectangle (cr, x, y, wd, h_gr);
757 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
758 cairo_rectangle (cr, x, y, wd, ht);
759 cairo_set_source_rgba (cr, 0.75, 0.75, 0.75, 1.0);
764 cairo_set_source_rgba (cr, .8, .8, .8, 1.0);
766 const float state_x = w * (1.f - (10.f-self->v_state_x)/70.f);
767 const float state_y = h * (comp_curve (self, self->v_state_x) - 10.f) / -70.f;
769 cairo_arc (cr, state_x, state_y, 3.f, 0.f, 2.f*M_PI);
773 cairo_set_source_rgba (cr, .8, .8, .8, 1.0);
774 cairo_move_to (cr, 0, h);
776 for (uint32_t x = 0; x < w; ++x) {
778 const float x_db = 70.f * (-1.f + x / (float)w) + 10.f;
779 const float y_db = comp_curve (self, x_db) - 10.f;
780 const float y = h * (y_db / -70.f);
781 cairo_line_to (cr, x, y);
783 cairo_stroke_preserve (cr);
785 cairo_line_to (cr, w, h);
786 cairo_close_path (cr);
789 // draw signal level & reduction/gradient
790 const float top = comp_curve (self, 0) - 10.f;
791 cairo_pattern_t* pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, h);
792 if (top > makeup_thres - 10.f) {
793 cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.8, 0.1, 0.1, 0.5);
794 cairo_pattern_add_color_stop_rgba (pat, top / -70.f, 0.8, 0.1, 0.1, 0.5);
796 if (self->v_knee > 0) {
797 cairo_pattern_add_color_stop_rgba (pat, ((makeup_thres -10.f) / -70.f), 0.7, 0.7, 0.2, 0.5);
798 cairo_pattern_add_color_stop_rgba (pat, ((makeup_thres - self->v_knee - 10.f) / -70.f), 0.5, 0.5, 0.5, 0.5);
800 cairo_pattern_add_color_stop_rgba (pat, ((makeup_thres - 10.f)/ -70.f), 0.7, 0.7, 0.2, 0.5);
801 cairo_pattern_add_color_stop_rgba (pat, ((makeup_thres - 10.01f) / -70.f), 0.5, 0.5, 0.5, 0.5);
803 cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.5, 0.5, 0.5, 0.5);
805 // maybe cut off at x-position?
806 const float x = w * (self->v_lvl_in + 60) / 70.f;
807 const float y = x + h*self->v_makeup;
808 cairo_rectangle (cr, 0, h - y, x, y);
809 if (self->v_ratio > 1.0) {
810 cairo_set_source (cr, pat);
812 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
816 cairo_pattern_destroy (pat); // TODO cache pattern
820 render_inline_only_bars (cairo_t* cr, const AComp* self)
822 const float w = self->w;
823 const float h = self->h;
825 cairo_rectangle (cr, 0, 0, w, h);
826 cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
832 const float ht = 0.25f * h;
834 const float x1 = w*0.05;
835 const float wd = w - 2.0f*x1;
837 const float y1 = 0.17*h;
838 const float y2 = h - y1 - ht;
840 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
842 cairo_rectangle (cr, x1, y1, wd, ht);
845 cairo_rectangle (cr, x1, y2, wd, ht);
848 cairo_set_source_rgba (cr, 0.75, 0.0, 0.0, 1.0);
849 const float w_gr = (self->v_gainr > 60.f) ? wd : wd * self->v_gainr * (1.f/60.f);
850 cairo_rectangle (cr, x1+wd-w_gr, y2, w_gr, ht);
853 if (self->v_lvl_in > -60.f) {
854 if (self->v_lvl_out > 6.f) {
855 cairo_set_source_rgba (cr, 0.75, 0.0, 0.0, 1.0);
856 } else if (self->v_lvl_out > 0.f) {
857 cairo_set_source_rgba (cr, 0.66, 0.66, 0.0, 1.0);
859 cairo_set_source_rgba (cr, 0.0, 0.66, 0.0, 1.0);
861 const float w_g = (self->v_lvl_in > 10.f) ? wd : wd * (60.f+self->v_lvl_in) / 70.f;
862 cairo_rectangle (cr, x1, y1, w_g, ht);
866 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
868 const float tck = 0.33*ht;
870 cairo_set_line_width (cr, .5);
872 for (uint32_t d = 1; d < 7; ++d) {
873 const float x = x1 + (d * wd * (10.f / 70.f));
875 cairo_move_to (cr, x, y1);
876 cairo_line_to (cr, x, y1+tck);
878 cairo_move_to (cr, x, y1+ht);
879 cairo_line_to (cr, x, y1+ht-tck);
881 cairo_move_to (cr, x, y2);
882 cairo_line_to (cr, x, y2+tck);
884 cairo_move_to (cr, x, y2+ht);
885 cairo_line_to (cr, x, y2+ht-tck);
890 const float x_0dB = x1 + wd*(60.f/70.f);
892 cairo_move_to (cr, x_0dB, y1);
893 cairo_line_to (cr, x_0dB, y1+ht);
895 cairo_rectangle (cr, x1, y1, wd, ht);
896 cairo_rectangle (cr, x1, y2, wd, ht);
899 cairo_set_line_width (cr, 2.0);
901 // visualize threshold
902 const float tr = x1 + wd * (60.f+self->v_thresdb) / 70.f;
903 cairo_set_source_rgba (cr, 0.95, 0.95, 0.0, 1.0);
904 cairo_move_to (cr, tr, y1);
905 cairo_line_to (cr, tr, y1+ht);
909 const float reduced_0dB = self->v_thresdb * (1.f - 1.f/self->v_ratio);
910 const float rt = x1 + wd * (60.f+reduced_0dB) / 70.f;
911 cairo_set_source_rgba (cr, 0.95, 0.0, 0.0, 1.0);
912 cairo_move_to (cr, rt, y1);
913 cairo_line_to (cr, rt, y1+ht);
917 if (self->v_peakdb > -60.f) {
918 cairo_set_source_rgba (cr, 0.0, 1.0, 0.0, 1.0);
919 const float pk = (self->v_peakdb > 10.f) ? x1+wd : wd * (60.f+self->v_peakdb) / 70.f;
920 cairo_move_to (cr, pk, y1);
921 cairo_line_to (cr, pk, y1+ht);
926 static LV2_Inline_Display_Image_Surface *
927 render_inline (LV2_Handle instance, uint32_t w, uint32_t max_h)
929 AComp* self = (AComp*)instance;
931 uint32_t h = MIN (w, max_h);
932 if (w < 200 && !self->v_full_inline_display) {
936 if (!self->display || self->w != w || self->h != h) {
937 if (self->display) cairo_surface_destroy(self->display);
938 self->display = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
943 cairo_t* cr = cairo_create (self->display);
945 if (w >= 200 || self->v_full_inline_display) {
946 render_inline_full (cr, self);
948 render_inline_only_bars (cr, self);
953 cairo_surface_flush (self->display);
954 self->surf.width = cairo_image_surface_get_width (self->display);
955 self->surf.height = cairo_image_surface_get_height (self->display);
956 self->surf.stride = cairo_image_surface_get_stride (self->display);
957 self->surf.data = cairo_image_surface_get_data (self->display);
964 extension_data(const char* uri)
967 static const LV2_Inline_Display_Interface display = { render_inline };
968 if (!strcmp(uri, LV2_INLINEDISPLAY__interface)) {
975 static const LV2_Descriptor descriptor_mono = {
986 static const LV2_Descriptor descriptor_stereo = {
998 const LV2_Descriptor*
999 lv2_descriptor(uint32_t index)
1003 return &descriptor_mono;
1005 return &descriptor_stereo;