libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xmeter.c
Go to the documentation of this file.
1 /*
2  * 0BSD
3  *
4  * BSD Zero Clause License
5  *
6  * Copyright (c) 2019 Hermann Meyer
7  *
8  * Permission to use, copy, modify, and/or distribute this software for any
9  * purpose with or without fee is hereby granted.
10 
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  *
19  */
20 
21 
22 #include "xmeter.h"
23 #include "xmeter_private.h"
24 
25 
26 float power2db(Widget_t *w, float power) {
27  const float falloff = 27 * 60 * 0.0005;
28  const float fallsoft = 6 * 60 * 0.0005;
29  //power = 20.*log10(power);
30  if (power <= 20.*log10(0.00021)) { // -70db
31  power = 20.*log10(0.00000000001); //-137db
32  w->adj->start_value = min(0.0,w->adj->start_value - fallsoft);
33  }
34  // retrieve old meter value and consider falloff
35  if (power < w->adj->std_value) {
36  power = max(power, w->adj->std_value - falloff);
37  w->adj->start_value = min(0.0,w->adj->start_value - fallsoft);
38  }
39  if (power > w->adj->start_value) {
40  w->adj->start_value = power ;
41  }
42 
43  w->adj->std_value = power;
44  return power;
45 }
46 
47 Widget_t* add_vmeter(Widget_t *parent, const char * label, bool show_scale,
48  int x, int y, int width, int height) {
49 
50  Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
51  _create_vertical_meter_image(wid, width, height);
52  wid->label = label;
53  wid->adj_y = add_adjustment(wid,-70.0, -70.0, -70.0, 6.0,0.001, CL_METER);
54  wid->adj = wid->adj_y;
55  wid->flags &= ~USE_TRANSPARENCY;
56  wid->scale.gravity = ASPECT;
58  if (show_scale) {
59  Widget_t *wid2 = create_widget(parent->app, parent, x+width, y, width, height);
60  wid2->scale.gravity = ASPECT;
62  }
63  return wid;
64 }
65 
66 Widget_t* add_hmeter(Widget_t *parent, const char * label, bool show_scale,
67  int x, int y, int width, int height) {
68 
69  Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
70  _create_horizontal_meter_image(wid, width, height);
71  wid->label = label;
72  wid->adj_x = add_adjustment(wid,-70.0, -70.0, -70.0, 6.0,0.001, CL_METER);
73  wid->adj = wid->adj_x;
74  wid->flags &= ~USE_TRANSPARENCY;
75  wid->scale.gravity = ASPECT;
77  if (show_scale) {
78  Widget_t *wid2 = create_widget(parent->app, parent, x, y+height, width, height);
79  wid2->scale.gravity = ASPECT;
81  }
82  return wid;
83 }
Adjustment_t::std_value
float std_value
Definition: xadjustment.h:84
add_hmeter
Widget_t * add_hmeter(Widget_t *parent, const char *label, bool show_scale, int x, int y, int width, int height)
add_hmeter - add a vumeter to a Widget_t connect to func.value_changed_callback to implement your act...
Definition: xmeter.c:66
Resize_t::gravity
Gravity gravity
Definition: xwidget.h:192
xmeter_private.h
add_vmeter
Widget_t * add_vmeter(Widget_t *parent, const char *label, bool show_scale, int x, int y, int width, int height)
add_vmeter - add a vumeter to a Widget_t connect to func.value_changed_callback to implement your act...
Definition: xmeter.c:47
_draw_vmeter_scale
void _draw_vmeter_scale(void *w_, void *user_data)
_draw_meter_scale - draw a meter scale beside the meter widget
Definition: xmeter_private.c:25
min
#define min(x, y)
min - set a maximal value (x) as return value
Definition: xputty.h:78
_draw_h_meter
void _draw_h_meter(void *w_, void *user_data)
_draw_h_meter - internal draw the meter to the buffer
Definition: xmeter_private.c:270
create_widget
Widget_t * create_widget(Xputty *app, Widget_t *win, int x, int y, int width, int height)
*create_widget - create a widget A Widget_t could only be created as child of a other Widget_t To...
Definition: xwidget.c:268
Func_t::expose_callback
xevfunc expose_callback
Definition: xwidget.h:80
Widget_t::flags
long long flags
Definition: xwidget.h:324
Widget_t::adj
Adjustment_t * adj
Definition: xwidget.h:334
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
_create_vertical_meter_image
void _create_vertical_meter_image(Widget_t *w, int width, int height)
_create_vertical_meter_image - internal draw the meter image to the cairo image surface
Definition: xmeter_private.c:138
_create_horizontal_meter_image
void _create_horizontal_meter_image(Widget_t *w, int width, int height)
_create_horizontal_meter_image - internal draw the meter image to the cairo image surface
Definition: xmeter_private.c:194
Widget_t::app
Xputty * app
Definition: xwidget.h:300
USE_TRANSPARENCY
@ USE_TRANSPARENCY
Definition: xwidget.h:243
_draw_v_meter
void _draw_v_meter(void *w_, void *user_data)
_draw_v_meter - internal draw the meter to the buffer
Definition: xmeter_private.c:250
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
ASPECT
@ ASPECT
Definition: xwidget.h:167
_draw_hmeter_scale
void _draw_hmeter_scale(void *w_, void *user_data)
_draw_hmeter_scale - draw a hmeter scale beside the meter widget
Definition: xmeter_private.c:69
power2db
float power2db(Widget_t *w, float power)
power2db - power (db) input to db output consider falloff
Definition: xmeter.c:26
CL_METER
@ CL_METER
Definition: xadjustment.h:59
Widget_t::adj_y
Adjustment_t * adj_y
Definition: xwidget.h:332
Widget_t::func
Func_t func
Definition: xwidget.h:310
add_adjustment
Adjustment_t * add_adjustment(Widget_t *w, float std_value, float value, float min_value, float max_value, float step, CL_type type)
*add_adjustment - adding a adjustment to a Widget_t
Definition: xadjustment.c:25
Adjustment_t::start_value
float start_value
Definition: xadjustment.h:94
xmeter.h
max
#define max(x, y)
max - set a minimal value (x) as return value
Definition: xputty.h:86
Widget_t::label
const char * label
Definition: xwidget.h:326
Widget_t::adj_x
Adjustment_t * adj_x
Definition: xwidget.h:330