Merge with git+ssh://sgc@fondialog1.hum.uva.nl/fro/git/sgc.git
[sgc.git] / frompraat.c
blob662bd68413bcbc025e785abcdb9dda7ab8b440d0
1 #ifndef PITCHTIER
3 #include "sgc.h"
4 #include "frompraat.h"
6 /* Removed Speckle */
8 void Sampled_drawInside_cairo (I, cairo_t *cr, double xmin, double xmax, double ymin, double ymax, long ilevel, int unit)
10 iam (Sampled);
11 long ixmin, ixmax, ix, startOfDefinedStretch = -1;
12 float *xarray = NULL, *yarray = NULL;
13 double previousValue = NUMundefined;
14 Function_unidirectionalAutowindow (me, & xmin, & xmax);
15 Sampled_getWindowSamples (me, xmin, xmax, & ixmin, & ixmax);
16 if (ClassFunction_isUnitLogarithmic (my methods, ilevel, unit)) {
17 ymin = ClassFunction_convertStandardToSpecialUnit (my methods, ymin, ilevel, unit);
18 ymax = ClassFunction_convertStandardToSpecialUnit (my methods, ymax, ilevel, unit);
21 if (ymax <= ymin) return;
24 xarray = NUMfvector (ixmin - 1, ixmax + 1); cherror
25 yarray = NUMfvector (ixmin - 1, ixmax + 1); cherror
26 previousValue = Sampled_getValueAtSample (me, ixmin - 1, ilevel, unit);
27 if (NUMdefined (previousValue)) {
28 startOfDefinedStretch = ixmin - 1;
29 xarray [ixmin - 1] = Sampled_indexToX (me, ixmin - 1);
30 yarray [ixmin - 1] = previousValue;
34 for (ix = ixmin; ix <= ixmax; ix ++) {
35 double x = Sampled_indexToX (me, ix), value = Sampled_getValueAtSample (me, ix, ilevel, unit);
36 if (NUMdefined (value)) {
37 if (NUMdefined (previousValue)) {
38 xarray [ix] = x;
39 yarray [ix] = value;
40 } else {
41 startOfDefinedStretch = ix - 1;
42 xarray [ix - 1] = x - 0.5 * my dx;
43 yarray [ix - 1] = value;
44 xarray [ix] = x;
45 yarray [ix] = value;
47 } else if (NUMdefined (previousValue)) {
48 Melder_assert (startOfDefinedStretch >= ixmin - 1);
49 if (ix > ixmin) {
50 xarray [ix] = x - 0.5 * my dx;
51 yarray [ix] = previousValue;
52 if (xarray [startOfDefinedStretch] < xmin) {
53 double phase = (xmin - xarray [startOfDefinedStretch]) / my dx;
54 xarray [startOfDefinedStretch] = xmin;
55 yarray [startOfDefinedStretch] = phase * yarray [startOfDefinedStretch + 1] + (1.0 - phase) * yarray [startOfDefinedStretch];
57 Graphics_polyline_cairo (cr, ix + 1 - startOfDefinedStretch, & xarray [startOfDefinedStretch], & yarray [startOfDefinedStretch]);
60 startOfDefinedStretch = -1;
62 previousValue = value;
65 if (startOfDefinedStretch > -1) {
66 double x = Sampled_indexToX (me, ixmax + 1), value = Sampled_getValueAtSample (me, ixmax + 1, ilevel, unit);
67 Melder_assert (NUMdefined (previousValue));
68 if (NUMdefined (value)) {
69 xarray [ixmax + 1] = x;
70 yarray [ixmax + 1] = value;
71 } else {
72 xarray [ixmax + 1] = x - 0.5 * my dx;
73 yarray [ixmax + 1] = previousValue;
75 if (xarray [startOfDefinedStretch] < xmin) {
76 double phase = (xmin - xarray [startOfDefinedStretch]) / my dx;
77 xarray [startOfDefinedStretch] = xmin;
78 yarray [startOfDefinedStretch] = phase * yarray [startOfDefinedStretch + 1] + (1.0 - phase) * yarray [startOfDefinedStretch];
80 if (xarray [ixmax + 1] > xmax) {
81 double phase = (xarray [ixmax + 1] - xmax) / my dx;
82 xarray [ixmax + 1] = xmax;
83 yarray [ixmax + 1] = phase * yarray [ixmax] + (1.0 - phase) * yarray [ixmax + 1];
85 Graphics_polyline_cairo (cr, ixmax + 2 - startOfDefinedStretch, & xarray [startOfDefinedStretch], & yarray [startOfDefinedStretch]);
87 end:
88 NUMfvector_free (xarray, ixmin - 1);
89 NUMfvector_free (yarray, ixmin - 1);
90 Melder_clearError ();
93 void Graphics_polyline_cairo (cairo_t *cr, long numberOfPoints, float *xWC, float *yWC) { /* Base 0. */
94 short *xyDC;
95 long i;
97 if (! numberOfPoints) return;
99 xyDC = (short *) Melder_malloc (2 * numberOfPoints * sizeof (short));
100 if (! xyDC) return;
101 for (i = 0; i < numberOfPoints; i ++) {
102 xyDC [i + i] = xWC [i]*300;
103 xyDC [i + i + 1] = 300 - yWC [i];
105 polyline_cairo (cr, numberOfPoints, xyDC);
106 Melder_free (xyDC);
109 void polyline_cairo (cairo_t *cr, long numberOfPoints, short *xyDC) {
110 long i;
111 int halfLine = 1;
112 cairo_move_to (cr, xyDC [0] - halfLine, xyDC [1] - halfLine);
113 for (i = 1; i < numberOfPoints; i ++) {
114 cairo_line_to (cr, xyDC [i + i] - halfLine, xyDC [i + i + 1] - halfLine);
116 cairo_stroke(cr);
119 #endif