Heavy-duty abstraction work to split type-specific classes into
[ardour.git] / gtk2_ardour / audio_region_view.h
1 /*
2     Copyright (C) 2001-2006 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #ifndef __gtk_ardour_audio_region_view_h__
20 #define __gtk_ardour_audio_region_view_h__
21
22 #include <vector>
23
24 #include <libgnomecanvasmm.h>
25 #include <libgnomecanvasmm/polygon.h>
26 #include <sigc++/signal.h>
27 #include <ardour/region.h>
28
29 #include "region_view.h"
30 #include "route_time_axis.h"
31 #include "time_axis_view_item.h"
32 #include "automation_line.h"
33 #include "enums.h"
34 #include "waveview.h"
35 #include "canvas.h"
36 #include "color.h"
37
38 namespace ARDOUR {
39         class AudioRegion;
40         class PeakData;
41 };
42
43 class AudioTimeAxisView;
44 class AudioRegionGainLine;
45 class AudioRegionEditor;
46 class GhostRegion;
47 class AutomationTimeAxisView;
48
49 class AudioRegionView : public RegionView
50 {
51   public:
52         AudioRegionView (ArdourCanvas::Group *, 
53                          RouteTimeAxisView&,
54                          ARDOUR::AudioRegion&,
55                          double initial_samples_per_unit,
56                          Gdk::Color& basic_color);
57
58         ~AudioRegionView ();
59         
60         virtual void init (Gdk::Color& base_color, bool wait_for_data = false);
61         
62         ARDOUR::AudioRegion& audio_region() const;
63     
64     void set_height (double);
65     void set_samples_per_unit (double);
66
67     void set_amplitude_above_axis (gdouble spp);
68
69     void temporarily_hide_envelope (); ///< Dangerous!
70     void unhide_envelope ();           ///< Dangerous!
71
72     void set_envelope_visible (bool);
73     void set_waveform_visible (bool yn);
74     void set_waveform_shape (WaveformShape);
75
76     bool waveform_rectified() const { return _flags & WaveformRectified; }
77     bool waveform_visible()   const { return _flags & WaveformVisible; }
78     bool envelope_visible()   const { return _flags & EnvelopeVisible; }
79     
80     void show_region_editor ();
81
82     void add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event);
83     void remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event);
84
85     AudioRegionGainLine* get_gain_line() const { return gain_line; }
86
87     void region_changed (ARDOUR::Change);
88     void envelope_active_changed ();
89
90     GhostRegion* add_ghost (AutomationTimeAxisView&);
91
92     void reset_fade_in_shape_width (jack_nframes_t);
93     void reset_fade_out_shape_width (jack_nframes_t);
94     void set_fade_in_active (bool);
95     void set_fade_out_active (bool);
96
97     virtual void entered ();
98     virtual void exited ();
99
100   protected:
101
102     /* this constructor allows derived types
103        to specify their visibility requirements
104        to the TimeAxisViewItem parent class
105     */
106     
107     AudioRegionView (ArdourCanvas::Group *, 
108                              RouteTimeAxisView&,
109                              ARDOUR::AudioRegion&,
110                              double      samples_per_unit,
111                              Gdk::Color& basic_color,
112                              TimeAxisViewItem::Visibility);
113     
114     enum Flags {
115             EnvelopeVisible = 0x1,
116             WaveformVisible = 0x4,
117             WaveformRectified = 0x8
118     };
119     
120     void reset_fade_shapes ();
121     void reset_fade_in_shape ();
122     void reset_fade_out_shape ();
123     void fade_in_changed ();
124     void fade_out_changed ();
125     void fade_in_active_changed ();
126     void fade_out_active_changed ();
127
128     void region_resized (ARDOUR::Change);
129     void region_moved (void *);
130     void region_muted ();
131     void region_scale_amplitude_changed ();
132
133     void create_waves ();
134     void create_one_wave (uint32_t, bool);
135     void manage_zero_line ();
136     void peaks_ready_handler (uint32_t);
137     void set_flags (XMLNode *);
138     void store_flags ();
139
140     void set_colors ();
141     void compute_colors (Gdk::Color&);
142     void reset_width_dependent_items (double pixel_width);
143     void set_waveview_data_src();
144     
145         void color_handler (ColorID, uint32_t);
146
147     vector<GnomeCanvasWaveViewCache*> wave_caches;
148     vector<ArdourCanvas::WaveView *>  waves;
149     vector<ArdourCanvas::WaveView *>  tmp_waves; ///< see ::create_waves()
150     ArdourCanvas::Polygon*            sync_mark; ///< polgyon for sync position 
151     ArdourCanvas::SimpleLine*         zero_line;
152     ArdourCanvas::Polygon*            fade_in_shape;
153     ArdourCanvas::Polygon*            fade_out_shape;
154     ArdourCanvas::SimpleRect*         fade_in_handle;
155     ArdourCanvas::SimpleRect*         fade_out_handle;
156     AudioRegionGainLine*              gain_line;
157
158     double _amplitude_above_axis;
159
160     uint32_t _flags;
161     uint32_t fade_color;
162 };
163
164 #endif /* __gtk_ardour_audio_region_view_h__ */