~ubuntu-branches/ubuntu/lucid/ardour/lucid-proposed

« back to all changes in this revision

Viewing changes to gtk2_ardour/canvas-waveview.c

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2008-02-07 20:51:55 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080207205155-xzi5lq5s2o1okvx8
Tags: 1:2.3.1-1
* New upstream release
* debian/control:
   - build-depend on libfftw3-dev (Closes: #463803)
   - added Homepage, Vcs-Svn, Vcs-Browser
* debian/patches
   - dropped 50-soundtouch.patch (fixed upstream)
   - updated 80_ardourino.patch
   - dropped unused patches from source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
     along with this program; if not, write to the Free Software
16
16
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
17
 
18
 
     $Id: canvas-waveview.c 1668 2007-04-05 21:56:32Z paul $
 
18
     $Id: canvas-waveview.c 2951 2008-01-19 22:15:43Z nostar $
19
19
*/
20
20
 
21
21
#include <stdio.h>
52
52
         PROP_WAVE_COLOR,
53
53
         PROP_CLIP_COLOR,
54
54
         PROP_ZERO_COLOR,
 
55
         PROP_FILL_COLOR,
 
56
         PROP_FILLED,
55
57
         PROP_RECTIFIED,
 
58
         PROP_ZERO_LINE,
56
59
         PROP_REGION_START,
57
60
         PROP_LOGSCALED,
58
61
};
265
268
                  g_param_spec_uint ("zero_color", NULL, NULL,
266
269
                                     0, G_MAXUINT, 0,
267
270
                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
 
271
 
 
272
         g_object_class_install_property
 
273
                 (gobject_class,
 
274
                  PROP_FILL_COLOR,
 
275
                  g_param_spec_uint ("fill_color", NULL, NULL,
 
276
                                     0, G_MAXUINT, 0,
 
277
                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
 
278
 
 
279
         g_object_class_install_property
 
280
                 (gobject_class,
 
281
                  PROP_FILLED,
 
282
                  g_param_spec_boolean ("filled", NULL, NULL,
 
283
                                        FALSE,
 
284
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
268
285
         
269
286
         g_object_class_install_property
270
287
                 (gobject_class,
275
292
 
276
293
         g_object_class_install_property
277
294
                 (gobject_class,
 
295
                  PROP_ZERO_LINE,
 
296
                  g_param_spec_boolean ("zero_line", NULL, NULL,
 
297
                                        FALSE,
 
298
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
 
299
 
 
300
         g_object_class_install_property
 
301
                 (gobject_class,
278
302
                  PROP_LOGSCALED,
279
303
                  g_param_spec_boolean ("logscaled", NULL, NULL,
280
304
                                        FALSE,
335
359
        waveview->gain_src = NULL;
336
360
        waveview->rectified = FALSE;
337
361
        waveview->logscaled = FALSE;
 
362
        waveview->filled = TRUE;
 
363
        waveview->zero_line = FALSE;
338
364
        waveview->region_start = 0;
339
365
        waveview->samples_per_unit = 1.0;
340
366
        waveview->amplitude_above_axis = 1.0;
342
368
        waveview->screen_width = gdk_screen_width ();
343
369
        waveview->reload_cache_in_render = FALSE;
344
370
 
345
 
        waveview->wave_color = RGBA_TO_UINT(44,35,126,255);
346
 
        waveview->clip_color = RGBA_TO_UINT(44,0,0,100);
347
 
        waveview->zero_color = RGBA_TO_UINT(44,0,128,100);
 
371
        waveview->wave_color = 0;
 
372
        waveview->clip_color = 0;
 
373
        waveview->zero_color = 0;
 
374
        waveview->fill_color = 0;
348
375
}
349
376
 
350
377
static void
830
857
                }
831
858
                break;
832
859
 
 
860
        case PROP_FILL_COLOR:
 
861
                if (waveview->fill_color != g_value_get_uint(value)) {
 
862
                        waveview->fill_color = g_value_get_uint(value);
 
863
                        redraw = TRUE;
 
864
                }
 
865
                break;
 
866
 
 
867
        case PROP_FILLED:
 
868
                if (waveview->filled != g_value_get_boolean(value)) {
 
869
                        waveview->filled = g_value_get_boolean(value);
 
870
                        redraw = TRUE;
 
871
                }
 
872
                break;
 
873
 
833
874
        case PROP_RECTIFIED:
834
875
                if (waveview->rectified != g_value_get_boolean(value)) {
835
876
                        waveview->rectified = g_value_get_boolean(value);
836
877
                        redraw = TRUE;
837
878
                }
838
879
                break;
 
880
 
 
881
        case PROP_ZERO_LINE:
 
882
                if (waveview->zero_line != g_value_get_boolean(value)) {
 
883
                        waveview->zero_line = g_value_get_boolean(value);
 
884
                        redraw = TRUE;
 
885
                }
 
886
                break;
 
887
 
839
888
        case PROP_LOGSCALED:
840
889
                if (waveview->logscaled != g_value_get_boolean(value)) {
841
890
                        waveview->logscaled = g_value_get_boolean(value);
950
999
                g_value_set_uint (value, waveview->zero_color);
951
1000
                break;
952
1001
 
 
1002
        case PROP_FILL_COLOR:
 
1003
                g_value_set_uint (value, waveview->fill_color);
 
1004
                break;
 
1005
 
 
1006
        case PROP_FILLED:
 
1007
                g_value_set_boolean (value, waveview->filled);
 
1008
                break;
 
1009
 
953
1010
        case PROP_RECTIFIED:
954
1011
                g_value_set_boolean (value, waveview->rectified);
955
1012
                break;
956
1013
 
 
1014
        case PROP_ZERO_LINE:
 
1015
                g_value_set_boolean (value, waveview->zero_line);
 
1016
                break;
 
1017
 
957
1018
        case PROP_LOGSCALED:
958
1019
                g_value_set_boolean (value, waveview->logscaled);
959
1020
                break;
1012
1073
                      &waveview->wave_a);
1013
1074
        UINT_TO_RGBA (waveview->clip_color, &waveview->clip_r, &waveview->clip_g, &waveview->clip_b,
1014
1075
                      &waveview->clip_a);
 
1076
        UINT_TO_RGBA (waveview->fill_color, &waveview->fill_r, &waveview->fill_g, &waveview->fill_b,
 
1077
                      &waveview->fill_a);
1015
1078
 
1016
1079
//      check_cache (waveview, "end of update");
1017
 
}
 
1080
}                                  
1018
1081
 
1019
1082
static void
1020
1083
gnome_canvas_waveview_render (GnomeCanvasItem *item,
1028
1091
        double half_height;
1029
1092
        int x, end, begin;
1030
1093
        int zbegin, zend;
 
1094
        char rectify;
1031
1095
 
1032
1096
        waveview = GNOME_CANVAS_WAVEVIEW (item);
1033
1097
 
1107
1171
                waveview->reload_cache_in_render = FALSE;
1108
1172
        }
1109
1173
 
1110
 
        cache_index = gnome_canvas_waveview_ensure_cache (waveview, s1, s2);
1111
 
 
1112
1174
//      check_cache (waveview, "post-ensure");
1113
1175
 
 
1176
        /* don't rectify at single-sample zoom */
 
1177
        if(waveview->rectified && waveview->samples_per_unit > 1) {
 
1178
                rectify = TRUE;
 
1179
        }
 
1180
        else {
 
1181
                rectify = FALSE;
 
1182
        }
 
1183
 
 
1184
        clip_length = MIN(5,(waveview->height/4));
 
1185
 
1114
1186
        /* 
1115
1187
           Now draw each line, clipping it appropriately. The clipping
1116
1188
           is done by the macros PAINT_FOO().
1119
1191
        half_height = waveview->half_height;
1120
1192
 
1121
1193
/* this makes it slightly easier to comprehend whats going on */
1122
 
 
1123
1194
#define origin half_height
1124
1195
 
1125
 
 
1126
 
        for (x = begin; x < end; x++) {
1127
 
 
1128
 
                double max, min;
1129
 
                int clip_max, clip_min;
1130
 
                
1131
 
                clip_max = 0;
1132
 
                clip_min = 0;
1133
 
 
1134
 
                max = waveview->cache->data[cache_index].max;
1135
 
                min = waveview->cache->data[cache_index].min;
1136
 
                
1137
 
                if (max >= 1.0) {
1138
 
                        max = 1.0;
1139
 
                        clip_max = 1;
1140
 
                }
1141
 
 
1142
 
                if (min <= -1.0) {
1143
 
                        min = -1.0;
1144
 
                        clip_min = 1;
1145
 
                }
1146
 
 
1147
 
                /* don't rectify at single-sample zoom */
1148
 
 
1149
 
                if (waveview->rectified && waveview->samples_per_unit > 1) {
1150
 
 
1151
 
                        if (fabs (min) > fabs (max)) {
1152
 
                                max = fabs (min);
1153
 
                        } 
1154
 
 
1155
 
                        max = max * waveview->height;
1156
 
 
1157
 
                        pymax = (int) rint ((item->y1 + waveview->height - max) * item->canvas->pixels_per_unit);
1158
 
                        pymin = (int) rint ((item->y1 + waveview->height) * item->canvas->pixels_per_unit);
1159
 
 
1160
 
                } else {
1161
 
                        
1162
 
                        max = max * half_height;
1163
 
                        min = min * half_height;
1164
 
                        
1165
 
                        pymax = (int) rint ((item->y1 + origin - max) * item->canvas->pixels_per_unit);
1166
 
                        pymin = (int) rint ((item->y1 + origin - min) * item->canvas->pixels_per_unit);
1167
 
                }
1168
 
 
1169
 
                /* OK, now fill the RGB buffer at x=i with a line between pymin and pymax,
1170
 
                   or, if samples_per_unit == 1, then a dot at each location.
1171
 
                */
1172
 
 
1173
 
                if (pymax == pymin) {
1174
 
                        PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymin);
1175
 
                } else {
1176
 
                        PAINT_VERTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymax, pymin);
1177
 
                }
1178
 
                
1179
 
                /* show clipped waveforms with small red lines */
1180
 
 
1181
 
                if (clip_max || clip_min) {
1182
 
                        clip_length = MIN(5,(waveview->height/4));
1183
 
                }
1184
 
 
1185
 
                if (clip_max) {
1186
 
                        PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymax, pymax+clip_length);
1187
 
                }
1188
 
 
1189
 
                if (clip_min) {
1190
 
                        PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymin-clip_length, pymin);
1191
 
                }
1192
 
 
1193
 
                /* presto, we're done */
1194
 
                
1195
 
                cache_index++;
1196
 
        }
1197
 
 
1198
 
        if (!waveview->rectified) {
 
1196
        if(waveview->filled && !rectify) {
 
1197
                int prev_pymin = 1;
 
1198
                int prev_pymax = 0;
 
1199
                int last_pymin = 1;
 
1200
                int last_pymax = 0;
 
1201
                int next_pymin, next_pymax;
 
1202
                double max, min;
 
1203
                int next_clip_max = 0;
 
1204
                int next_clip_min = 0;
 
1205
 
 
1206
                if(s1 < waveview->samples_per_unit) {
 
1207
                        /* we haven't got a prev vars to compare with, so outline the whole line here */
 
1208
                        prev_pymax = (int) rint ((item->y1 + origin) * item->canvas->pixels_per_unit);
 
1209
                        prev_pymin = prev_pymax;
 
1210
                }
 
1211
                else {
 
1212
                        s1 -= waveview->samples_per_unit;
 
1213
                }
 
1214
 
 
1215
                if(end == waveview->bbox_lrx) {
 
1216
                        /* we don't have the NEXT vars for the last sample */
 
1217
                        last_pymax = (int) rint ((item->y1 + origin) * item->canvas->pixels_per_unit);
 
1218
                        last_pymin = last_pymax;
 
1219
                }
 
1220
                else {
 
1221
                        s2 += waveview->samples_per_unit;
 
1222
                }
 
1223
 
 
1224
                cache_index = gnome_canvas_waveview_ensure_cache (waveview, s1, s2);
 
1225
 
 
1226
                /*
 
1227
                 * Compute the variables outside the rendering rect
 
1228
                 */
 
1229
                if(prev_pymax != prev_pymin) {
 
1230
                        prev_pymax = (int) rint ((item->y1 + origin - MIN(waveview->cache->data[cache_index].max, 1.0) * half_height) * item->canvas->pixels_per_unit);
 
1231
                        prev_pymin = (int) rint ((item->y1 + origin - MAX(waveview->cache->data[cache_index].min, -1.0) * half_height) * item->canvas->pixels_per_unit);
 
1232
                        ++cache_index;
 
1233
                }
 
1234
                if(last_pymax != last_pymin) {
 
1235
                        /* take the index of one sample right of what we render */
 
1236
                        int index = cache_index + (end - begin);
 
1237
                        
 
1238
                        last_pymax = (int) rint ((item->y1 + origin - MIN(waveview->cache->data[index].max, 1.0) * half_height) * item->canvas->pixels_per_unit);
 
1239
                        last_pymin = (int) rint ((item->y1 + origin - MAX(waveview->cache->data[index].min, -1.0) * half_height) * item->canvas->pixels_per_unit);
 
1240
                }
 
1241
 
 
1242
                /* 
 
1243
                 * initialize NEXT* variables for the first run, duplicated in the loop for speed
 
1244
                 */
 
1245
                max = waveview->cache->data[cache_index].max;
 
1246
                min = waveview->cache->data[cache_index].min;
 
1247
                
 
1248
                if (max >= 1.0) {
 
1249
                        max = 1.0;
 
1250
                        next_clip_max = 1;
 
1251
                }
 
1252
                
 
1253
                if (min <= -1.0) {
 
1254
                        min = -1.0;
 
1255
                        next_clip_min = 1;
 
1256
                }
 
1257
                
 
1258
                max *= half_height;
 
1259
                min *= half_height;
 
1260
                
 
1261
                next_pymax = (int) rint ((item->y1 + origin - max) * item->canvas->pixels_per_unit);
 
1262
                next_pymin = (int) rint ((item->y1 + origin - min) * item->canvas->pixels_per_unit);
 
1263
 
 
1264
                /*
 
1265
                 * And now the loop
 
1266
                 */
 
1267
                for(x = begin; x < end; ++x) {
 
1268
                        int clip_max = next_clip_max;
 
1269
                        int clip_min = next_clip_min;
 
1270
                        int fill_max, fill_min;
 
1271
 
 
1272
                        pymax = next_pymax;
 
1273
                        pymin = next_pymin;
 
1274
 
 
1275
                        /* compute next */
 
1276
                        if(x == end - 1) {
 
1277
                                /*next is now the last column, which is outside the rendering rect, and possibly outside the region*/
 
1278
                                next_pymax = last_pymax;
 
1279
                                next_pymin = last_pymin;
 
1280
                        }
 
1281
                        else {
 
1282
                                ++cache_index;
 
1283
 
 
1284
                                max = waveview->cache->data[cache_index].max;
 
1285
                                min = waveview->cache->data[cache_index].min;
 
1286
 
 
1287
                                next_clip_max = 0;
 
1288
                                next_clip_min = 0;
 
1289
 
 
1290
                                if (max >= 1.0) {
 
1291
                                        max = 1.0;
 
1292
                                        next_clip_max = 1;
 
1293
                                }
 
1294
                                
 
1295
                                if (min <= -1.0) {
 
1296
                                        min = -1.0;
 
1297
                                        next_clip_min = 1;
 
1298
                                }
 
1299
 
 
1300
                                max *= half_height;
 
1301
                                min *= half_height;
 
1302
                                
 
1303
                                next_pymax = (int) rint ((item->y1 + origin - max) * item->canvas->pixels_per_unit);
 
1304
                                next_pymin = (int) rint ((item->y1 + origin - min) * item->canvas->pixels_per_unit);
 
1305
                        }
 
1306
                        
 
1307
                        /* render */
 
1308
                        if (pymax == pymin) {
 
1309
                                PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymin);
 
1310
                        } else {
 
1311
                                if((prev_pymax < pymax && next_pymax < pymax) ||
 
1312
                                   (prev_pymax == pymax && next_pymax == pymax)) {
 
1313
                                        fill_max = pymax + 1;
 
1314
                                        PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymax);
 
1315
                                }
 
1316
                                else {
 
1317
                                        fill_max = MAX(prev_pymax, next_pymax);
 
1318
                                        if(pymax == fill_max) {
 
1319
                                                PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymax);
 
1320
                                                ++fill_max;
 
1321
                                        }
 
1322
                                        else {
 
1323
                                                PAINT_VERTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymax, fill_max);
 
1324
                                        }
 
1325
                                }
 
1326
 
 
1327
                                if((prev_pymin > pymin && next_pymin > pymin) ||
 
1328
                                   (prev_pymin == pymin && next_pymin == pymin)) {
 
1329
                                        fill_min = pymin - 1;
 
1330
                                        PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymin-1);
 
1331
                                }
 
1332
                                else {
 
1333
                                        fill_min = MIN(prev_pymin, next_pymin);
 
1334
                                        if(pymin == fill_min) {
 
1335
                                                PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymin);
 
1336
                                        }
 
1337
                                        else {
 
1338
                                                PAINT_VERTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, fill_min, pymin);
 
1339
                                        }
 
