Update zodat ik PPC kan scheiden. Verder wat overige GUI abstracties.
[sgc.git] / cairo.c.toonew
blobe7d9bdb07b003d8dd0c4410551d014b556bd84c7
1 #include "sgc.h"
3 void drawPitchTier(cairo_t *cr, gchar *filename, gint width, gint height, gdouble top) {
4         gchar *contents;
5         GError *error = NULL;
6         gsize length;
7         g_debug("%s welcomes %s!", __func__, filename);
9         if (g_access(path, F_OK) == 0) {
10                 structMelderFile file;
11                 Pitch melderPitchFromFile;
12 #ifdef MINGW
13                 __declspec(dllimport) Pitch_Table classPitch;
14 #endif
15                 Thing_recognizeClassesByName (classPitch, NULL);
16                 Melder_pathToFile(path, & file);
17                 melderPitchFromFile = Data_readFromTextFile (& file);
19                 if (melderPitchFromFile != NULL) {
20                         forget(melderPitchFromFile);
21                 }
24         }
25         Melder_clearError ();
28         if (g_file_get_contents(filename, &contents, &length, &error) != TRUE) {
29                 //              g_warning("HET PROBLEEM ZIT IN HET INLEZEN VAN HET %s BESTAND!!!!!\n", filename);
30                 g_warning("%s\n", error->message);
31                 g_error_free(error);
32         } else {
33                 gdouble scalex = 0, scaley = 0;
34                 gdouble fromx = 0;
35                 gdouble middlex = 0;
36                 gdouble endx = 0;
37                 gdouble fromy = 0;
38                 gdouble middley = 0;
39                 gsize i = 0;
40                 gsize j = 0;
41                 gsize m = 0;
42                 int pointloc = 0;
43                 while (i < length) {
44                         if (contents[i] == '\n') {
45                                 gchar * this = g_strndup(&contents[m], i-m);
46                                 switch ( j ) {
47                                         case 0:
48                                         case 1:
49                                         case 2:
50                                         case 3:
51                                                 fromx = g_strtod(this, NULL);
52                                                 j++;
53                                                 break;
54                                         case 4:
55                                                 endx  = g_strtod(this, NULL);
56                                                 scalex = width / endx;
57                                                 scaley = height / top;
58                                                 cairo_move_to(cr, fromx*scalex, 0);
59                                         case 5:
60                                                 j++;
61                                                 break;
62                                         default:
63                                                 if (pointloc == 0) {
64                                                         middlex = g_strtod(this, NULL);
66                                                         pointloc = 1;
67                                                 } else {
68                                                         gdouble to;
69                                                         middley = g_strtod(this, NULL);
70                                                         pointloc = 0;
71                                                         to = height - (middley*scaley);
73                                                         if ((middlex - fromx) < 0.015 && fromy != -1 && middley != -1) {
74                                                                 cairo_line_to(cr, middlex*scalex,  to);
75                                                         } else {
76                                                                 cairo_move_to(cr, middlex*scalex,  to);
77                                                         }
78                                                         fromx = middlex;
79                                                         fromy = middley;
80                                                 }
82                                 }
83                                 g_free(this);
84                                 m = i+1;
85                         }
86                         i++;
87                 }
88                 cairo_stroke (cr);
89         }
90         g_debug("%s for %s done!\n", __func__, filename);