merged with 1697 revision of trunk (which is post-rc1 but pre-rc2
[ardour.git] / gtk2_ardour / canvas-waveview.h
1 /* libgnomecanvas/gnome-canvas-waveview.h: GnomeCanvas item for displaying wave data
2  *
3  * Copyright (C) 2001 Paul Davis <pbd@op.net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  */
21
22 #ifndef __GNOME_CANVAS_WAVEVIEW_H__
23 #define __GNOME_CANVAS_WAVEVIEW_H__
24
25 #include <stdint.h>
26
27 #include <libgnomecanvas/libgnomecanvas.h>
28
29 G_BEGIN_DECLS
30
31 /* Wave viewer item for canvas.
32  */
33
34 #define GNOME_TYPE_CANVAS_WAVEVIEW            (gnome_canvas_waveview_get_type ())
35 #define GNOME_CANVAS_WAVEVIEW(obj)            (GTK_CHECK_CAST ((obj), GNOME_TYPE_CANVAS_WAVEVIEW, GnomeCanvasWaveView))
36 #define GNOME_CANVAS_WAVEVIEW_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), GNOME_TYPE_CANVAS_WAVEVIEW, GnomeCanvasWaveViewClass))
37 #define GNOME_IS_CANVAS_WAVEVIEW(obj)         (GTK_CHECK_TYPE ((obj), GNOME_TYPE_CANVAS_WAVEVIEW))
38 #define GNOME_IS_CANVAS_WAVEVIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_CANVAS_WAVEVIEW))
39 #define GNOME_CANVAS_WAVEVIEW_GET_CLASS(obj)  (GTK_CHECK_GET_CLASS ((obj), GNOME_TYPE_CANVAS_WAVEVIEW, GnomeCanvasWaveViewClass))
40
41 typedef struct _GnomeCanvasWaveView            GnomeCanvasWaveView;
42 typedef struct _GnomeCanvasWaveViewClass       GnomeCanvasWaveViewClass;
43 typedef struct _GnomeCanvasWaveViewChannelInfo GnomeCanvasWaveViewChannelInfo;
44 typedef struct _GnomeCanvasWaveViewCacheEntry  GnomeCanvasWaveViewCacheEntry;
45 typedef struct _GnomeCanvasWaveViewCache       GnomeCanvasWaveViewCache;
46
47 /* XXX this needs to be synced with ardour/source.h PeakData */
48
49 struct _GnomeCanvasWaveViewCacheEntry
50 {
51     float  min;
52     float  max;
53 };
54
55 struct _GnomeCanvasWaveViewCache
56 {
57     GnomeCanvasWaveViewCacheEntry* data;
58     gint32                       allocated;
59     gint32                       data_size;
60     gulong                       start;
61     gulong                       end;
62 };    
63
64 GnomeCanvasWaveViewCache* gnome_canvas_waveview_cache_new ();
65 void                    gnome_canvas_waveview_cache_destroy (GnomeCanvasWaveViewCache*);
66
67 struct _GnomeCanvasWaveView
68 {
69     GnomeCanvasItem item;
70     
71     GnomeCanvasWaveViewCache *cache;
72     gboolean                cache_updater;
73     gint                    screen_width;
74
75     void *data_src;
76     guint32 channel;
77         void (*peak_function)(void*,gulong,gulong,gulong,gpointer,guint32,double);
78     gulong (*length_function)(void *);
79     gulong (*sourcefile_length_function)(void*,double);
80     void (*gain_curve_function)(void *arg, double start, double end, float* vector, guint32 veclen);
81     void *gain_src;
82
83     /** x-axis: samples per canvas unit. */
84     double samples_per_unit;
85     
86     /** y-axis: amplitude_above_axis.
87      * 
88      * the default is that an (scaled, normalized -1.0 ... +1.0) amplitude of 1.0
89      * corresponds to the top of the area assigned to the waveview.
90      *
91      * larger values will expand the vertical scale, cutting off the peaks/troughs.
92      * smaller values will decrease the vertical scale, moving peaks/troughs toward
93      * the middle of the area assigned to the waveview.
94      */
95     double amplitude_above_axis;
96
97     double x;
98     double y;
99     double height;
100     double half_height;
101     uint32_t wave_color;
102     uint32_t clip_color;
103     uint32_t zero_color;
104
105     char rectified;
106     char logscaled; 
107         
108     /* These are updated by the update() routine
109        to optimize the render() routine, which may
110        be called several times after a single update().
111     */
112
113     int32_t bbox_ulx;
114     int32_t bbox_uly;
115     int32_t bbox_lrx;
116     int32_t bbox_lry;
117     unsigned char wave_r, wave_g, wave_b, wave_a;
118     unsigned char clip_r, clip_g, clip_b, clip_a;
119     uint32_t samples;
120     uint32_t region_start;
121     int32_t reload_cache_in_render;
122 };
123
124 struct _GnomeCanvasWaveViewClass {
125         GnomeCanvasItemClass parent_class;
126 };
127
128 GType gnome_canvas_waveview_get_type (void) G_GNUC_CONST;
129
130 G_END_DECLS
131
132 #endif /* __GNOME_CANVAS_WAVEVIEW_H__ */