1340
                                }
 
1341
 
 
1342
                                if(fill_max < fill_min) {
 
1343
                                        PAINT_VERTA(buf, waveview->fill_r, waveview->fill_g, waveview->fill_b, waveview->fill_a, x, fill_max, fill_min);
 
1344
                                }
 
1345
                                else if(fill_max == fill_min) {
 
1346
                                        PAINT_DOTA(buf, waveview->fill_r, waveview->fill_g, waveview->fill_b, waveview->fill_a, x, fill_max);
 
1347
                                }
 
1348
                        }
 
1349
 
 
1350
                        if (clip_max) {
 
1351
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymax, pymax+clip_length);
 
1352
                        }
 
1353
                        
 
1354
                        if (clip_min) {
 
1355
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymin-clip_length, pymin);
 
1356
                        }
 
1357
 
 
1358
                        prev_pymax = pymax;
 
1359
                        prev_pymin = pymin;
 
1360
                }
 
1361
        }
 
1362
        else if(waveview->filled && rectify) {
 
1363
                int prev_pymax = -1;
 
1364
                int last_pymax = -1;
 
1365
                int next_pymax;
 
1366
                double max, min;
 
1367
                int next_clip_max = 0;
 
1368
                int next_clip_min = 0;
 
1369
 
 
1370
                // for rectified, this stays constant throughout the loop
 
1371
                pymin = (int) rint ((item->y1 + waveview->height) * item->canvas->pixels_per_unit);
 
1372
 
 
1373
                if(s1 < waveview->samples_per_unit) {
 
1374
                        /* we haven't got a prev vars to compare with, so outline the whole line here */
 
1375
                        prev_pymax = pymin;
 
1376
                }
 
1377
                else {
 
1378
                        s1 -= waveview->samples_per_unit;
 
1379
                }
 
1380
 
 
1381
                if(end == waveview->bbox_lrx) {
 
1382
                        /* we don't have the NEXT vars for the last sample */
 
1383
                        last_pymax = pymin;
 
1384
                }
 
1385
                else {
 
1386
                        s2 += waveview->samples_per_unit;
 
1387
                }
 
1388
 
 
1389
                cache_index = gnome_canvas_waveview_ensure_cache (waveview, s1, s2);
 
1390
 
 
1391
                /*
 
1392
                 * Compute the variables outside the rendering rect
 
1393
                 */
 
1394
                if(prev_pymax < 0) {
 
1395
                        max = MIN(waveview->cache->data[cache_index].max, 1.0);
 
1396
                        min = MAX(waveview->cache->data[cache_index].min, -1.0);
 
1397
 
 
1398
                        if (fabs (min) > fabs (max)) {
 
1399
                                max = fabs (min);
 
1400
                        }
 
1401
 
 
1402
                        prev_pymax = (int) rint ((item->y1 + waveview->height - max * waveview->height) * item->canvas->pixels_per_unit);
 
1403
                        ++cache_index;
 
1404
                }
 
1405
                if(last_pymax < 0) {
 
1406
                        /* take the index of one sample right of what we render */
 
1407
                        int index = cache_index + (end - begin);
 
1408
                        
 
1409
                        max = MIN(waveview->cache->data[index].max, 1.0);
 
1410
                        min = MAX(waveview->cache->data[index].min, -1.0);
 
1411
 
 
1412
                        if (fabs (min) > fabs (max)) {
 
1413
                                max = fabs (min);
 
1414
                        }
 
1415
 
 
1416
                        last_pymax = (int) rint ((item->y1 + waveview->height - max * waveview->height) * item->canvas->pixels_per_unit);
 
1417
                }
 
1418
 
 
1419
                /* 
 
1420
                 * initialize NEXT* variables for the first run, duplicated in the loop for speed
 
1421
                 */
 
1422
                max = waveview->cache->data[cache_index].max;
 
1423
                min = waveview->cache->data[cache_index].min;
 
1424
                
 
1425
                if (max >= 1.0) {
 
1426
                        max = 1.0;
 
1427
                        next_clip_max = 1;
 
1428
                }
 
1429
                
 
1430
                if (min <= -1.0) {
 
1431
                        min = -1.0;
 
1432
                        next_clip_min = 1;
 
1433
                }
 
1434
                
 
1435
                if (fabs (min) > fabs (max)) {
 
1436
                        max = fabs (min);
 
1437
                } 
 
1438
                
 
1439
                next_pymax = (int) rint ((item->y1 + waveview->height - max * waveview->height) * item->canvas->pixels_per_unit);
 
1440
 
 
1441
                /*
 
1442
                 * And now the loop
 
1443
                 */
 
1444
                for(x = begin; x < end; ++x) {
 
1445
                        int clip_max = next_clip_max;
 
1446
                        int clip_min = next_clip_min;
 
1447
                        int fill_max;
 
1448
 
 
1449
                        pymax = next_pymax;
 
1450
 
 
1451
                        /* compute next */
 
1452
                        if(x == end - 1) {
 
1453
                                /*next is now the last column, which is outside the rendering rect, and possibly outside the region*/
 
1454
                                next_pymax = last_pymax;
 
1455
                        }
 
1456
                        else {
 
1457
                                ++cache_index;
 
1458
 
 
1459
                                max = waveview->cache->data[cache_index].max;
 
1460
                                min = waveview->cache->data[cache_index].min;
 
1461
                                
 
1462
                                if (max >= 1.0) {
 
1463
                                        max = 1.0;
 
1464
                                        next_clip_max = 1;
 
1465
                                }
 
1466
                                
 
1467
                                if (min <= -1.0) {
 
1468
                                        min = -1.0;
 
1469
                                        next_clip_min = 1;
 
1470
                                }
 
1471
                                
 
1472
                                if (fabs (min) > fabs (max)) {
 
1473
                                        max = fabs (min);
 
1474
                                } 
 
1475
                                
 
1476
                                next_pymax = (int) rint ((item->y1 + waveview->height - max * waveview->height) * item->canvas->pixels_per_unit);
 
1477
                        }
 
1478
                        
 
1479
                        /* render */
 
1480
                        if (pymax == pymin) {
 
1481
                                PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymin);
 
1482
                        } else {
 
1483
                                if((prev_pymax < pymax && next_pymax < pymax) ||
 
1484
                                   (prev_pymax == pymax && next_pymax == pymax)) {
 
1485
                                        fill_max = pymax + 1;
 
1486
                                        PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymax);
 
1487
                                }
 
1488
                                else {
 
1489
                                        fill_max = MAX(prev_pymax, next_pymax);
 
1490
                                        if(pymax == fill_max) {
 
1491
                                                PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymax);
 
1492
                                                ++fill_max;
 
1493
                                        }
 
1494
                                        else {
 
1495
                                                PAINT_VERTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymax, fill_max);
 
1496
                                        }
 
