25 static const char *note_sharp[] = {
"A",
"A#",
"B",
"C",
"C#",
"D",
"D#",
"E",
"F",
"F#",
"G",
"G#"};
26 static const char *note_flat[] = {
"A",
"Bb",
"B",
"C",
"Db",
"D",
"Eb",
"E",
"F",
"Gb",
"G",
"Ab"};
27 static const char* note_19[19] = {
"A",
"A♯",
"B♭",
"B",
"B♯",
"C",
"C♯",
"D♭",
"D",
"D♯",
"E♭",
"E",
"E♯",
"F",
"F♯",
"G♭",
"G",
"G♯",
"A♭"};
28 static const char* note_24[24] = {
"A",
"A¼♯",
"A♯",
"A¾♯",
"B",
"B¼♯",
"C",
"C¼♯",
"C♯",
"C¾♯",
"D",
"D¼♯",
"D♯",
"D¾♯",
"E",
"E¼♯",
"F",
"F¼♯",
"F♯",
"F¾♯",
"G",
"G¼♯",
"G♯",
"G¾♯"};
29 static const char* note_31[31] = {
"A",
"B♭♭",
"A♯",
"B♭",
"A♯♯",
"B",
"C♭",
"B♯",
"C ",
"D♭♭",
"C♯",
"D♭",
"C♯♯",
"D",
"E♭♭",
"D♯",
"E♭",
"D♯♯",
"E",
"F♭",
"E♯",
"F",
"G♭♭",
"F♯",
"G♭",
"F♯♯",
"G",
"A♭♭",
"G♯",
"A♭",
"G♯♯"};
30 static const char* note_53[53] = {
"la",
"laa",
"lo",
"law",
"ta",
"teh",
"te",
"tu",
"tuh",
"ti",
"tih",
"to",
"taw",
"da",
"do",
"di",
"daw",
"ro",
"rih",
"ra",
"ru",
"ruh",
"reh",
"re ",
"ri",
"raw",
"ma",
"meh",
"me",
"mu",
"muh",
"mi",
"maa",
"mo",
"maw",
"fe",
"fa",
"fih",
"fu",
"fuh",
"fi",
"se",
"suh",
"su",
"sih",
"sol",
"si",
"saw",
"lo",
"leh",
"le",
"lu",
"luh"};
31 static const char *octave[] = {
"0",
"1",
"2",
"3",
"4",
"5",
" "};
33 static void _tuner_triangle(
Widget_t *w,
float posx,
float posy,
float width,
float height)
35 float h2 = height/2.0;
36 cairo_move_to(w->
crb, posx, posy-h2);
38 cairo_curve_to(w->
crb,posx, posy-h2, posx+10, posy, posx, posy+h2);
40 cairo_curve_to(w->
crb,posx, posy-h2, posx-10, posy, posx, posy+h2);
42 cairo_curve_to(w->
crb,posx, posy+h2, posx+width/2, posy+h2, posx+width, posy);
43 cairo_curve_to(w->
crb, posx+width, posy, posx+width/2, posy-h2, posx, posy-h2);
45 cairo_new_path (w->
crb);
48 static int _get_tuner_temperament(
Widget_t *w) {
58 static const char **_get_note_set(
Widget_t *w) {
65 else return note_flat;
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;
84 cairo_set_source_rgb(w->
crb,0.2,0.2,0.2);
91 float fvis = _get_tuner_temperament(w) * (log2f(value/xt->
ref_freq) + 4);
92 float fvisr = round(fvis);
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) {
99 indicate_oc = octsz - 1;
102 scale = (fvis-vis) / 2;
103 vis = vis % _get_tuner_temperament(w);
105 vis += _get_tuner_temperament(w);
108 if (value > 24.0 && value < 999.0) {
110 cairo_set_source_rgb(w->
crb,0.80,0.79,0.01);
115 if (scale > -0.003) {
116 cairo_set_source_rgb(w->
crb,0.80,0.79,0.01);
123 cairo_set_source_rgba(w->
crb, fabsf(scale)*2, 1-(scale*scale*4), 0.2,1-(fabsf(scale)*2));
125 cairo_text_extents_t extents;
126 cairo_text_extents(w->
crb,_get_note_set(w)[vis] , &extents);
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]);
133 cairo_move_to(w->
crb,x0+c-10.0, y0+ extents.height/2 );
134 cairo_show_text(w->
crb, octave[indicate_oc]);
137 const char* format[] = {
"%.1f Hz",
"%.2f Hz",
"%.3f Hz"};
138 snprintf(s, 63, format[2-1], value);
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);