Label troep
[sgc.git] / cairo.c
blob0198caf5688afdab906848407dd7e3f948264d69
1 #include "sgc.h"
3 #ifdef PITCHTIER
5 void drawPitchTier(cairo_t *cr, gchar *filename, gint width, gint height, gdouble top) {
6 gchar *contents;
7 gsize length;
8 // g_debug("%s welcomes %s!", __func__, filename);
9 if (g_file_get_contents(filename, &contents, &length, NULL) != TRUE) {
10 } else {
11 gdouble scalex = 0, scaley = 0;
12 gdouble fromx = 0;
13 gdouble middlex = 0;
14 gdouble endx = 0;
15 gdouble fromy = 0;
16 gdouble middley = 0;
17 gsize i = 0;
18 gsize j = 0;
19 gsize m = 0;
20 int pointloc = 0;
21 while (i < length) {
22 if (contents[i] == '\n') {
23 gchar * this = g_strndup(&contents[m], i-m);
24 switch ( j ) {
25 case 0:
26 case 1:
27 case 2:
28 case 3:
29 fromx = g_strtod(this, NULL);
30 j++;
31 break;
32 case 4:
33 endx = g_strtod(this, NULL);
34 scalex = width / endx;
35 scaley = height / top;
36 cairo_move_to(cr, fromx*scalex, 0);
37 case 5:
38 j++;
39 break;
40 default:
41 if (pointloc == 0) {
42 middlex = g_strtod(this, NULL);
44 pointloc = 1;
45 } else {
46 gdouble to;
47 middley = g_strtod(this, NULL);
48 pointloc = 0;
49 to = height - (middley*scaley);
51 if ((middlex - fromx) < 0.015 && fromy != -1 && middley != -1) {
52 cairo_line_to(cr, middlex*scalex, to);
53 } else {
54 cairo_move_to(cr, middlex*scalex, to);
56 fromx = middlex;
57 fromy = middley;
61 g_free(this);
62 m = i+1;
64 i++;
66 cairo_stroke (cr);
68 // g_debug("%s for %s done!\n", __func__, filename);
71 #else
73 #include "frompraat.h"
75 void drawPitchTier(cairo_t *cr, gchar *filename, gint width, gint height, gdouble top) {
76 gchar *contents;
77 GError *error = NULL;
78 gsize length;
79 // g_debug("%s welcomes %s!", __func__, filename);
81 if (g_access(filename, F_OK) == 0) {
82 structMelderFile file;
83 Pitch melderPitchFromFile;
84 #ifdef MINGW
85 __declspec(dllimport) Pitch_Table classPitch;
86 #endif
88 Thing_recognizeClassesByName (classPitch, NULL);
89 Melder_pathToFile(filename, & file);
90 melderPitchFromFile = Data_readFromTextFile (& file);
92 Melder_clearError();
94 if (melderPitchFromFile != NULL) {
96 Sampled_drawInside_cairo (melderPitchFromFile, cr, 0.0, width, 0.0, height, Pitch_LEVEL_FREQUENCY, Pitch_UNIT_HERTZ);
97 forget(melderPitchFromFile);
100 Melder_clearError ();
101 // g_debug("%s for %s done!\n", __func__, filename);
104 #endif