1497
                                }
 
1498
 
 
1499
                                if(fill_max < pymin) {
 
1500
                                        PAINT_VERTA(buf, waveview->fill_r, waveview->fill_g, waveview->fill_b, waveview->fill_a, x, fill_max, pymin);
 
1501
                                }
 
1502
                                else if(fill_max == pymin) {
 
1503
                                        PAINT_DOTA(buf, waveview->fill_r, waveview->fill_g, waveview->fill_b, waveview->fill_a, x, pymin);
 
1504
                                }
 
1505
                        }
 
1506
 
 
1507
                        if (clip_max) {
 
1508
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymax, pymax+clip_length);
 
1509
                        }
 
1510
                        
 
1511
                        if (clip_min) {
 
1512
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymin-clip_length, pymin);
 
1513
                        }
 
1514
 
 
1515
                        prev_pymax = pymax;
 
1516
                }
 
1517
        }
 
1518
        else {
 
1519
                cache_index = gnome_canvas_waveview_ensure_cache (waveview, s1, s2);
 
1520
 
 
1521
                for (x = begin; x < end; x++) {
 
1522
                        
 
1523
                        double max, min;
 
1524
                        int clip_max, clip_min;
 
1525
                        
 
1526
                        clip_max = 0;
 
1527
                        clip_min = 0;
 
1528
                        
 
1529
                        max = waveview->cache->data[cache_index].max;
 
1530
                        min = waveview->cache->data[cache_index].min;
 
1531
                        
 
1532
                        if (max >= 1.0) {
 
1533
                                max = 1.0;
 
1534
                                clip_max = 1;
 
1535
                        }
 
1536
                        
 
1537
                        if (min <= -1.0) {
 
1538
                                min = -1.0;
 
1539
                                clip_min = 1;
 
1540
                        }
 
1541
                        
 
1542
                        if (rectify) {
 
1543
                                
 
1544
                                if (fabs (min) > fabs (max)) {
 
1545
                                        max = fabs (min);
 
1546
                                } 
 
1547
                                
 
1548
                                max = max * waveview->height;
 
1549
                                
 
1550
                                pymax = (int) rint ((item->y1 + waveview->height - max) * item->canvas->pixels_per_unit);
 
1551
                                pymin = (int) rint ((item->y1 + waveview->height) * item->canvas->pixels_per_unit);
 
1552
                                
 
1553
                        } else {
 
1554
                                
 
1555
                                max = max * half_height;
 
1556
                                min = min * half_height;
 
1557
                                
 
1558
                                pymax = (int) rint ((item->y1 + origin - max) * item->canvas->pixels_per_unit);
 
1559
                                pymin = (int) rint ((item->y1 + origin - min) * item->canvas->pixels_per_unit);
 
1560
                        }
 
1561
                        
 
1562
                        /* OK, now fill the RGB buffer at x=i with a line between pymin and pymax,
 
1563
                           or, if samples_per_unit == 1, then a dot at each location.
 
1564
                        */
 
1565
                        
 
1566
                        if (pymax == pymin) {
 
1567
                                PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymin);
 
1568
                        } else {
 
1569
                                PAINT_VERTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymax, pymin);
 
1570
                        }
 
1571
                        
 
1572
                        /* show clipped waveforms with small red lines */
 
1573
                        
 
1574
                        if (clip_max) {
 
1575
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymax, pymax+clip_length);
 
1576
                        }
 
1577
                        
 
1578
                        if (clip_min) {
 
1579
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymin-clip_length, pymin);
 
1580
                        }
 
1581
 
 
1582
                        /* presto, we're done */
 
1583
                
 
1584
                        cache_index++;
 
1585
                }
 
1586
        }
 
1587
 
 
1588
        if (!waveview->rectified && waveview->zero_line) {
1199
1589
                // Paint zeroline.
1200
1590
                //PAINT_HORIZA(buf, waveview->zero_r, waveview->zero_g, waveview->zero_b, waveview->zero_a, begin, endi-1, origin );
1201
1591