libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xtuner_private.h File Reference
#include "xtuner.h"
Include dependency graph for xtuner_private.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define XTUNER_PRIVATE_H_
 

Functions

void _draw_tuner (void *w_, void *user_data)
 _draw_tuner - draw the tuner on expose call More...
 

Macro Definition Documentation

◆ XTUNER_PRIVATE_H_

#define XTUNER_PRIVATE_H_

Definition at line 24 of file xtuner_private.h.

Function Documentation

◆ _draw_tuner()

void _draw_tuner ( void *  w_,
void *  user_data 
)

_draw_tuner - draw the tuner on expose call

Parameters
*w_- The Widget_t contain the tuner
*user_data- attached user_data
Returns
void

Definition at line 69 of file xtuner_private.c.

69  {
70  Widget_t *w = (Widget_t*)w_;
71  if (!w) return;
72  XTuner *xt = (XTuner *)w->parent_struct;
73  XWindowAttributes attrs;
74  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
75  if (attrs.map_state != IsViewable) return;
76  int width = attrs.width;
77  int height = attrs.height;
78  float x0 = width/2;
79  float y0 = height/2;
80 
82  cairo_paint (w->crb);
83 
84  cairo_set_source_rgb(w->crb,0.2,0.2,0.2);
85  _tuner_triangle(w, width/5.8,y0 , 25/w->scale.ascale, 20/w->scale.ascale);
86  _tuner_triangle(w, width/1.2, y0, -25/w->scale.ascale, 20/w->scale.ascale);
87 
88  float value = adj_get_value(w->adj);
89  float scale = -0.5;
90 
91  float fvis = _get_tuner_temperament(w) * (log2f(value/xt->ref_freq) + 4);
92  float fvisr = round(fvis);
93  int vis = fvisr;
94  int indicate_oc = round((fvisr+xt->temp_adjust)/_get_tuner_temperament(w));
95  const int octsz = sizeof(octave) / sizeof(octave[0]);
96  if (indicate_oc < 0 || indicate_oc >= octsz) {
97  // just safety, should not happen with current parameters
98  // (pitch tracker output 23 .. 999 Hz)
99  indicate_oc = octsz - 1;
100  }
101 
102  scale = (fvis-vis) / 2;
103  vis = vis % _get_tuner_temperament(w);
104  if (vis < 0) {
105  vis += _get_tuner_temperament(w);
106  }
107 
108  if (value > 24.0 && value < 999.0) {
109  if (scale < 0.003) {
110  cairo_set_source_rgb(w->crb,0.80,0.79,0.01);
111  _tuner_triangle(w, (width/5.8),y0 , 25/w->scale.ascale, 20/w->scale.ascale);
112  _tuner_triangle(w, (width/5.8)-(140*scale)/w->scale.ascale,y0 , 25/w->scale.ascale, 20/w->scale.ascale);
113  _tuner_triangle(w, (width/5.8)-(280*scale)/w->scale.ascale,y0 , 25/w->scale.ascale, 20/w->scale.ascale);
114  }
115  if (scale > -0.003) {
116  cairo_set_source_rgb(w->crb,0.80,0.79,0.01);
117  _tuner_triangle(w, (width/1.2), y0, -25/w->scale.ascale, 20/w->scale.ascale);
118  _tuner_triangle(w, (width/1.2)-(140*scale)/w->scale.ascale, y0, -25/w->scale.ascale, 20/w->scale.ascale);
119  _tuner_triangle(w, (width/1.2)-(280*scale)/w->scale.ascale, y0, -25/w->scale.ascale, 20/w->scale.ascale);
120  }
121  }
122  // display note
123  cairo_set_source_rgba(w->crb, fabsf(scale)*2, 1-(scale*scale*4), 0.2,1-(fabsf(scale)*2));
124  cairo_set_font_size(w->crb, (w->app->big_font*2)/w->scale.ascale);
125  cairo_text_extents_t extents;
126  cairo_text_extents(w->crb,_get_note_set(w)[vis] , &extents);
127 
128  if (value > 24.0 && value < 999.0) {
129  float c = (extents.width/2)+10.0;
130  cairo_move_to(w->crb,x0-c , y0 );
131  cairo_show_text(w->crb, _get_note_set(w)[vis]);
132  cairo_set_font_size(w->crb, (w->app->small_font*2)/w->scale.ascale);
133  cairo_move_to(w->crb,x0+c-10.0, y0+ extents.height/2 );
134  cairo_show_text(w->crb, octave[indicate_oc]);
135 
136  char s[64];
137  const char* format[] = {"%.1f Hz", "%.2f Hz", "%.3f Hz"};
138  snprintf(s, 63, format[2-1], value);
140  cairo_set_font_size (w->crb, w->app->normal_font/w->scale.ascale);
141  cairo_text_extents(w->crb,s , &extents);
142  cairo_move_to (w->crb, width/1.2-extents.width/2, height-extents.height );
143  cairo_show_text(w->crb, s);
144  }
145 }

References Widget_t::app, Widget_t::crb, Xputty::dpy, NORMAL_, Widget_t::parent_struct, use_bg_color_scheme(), and Widget_t::widget.

XTuner
Definition: xtuner.h:33
use_text_color_scheme
void use_text_color_scheme(Widget_t *w, Color_state st)
use_text_color_scheme - use text Colors to paint on Widget_t
Definition: xcolor.c:199
Xputty::big_font
int big_font
Definition: xputty.h:193
Widget_t::parent_struct
void * parent_struct
Definition: xwidget.h:306
Xputty::normal_font
int normal_font
Definition: xputty.h:191
adj_get_value
float adj_get_value(Adjustment_t *adj)
adj_get_value - get the current value of the Adjustment_t
Definition: xadjustment.c:154
Widget_t::crb
cairo_t * crb
Definition: xwidget.h:318
Widget_t::adj
Adjustment_t * adj
Definition: xwidget.h:334
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
use_bg_color_scheme
void use_bg_color_scheme(Widget_t *w, Color_state st)
use_bg_color_scheme - use background Colors to paint on Widget_t
Definition: xcolor.c:185
Widget_t::app
Xputty * app
Definition: xwidget.h:300
Xputty::dpy
Display * dpy
Definition: xputty.h:181
Resize_t::ascale
float ascale
Definition: xwidget.h:214
Widget_t::widget
Window widget
Definition: xwidget.h:302
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
XTuner::temp_adjust
int temp_adjust
Definition: xtuner.h:36
NORMAL_
@ NORMAL_
Definition: xcolor.h:39
Xputty::small_font
int small_font
Definition: xputty.h:189
XTuner::ref_freq
float ref_freq
Definition: xtuner.h:34