Put duplicate code of a-comp and a-expander into one file ...
... for better maintainability consolidated duplicate code: * drawing the dB-grid of a-comp's and a-expander's full display * drawing the gain reduction bar of a-comp's and a-expander's full display * the entire only-bars display
This commit is contained in:
parent
0c64eacef5
commit
18511f851e
@ -521,6 +521,9 @@ comp_curve (const AComp* self, float xg) {
|
||||
return yg;
|
||||
}
|
||||
|
||||
|
||||
#include "dynamic_display.c"
|
||||
|
||||
static void
|
||||
render_inline_full (cairo_t* cr, const AComp* self)
|
||||
{
|
||||
@ -529,76 +532,16 @@ render_inline_full (cairo_t* cr, const AComp* self)
|
||||
|
||||
const float makeup_thres = self->v_thresdb + self->v_makeup;
|
||||
|
||||
// clear background
|
||||
cairo_rectangle (cr, 0, 0, w, h);
|
||||
cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
|
||||
cairo_fill (cr);
|
||||
draw_grid (cr, w,h);
|
||||
|
||||
cairo_set_line_width(cr, 1.0);
|
||||
|
||||
// draw grid 10dB steps
|
||||
const double dash1[] = {1, 2};
|
||||
const double dash2[] = {1, 3};
|
||||
cairo_save (cr);
|
||||
cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
|
||||
cairo_set_dash(cr, dash2, 2, 2);
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
|
||||
|
||||
for (uint32_t d = 1; d < 7; ++d) {
|
||||
const float x = -.5 + floorf (w * (d * 10.f / 70.f));
|
||||
const float y = -.5 + floorf (h * (d * 10.f / 70.f));
|
||||
|
||||
cairo_move_to (cr, x, 0);
|
||||
cairo_line_to (cr, x, h);
|
||||
cairo_stroke (cr);
|
||||
|
||||
cairo_move_to (cr, 0, y);
|
||||
cairo_line_to (cr, w, y);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 1.0);
|
||||
cairo_set_dash(cr, dash1, 2, 2);
|
||||
if (self->v_thresdb < 0) {
|
||||
const float y = -.5 + floorf (h * ((makeup_thres - 10.f) / -70.f));
|
||||
cairo_move_to (cr, 0, y);
|
||||
cairo_line_to (cr, w, y);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
// diagonal unity
|
||||
cairo_move_to (cr, 0, h);
|
||||
cairo_line_to (cr, w, 0);
|
||||
cairo_stroke (cr);
|
||||
cairo_restore (cr);
|
||||
|
||||
{ // 0, 0
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
|
||||
const float x = -.5 + floorf (w * (60.f / 70.f));
|
||||
const float y = -.5 + floorf (h * (10.f / 70.f));
|
||||
cairo_move_to (cr, x, 0);
|
||||
cairo_line_to (cr, x, h);
|
||||
cairo_stroke (cr);
|
||||
cairo_move_to (cr, 0, y);
|
||||
cairo_line_to (cr, w, y);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
{ // GR
|
||||
const float x = -.5 + floorf (w * (62.5f / 70.f));
|
||||
const float y = -.5 + floorf (h * (10.0f / 70.f));
|
||||
const float wd = floorf (w * (5.f / 70.f));
|
||||
const float ht = floorf (h * (55.f / 70.f));
|
||||
cairo_rectangle (cr, x, y, wd, ht);
|
||||
cairo_fill (cr);
|
||||
|
||||
const float h_gr = fminf (ht, floorf (h * self->v_gainr / 70.f));
|
||||
cairo_set_source_rgba (cr, 0.95, 0.0, 0.0, 1.0);
|
||||
cairo_rectangle (cr, x, y, wd, h_gr);
|
||||
cairo_fill (cr);
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
|
||||
cairo_rectangle (cr, x, y, wd, ht);
|
||||
cairo_set_source_rgba (cr, 0.75, 0.75, 0.75, 1.0);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
draw_GR_bar (cr, w,h, self->v_gainr);
|
||||
|
||||
// draw state
|
||||
cairo_set_source_rgba (cr, .8, .8, .8, 1.0);
|
||||
@ -659,108 +602,10 @@ render_inline_full (cairo_t* cr, const AComp* self)
|
||||
static void
|
||||
render_inline_only_bars (cairo_t* cr, const AComp* self)
|
||||
{
|
||||
const float w = self->w;
|
||||
const float h = self->h;
|
||||
|
||||
cairo_rectangle (cr, 0, 0, w, h);
|
||||
cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
|
||||
cairo_fill (cr);
|
||||
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
const float ht = 0.25f * h;
|
||||
|
||||
const float x1 = w*0.05;
|
||||
const float wd = w - 2.0f*x1;
|
||||
|
||||
const float y1 = 0.17*h;
|
||||
const float y2 = h - y1 - ht;
|
||||
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
|
||||
|
||||
cairo_rectangle (cr, x1, y1, wd, ht);
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_rectangle (cr, x1, y2, wd, ht);
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_set_source_rgba (cr, 0.75, 0.0, 0.0, 1.0);
|
||||
const float w_gr = (self->v_gainr > 60.f) ? wd : wd * self->v_gainr * (1.f/60.f);
|
||||
cairo_rectangle (cr, x1+wd-w_gr, y2, w_gr, ht);
|
||||
cairo_fill (cr);
|
||||
|
||||
if (self->v_lvl_in > -60.f) {
|
||||
if (self->v_lvl_out > 6.f) {
|
||||
cairo_set_source_rgba (cr, 0.75, 0.0, 0.0, 1.0);
|
||||
} else if (self->v_lvl_out > 0.f) {
|
||||
cairo_set_source_rgba (cr, 0.66, 0.66, 0.0, 1.0);
|
||||
} else {
|
||||
cairo_set_source_rgba (cr, 0.0, 0.66, 0.0, 1.0);
|
||||
}
|
||||
const float w_g = (self->v_lvl_in > 10.f) ? wd : wd * (60.f+self->v_lvl_in) / 70.f;
|
||||
cairo_rectangle (cr, x1, y1, w_g, ht);
|
||||
cairo_fill (cr);
|
||||
}
|
||||
|
||||
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
const float tck = 0.33*ht;
|
||||
|
||||
cairo_set_line_width (cr, .5);
|
||||
|
||||
for (uint32_t d = 1; d < 7; ++d) {
|
||||
const float x = x1 + (d * wd * (10.f / 70.f));
|
||||
|
||||
cairo_move_to (cr, x, y1);
|
||||
cairo_line_to (cr, x, y1+tck);
|
||||
|
||||
cairo_move_to (cr, x, y1+ht);
|
||||
cairo_line_to (cr, x, y1+ht-tck);
|
||||
|
||||
cairo_move_to (cr, x, y2);
|
||||
cairo_line_to (cr, x, y2+tck);
|
||||
|
||||
cairo_move_to (cr, x, y2+ht);
|
||||
cairo_line_to (cr, x, y2+ht-tck);
|
||||
}
|
||||
|
||||
cairo_stroke (cr);
|
||||
|
||||
const float x_0dB = x1 + wd*(60.f/70.f);
|
||||
|
||||
cairo_move_to (cr, x_0dB, y1);
|
||||
cairo_line_to (cr, x_0dB, y1+ht);
|
||||
|
||||
cairo_rectangle (cr, x1, y1, wd, ht);
|
||||
cairo_rectangle (cr, x1, y2, wd, ht);
|
||||
cairo_stroke (cr);
|
||||
|
||||
cairo_set_line_width (cr, 2.0);
|
||||
|
||||
// visualize threshold
|
||||
const float tr = x1 + wd * (60.f+self->v_thresdb) / 70.f;
|
||||
cairo_set_source_rgba (cr, 0.95, 0.95, 0.0, 1.0);
|
||||
cairo_move_to (cr, tr, y1);
|
||||
cairo_line_to (cr, tr, y1+ht);
|
||||
cairo_stroke (cr);
|
||||
|
||||
// visualize ratio
|
||||
const float reduced_0dB = self->v_thresdb * (1.f - 1.f/self->v_ratio);
|
||||
const float rt = x1 + wd * (60.f+reduced_0dB) / 70.f;
|
||||
cairo_set_source_rgba (cr, 0.95, 0.0, 0.0, 1.0);
|
||||
cairo_move_to (cr, rt, y1);
|
||||
cairo_line_to (cr, rt, y1+ht);
|
||||
cairo_stroke (cr);
|
||||
|
||||
// visualize in peak
|
||||
if (self->v_peakdb > -60.f) {
|
||||
cairo_set_source_rgba (cr, 0.0, 1.0, 0.0, 1.0);
|
||||
const float pk = (self->v_peakdb > 10.f) ? x1+wd : wd * (60.f+self->v_peakdb) / 70.f;
|
||||
cairo_move_to (cr, pk, y1);
|
||||
cairo_line_to (cr, pk, y1+ht);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
draw_inline_bars (cr, self->w, self->h,
|
||||
self->v_thresdb, self->v_ratio,
|
||||
self->v_peakdb, self->v_gainr,
|
||||
self->v_lvl_in, self->v_lvl_out);
|
||||
}
|
||||
|
||||
static LV2_Inline_Display_Image_Surface *
|
||||
|
@ -18,7 +18,7 @@ def configure(conf):
|
||||
if Options.options.lv2:
|
||||
autowaf.check_pkg(conf, 'lv2', atleast_version='1.0.0',
|
||||
uselib_store='LV2_1_0_0')
|
||||
autowaf.check_pkg(conf, 'cairo', uselib_store='CAIRO', atleast_version='1.12.0')
|
||||
autowaf.check_pkg(conf, 'cairo', uselib_store='CAIRO', atleast_version='1.12.0')
|
||||
|
||||
def build(bld):
|
||||
bundle = 'a-comp.lv2'
|
||||
@ -40,7 +40,7 @@ def build(bld):
|
||||
source = 'a-comp.c',
|
||||
name = 'a-comp',
|
||||
cflags = [ '-fPIC', bld.env['compiler_flags_dict']['c99'] ],
|
||||
includes = [ '../../ardour' ],
|
||||
includes = [ '../../ardour', '../shared' ],
|
||||
target = '../../LV2/%s/a-comp' % bundle,
|
||||
install_path = '${LV2DIR}/%s' % bundle,
|
||||
uselib = 'CAIRO',
|
||||
|
@ -515,6 +515,7 @@ exp_curve (const AExp* self, float xg) {
|
||||
return yg;
|
||||
}
|
||||
|
||||
#include "dynamic_display.c"
|
||||
|
||||
static void
|
||||
render_inline_full (cairo_t* cr, const AExp* self)
|
||||
@ -524,76 +525,26 @@ render_inline_full (cairo_t* cr, const AExp* self)
|
||||
|
||||
const float makeup_thres = self->v_thresdb + self->v_makeup;
|
||||
|
||||
// clear background
|
||||
cairo_rectangle (cr, 0, 0, w, h);
|
||||
cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
|
||||
cairo_fill (cr);
|
||||
draw_grid (cr, w,h);
|
||||
|
||||
cairo_set_line_width(cr, 1.0);
|
||||
|
||||
// draw grid 10dB steps
|
||||
const double dash1[] = {1, 2};
|
||||
const double dash2[] = {1, 3};
|
||||
cairo_save (cr);
|
||||
cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
|
||||
cairo_set_dash(cr, dash2, 2, 2);
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
|
||||
|
||||
for (uint32_t d = 1; d < 7; ++d) {
|
||||
const float x = -.5 + floorf (w * (d * 10.f / 70.f));
|
||||
const float y = -.5 + floorf (h * (d * 10.f / 70.f));
|
||||
|
||||
cairo_move_to (cr, x, 0);
|
||||
cairo_line_to (cr, x, h);
|
||||
cairo_stroke (cr);
|
||||
|
||||
cairo_move_to (cr, 0, y);
|
||||
cairo_line_to (cr, w, y);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 1.0);
|
||||
cairo_set_dash(cr, dash1, 2, 2);
|
||||
if (self->v_thresdb < 0) {
|
||||
const float y = -.5 + floorf (h * ((makeup_thres - 10.f) / -70.f));
|
||||
cairo_move_to (cr, 0, y);
|
||||
cairo_line_to (cr, w, y);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
// diagonal unity
|
||||
cairo_move_to (cr, 0, h);
|
||||
cairo_line_to (cr, w, 0);
|
||||
cairo_stroke (cr);
|
||||
cairo_restore (cr);
|
||||
|
||||
{ // 0, 0
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
|
||||
const float x = -.5 + floorf (w * (60.f / 70.f));
|
||||
const float y = -.5 + floorf (h * (10.f / 70.f));
|
||||
cairo_move_to (cr, x, 0);
|
||||
cairo_line_to (cr, x, h);
|
||||
cairo_stroke (cr);
|
||||
cairo_move_to (cr, 0, y);
|
||||
cairo_line_to (cr, w, y);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
draw_GR_bar (cr, w,h, self->v_gainr);
|
||||
|
||||
{ // GR
|
||||
const float x = -.5 + floorf (w * (62.5f / 70.f));
|
||||
const float y = -.5 + floorf (h * (10.0f / 70.f));
|
||||
const float wd = floorf (w * (5.f / 70.f));
|
||||
const float ht = floorf (h * (55.f / 70.f));
|
||||
cairo_rectangle (cr, x, y, wd, ht);
|
||||
cairo_fill (cr);
|
||||
// draw peak input
|
||||
cairo_set_source_rgba (cr, .8, .8, .8, 1.0);
|
||||
cairo_set_line_width(cr, 1.0);
|
||||
|
||||
const float h_gr = fminf (ht, floorf (h * self->v_gainr / 70.f));
|
||||
cairo_set_source_rgba (cr, 0.95, 0.0, 0.0, 1.0);
|
||||
cairo_rectangle (cr, x, y, wd, h_gr);
|
||||
cairo_fill (cr);
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
|
||||
cairo_rectangle (cr, x, y, wd, ht);
|
||||
cairo_set_source_rgba (cr, 0.75, 0.75, 0.75, 1.0);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
const float peak_x = w * (1.f - (10.f-self->v_peakdb)/70.f);
|
||||
const float peak_y = fminf (h * (exp_curve (self, self->v_peakdb) - 10.f) / -70.f, h);
|
||||
|
||||
cairo_arc (cr, peak_x, peak_y, 3.f, 0.f, 2.f*M_PI);
|
||||
cairo_fill (cr);
|
||||
|
||||
// draw curve
|
||||
cairo_set_source_rgba (cr, .8, .8, .8, 1.0);
|
||||
@ -639,125 +590,16 @@ render_inline_full (cairo_t* cr, const AExp* self)
|
||||
}
|
||||
cairo_fill (cr);
|
||||
|
||||
// draw peak input
|
||||
cairo_set_source_rgba (cr, .0f, 1.f, 0.f, 1.0);
|
||||
cairo_set_line_width(cr, 1.0);
|
||||
|
||||
const float peak_x = w * (1.f - (10.f-self->v_peakdb)/70.f);
|
||||
const float peak_y = h * (exp_curve (self, self->v_peakdb) - 10.f) / -70.f;
|
||||
|
||||
cairo_move_to(cr, peak_x, h);
|
||||
cairo_line_to(cr, peak_x, peak_y);
|
||||
cairo_stroke (cr);
|
||||
|
||||
cairo_pattern_destroy (pat); // TODO cache pattern
|
||||
}
|
||||
|
||||
static void
|
||||
render_inline_only_bars (cairo_t* cr, const AExp* self)
|
||||
{
|
||||
const float w = self->w;
|
||||
const float h = self->h;
|
||||
|
||||
cairo_rectangle (cr, 0, 0, w, h);
|
||||
cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
|
||||
cairo_fill (cr);
|
||||
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
const float ht = 0.25f * h;
|
||||
|
||||
const float x1 = w*0.05;
|
||||
const float wd = w - 2.0f*x1;
|
||||
|
||||
const float y1 = 0.17*h;
|
||||
const float y2 = h - y1 - ht;
|
||||
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
|
||||
|
||||
cairo_rectangle (cr, x1, y1, wd, ht);
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_rectangle (cr, x1, y2, wd, ht);
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_set_source_rgba (cr, 0.75, 0.0, 0.0, 1.0);
|
||||
const float w_gr = (self->v_gainr > 60.f) ? wd : wd * self->v_gainr * (1.f/60.f);
|
||||
cairo_rectangle (cr, x1+wd-w_gr, y2, w_gr, ht);
|
||||
cairo_fill (cr);
|
||||
|
||||
if (self->v_lvl_in > -60.f) {
|
||||
if (self->v_lvl_out > 10.f) {
|
||||
cairo_set_source_rgba (cr, 0.75, 0.0, 0.0, 1.0);
|
||||
} else if (self->v_lvl_out > 0.f) {
|
||||
cairo_set_source_rgba (cr, 0.66, 0.66, 0.0, 1.0);
|
||||
} else {
|
||||
cairo_set_source_rgba (cr, 0.0, 0.66, 0.0, 1.0);
|
||||
}
|
||||
const float w_g = (self->v_lvl_in > 10.f) ? wd : wd * (60.f+self->v_lvl_in) / 70.f;
|
||||
cairo_rectangle (cr, x1, y1, w_g, ht);
|
||||
cairo_fill (cr);
|
||||
}
|
||||
|
||||
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
const float tck = 0.33*ht;
|
||||
|
||||
cairo_set_line_width (cr, .5);
|
||||
|
||||
for (uint32_t d = 1; d < 7; ++d) {
|
||||
const float x = x1 + (d * wd * (10.f / 70.f));
|
||||
|
||||
cairo_move_to (cr, x, y1);
|
||||
cairo_line_to (cr, x, y1+tck);
|
||||
|
||||
cairo_move_to (cr, x, y1+ht);
|
||||
cairo_line_to (cr, x, y1+ht-tck);
|
||||
|
||||
cairo_move_to (cr, x, y2);
|
||||
cairo_line_to (cr, x, y2+tck);
|
||||
|
||||
cairo_move_to (cr, x, y2+ht);
|
||||
cairo_line_to (cr, x, y2+ht-tck);
|
||||
}
|
||||
|
||||
cairo_stroke (cr);
|
||||
|
||||
const float x_0dB = x1 + wd*(60.f/70.f);
|
||||
|
||||
cairo_move_to (cr, x_0dB, y1);
|
||||
cairo_line_to (cr, x_0dB, y1+ht);
|
||||
|
||||
cairo_rectangle (cr, x1, y1, wd, ht);
|
||||
cairo_rectangle (cr, x1, y2, wd, ht);
|
||||
cairo_stroke (cr);
|
||||
|
||||
cairo_set_line_width (cr, 2.0);
|
||||
|
||||
// visualize threshold
|
||||
const float tr = x1 + wd * (60.f+self->v_thresdb) / 70.f;
|
||||
cairo_set_source_rgba (cr, 0.95, 0.95, 0.0, 1.0);
|
||||
cairo_move_to (cr, tr, y1);
|
||||
cairo_line_to (cr, tr, y1+ht);
|
||||
cairo_stroke (cr);
|
||||
|
||||
// visualize ratio
|
||||
const float reduced_0dB = self->v_thresdb * (1.f - 1.f/self->v_ratio);
|
||||
const float rt = x1 + wd * (60.f+reduced_0dB) / 70.f;
|
||||
cairo_set_source_rgba (cr, 0.95, 0.0, 0.0, 1.0);
|
||||
cairo_move_to (cr, rt, y1);
|
||||
cairo_line_to (cr, rt, y1+ht);
|
||||
cairo_stroke (cr);
|
||||
|
||||
// visualize in peak
|
||||
if (self->v_peakdb > -60.f) {
|
||||
cairo_set_source_rgba (cr, 0.0, 1.0, 0.0, 1.0);
|
||||
const float pk = (self->v_peakdb > 10.f) ? x1+wd : wd * (60.f+self->v_peakdb) / 70.f;
|
||||
cairo_move_to (cr, pk, y1);
|
||||
cairo_line_to (cr, pk, y1+ht);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
draw_inline_bars (cr, self->w, self->h,
|
||||
self->v_thresdb, self->v_ratio,
|
||||
self->v_peakdb, self->v_gainr,
|
||||
self->v_lvl_in, self->v_lvl_out);
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,7 +40,7 @@ def build(bld):
|
||||
source = 'a-exp.c',
|
||||
name = 'a-exp',
|
||||
cflags = [ '-fPIC', bld.env['compiler_flags_dict']['c99'] ],
|
||||
includes = [ '../../ardour' ],
|
||||
includes = [ '../../ardour', '../shared' ],
|
||||
target = '../../LV2/%s/a-exp' % bundle,
|
||||
install_path = '${LV2DIR}/%s' % bundle,
|
||||
uselib = 'CAIRO',
|
||||
|
205
libs/plugins/shared/dynamic_display.c
Normal file
205
libs/plugins/shared/dynamic_display.c
Normal file
@ -0,0 +1,205 @@
|
||||
/* dynamic_screen.c
|
||||
* Copyright (C) 2018 Johannes Mueller <github@johannes-mueller.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
|
||||
/* Shared code for a-comp.c and a-exp.c
|
||||
*
|
||||
* This file contains some code that draws the basic layout of for the inline
|
||||
* rendering of a-comp.c and a-exp.c. It is put into a shared file for better
|
||||
* maintainability. It is not meant to be compiled as a individual compilation
|
||||
* unit but to be included like
|
||||
*
|
||||
* #include "dynamic_screen.c"
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
static inline void
|
||||
draw_grid (cairo_t* cr, const float w, const float h)
|
||||
{
|
||||
// clear background
|
||||
cairo_rectangle (cr, 0, 0, w, h);
|
||||
cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_set_line_width(cr, 1.0);
|
||||
|
||||
// draw grid 10dB steps
|
||||
const double dash1[] = {1, 2};
|
||||
const double dash2[] = {1, 3};
|
||||
cairo_save (cr);
|
||||
cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
|
||||
cairo_set_dash(cr, dash2, 2, 2);
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
|
||||
|
||||
for (uint32_t d = 1; d < 7; ++d) {
|
||||
const float x = -.5 + floorf (w * (d * 10.f / 70.f));
|
||||
const float y = -.5 + floorf (h * (d * 10.f / 70.f));
|
||||
|
||||
cairo_move_to (cr, x, 0);
|
||||
cairo_line_to (cr, x, h);
|
||||
cairo_stroke (cr);
|
||||
|
||||
cairo_move_to (cr, 0, y);
|
||||
cairo_line_to (cr, w, y);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 1.0);
|
||||
cairo_set_dash(cr, dash1, 2, 2);
|
||||
|
||||
// diagonal unity
|
||||
cairo_move_to (cr, 0, h);
|
||||
cairo_line_to (cr, w, 0);
|
||||
cairo_stroke (cr);
|
||||
cairo_restore (cr);
|
||||
|
||||
{ // 0, 0
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
|
||||
const float x = -.5 + floorf (w * (60.f / 70.f));
|
||||
const float y = -.5 + floorf (h * (10.f / 70.f));
|
||||
cairo_move_to (cr, x, 0);
|
||||
cairo_line_to (cr, x, h);
|
||||
cairo_stroke (cr);
|
||||
cairo_move_to (cr, 0, y);
|
||||
cairo_line_to (cr, w, y);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
draw_GR_bar (cairo_t* cr, const float w, const float h, const float gainr)
|
||||
{
|
||||
const float x = -.5 + floorf (w * (62.5f / 70.f));
|
||||
const float y = -.5 + floorf (h * (10.0f / 70.f));
|
||||
const float wd = floorf (w * (5.f / 70.f));
|
||||
const float ht = floorf (h * (55.f / 70.f));
|
||||
cairo_rectangle (cr, x, y, wd, ht);
|
||||
cairo_fill (cr);
|
||||
|
||||
const float h_gr = fminf (ht, floorf (h * gainr / 70.f));
|
||||
cairo_set_source_rgba (cr, 0.95, 0.0, 0.0, 1.0);
|
||||
cairo_rectangle (cr, x, y, wd, h_gr);
|
||||
cairo_fill (cr);
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
|
||||
cairo_rectangle (cr, x, y, wd, ht);
|
||||
cairo_set_source_rgba (cr, 0.75, 0.75, 0.75, 1.0);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
static inline void
|
||||
draw_inline_bars (cairo_t* cr, const float w, const float h,
|
||||
const float thresdb, const float ratio,
|
||||
const float peakdb, const float gainr,
|
||||
const float level_in, const float level_out)
|
||||
{
|
||||
cairo_rectangle (cr, 0, 0, w, h);
|
||||
cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
|
||||
cairo_fill (cr);
|
||||
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
const float ht = 0.25f * h;
|
||||
|
||||
const float x1 = w*0.05;
|
||||
const float wd = w - 2.0f*x1;
|
||||
|
||||
const float y1 = 0.17*h;
|
||||
const float y2 = h - y1 - ht;
|
||||
|
||||
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
|
||||
|
||||
cairo_rectangle (cr, x1, y1, wd, ht);
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_rectangle (cr, x1, y2, wd, ht);
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_set_source_rgba (cr, 0.75, 0.0, 0.0, 1.0);
|
||||
const float w_gr = (gainr > 60.f) ? wd : wd * gainr * (1.f/60.f);
|
||||
cairo_rectangle (cr, x1+wd-w_gr, y2, w_gr, ht);
|
||||
cairo_fill (cr);
|
||||
|
||||
if (level_in > -60.f) {
|
||||
if (level_out > 6.f) {
|
||||
cairo_set_source_rgba (cr, 0.75, 0.0, 0.0, 1.0);
|
||||
} else if (level_out > 0.f) {
|
||||
cairo_set_source_rgba (cr, 0.66, 0.66, 0.0, 1.0);
|
||||
} else {
|
||||
cairo_set_source_rgba (cr, 0.0, 0.66, 0.0, 1.0);
|
||||
}
|
||||
const float w_g = (level_in > 10.f) ? wd : wd * (60.f+level_in) / 70.f;
|
||||
cairo_rectangle (cr, x1, y1, w_g, ht);
|
||||
cairo_fill (cr);
|
||||
}
|
||||
|
||||
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
const float tck = 0.33*ht;
|
||||
|
||||
cairo_set_line_width (cr, .5);
|
||||
|
||||
for (uint32_t d = 1; d < 7; ++d) {
|
||||
const float x = x1 + (d * wd * (10.f / 70.f));
|
||||
|
||||
cairo_move_to (cr, x, y1);
|
||||
cairo_line_to (cr, x, y1+tck);
|
||||
|
||||
cairo_move_to (cr, x, y1+ht);
|
||||
cairo_line_to (cr, x, y1+ht-tck);
|
||||
|
||||
cairo_move_to (cr, x, y2);
|
||||
cairo_line_to (cr, x, y2+tck);
|
||||
|
||||
cairo_move_to (cr, x, y2+ht);
|
||||
cairo_line_to (cr, x, y2+ht-tck);
|
||||
}
|
||||
|
||||
cairo_stroke (cr);
|
||||
|
||||
const float x_0dB = x1 + wd*(60.f/70.f);
|
||||
|
||||
cairo_move_to (cr, x_0dB, y1);
|
||||
cairo_line_to (cr, x_0dB, y1+ht);
|
||||
|
||||
cairo_rectangle (cr, x1, y1, wd, ht);
|
||||
cairo_rectangle (cr, x1, y2, wd, ht);
|
||||
cairo_stroke (cr);
|
||||
|
||||
cairo_set_line_width (cr, 2.0);
|
||||
|
||||
// visualize threshold
|
||||
const float tr = x1 + wd * (60.f+thresdb) / 70.f;
|
||||
cairo_set_source_rgba (cr, 0.95, 0.95, 0.0, 1.0);
|
||||
cairo_move_to (cr, tr, y1);
|
||||
cairo_line_to (cr, tr, y1+ht);
|
||||
cairo_stroke (cr);
|
||||
|
||||
// visualize ratio
|
||||
const float reduced_0dB = thresdb * (1.f - 1.f/ratio);
|
||||
const float rt = x1 + wd * (60.f+reduced_0dB) / 70.f;
|
||||
cairo_set_source_rgba (cr, 0.95, 0.0, 0.0, 1.0);
|
||||
cairo_move_to (cr, rt, y1);
|
||||
cairo_line_to (cr, rt, y1+ht);
|
||||
cairo_stroke (cr);
|
||||
|
||||
// visualize in peak
|
||||
if (peakdb > -60.f) {
|
||||
cairo_set_source_rgba (cr, 0.0, 1.0, 0.0, 1.0);
|
||||
const float pk = (peakdb > 10.f) ? x1+wd : wd * (60.f+peakdb) / 70.f;
|
||||
cairo_move_to (cr, pk, y1);
|
||||
cairo_line_to (cr, pk, y1+ht);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user