Merge branch 'cairocanvas' into windows+cc
[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 #ifdef interface
23 #undef interface
24 #endif
25
26 #include <vector>
27
28 #include <sigc++/signal.h>
29 #include "ardour/audioregion.h"
30
31 #include "canvas/fwd.h"
32 #include "canvas/wave_view.h"
33
34 #include "region_view.h"
35 #include "time_axis_view_item.h"
36 #include "automation_line.h"
37 #include "enums.h"
38
39 namespace ARDOUR {
40         class AudioRegion;
41         struct PeakData;
42 };
43
44 class AudioTimeAxisView;
45 class AudioRegionGainLine;
46 class GhostRegion;
47 class AutomationTimeAxisView;
48 class RouteTimeAxisView;
49
50 class AudioRegionView : public RegionView
51 {
52   public:
53         AudioRegionView (ArdourCanvas::Group *,
54                          RouteTimeAxisView&,
55                          boost::shared_ptr<ARDOUR::AudioRegion>,
56                          double initial_samples_per_pixel,
57                          Gdk::Color const & basic_color);
58
59         AudioRegionView (ArdourCanvas::Group *,
60                          RouteTimeAxisView&,
61                          boost::shared_ptr<ARDOUR::AudioRegion>,
62                          double samples_per_pixel,
63                          Gdk::Color const & basic_color,
64                          bool recording,
65                          TimeAxisViewItem::Visibility);
66
67         AudioRegionView (const AudioRegionView& other, boost::shared_ptr<ARDOUR::AudioRegion>);
68
69         ~AudioRegionView ();
70
71         virtual void init (Gdk::Color const & base_color, bool wait_for_data);
72
73         boost::shared_ptr<ARDOUR::AudioRegion> audio_region() const;
74
75         void create_waves ();
76
77         void set_height (double);
78         void set_samples_per_pixel (double);
79
80         void set_amplitude_above_axis (gdouble spp);
81
82         void temporarily_hide_envelope (); ///< Dangerous!
83         void unhide_envelope ();           ///< Dangerous!
84
85         void update_envelope_visibility ();
86
87         void add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event);
88         void remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event);
89
90         boost::shared_ptr<AudioRegionGainLine> get_gain_line() const { return gain_line; }
91
92         void region_changed (const PBD::PropertyChange&);
93         void envelope_active_changed ();
94
95         GhostRegion* add_ghost (TimeAxisView&);
96
97         void reset_fade_in_shape_width (boost::shared_ptr<ARDOUR::AudioRegion> ar, framecnt_t);
98         void reset_fade_out_shape_width (boost::shared_ptr<ARDOUR::AudioRegion> ar, framecnt_t);
99
100         framepos_t get_fade_in_shape_width ();
101         framepos_t get_fade_out_shape_width ();
102
103         void set_fade_visibility (bool);
104         void update_coverage_frames (LayerDisplay);
105
106         void update_transient(float old_pos, float new_pos);
107         void remove_transient(float pos);
108
109         void show_region_editor ();
110
111         virtual void entered (bool);
112         virtual void exited ();
113
114         void thaw_after_trim ();
115
116         void drag_start ();
117         void drag_end ();
118
119         void redraw_start_xfade_to (boost::shared_ptr<ARDOUR::AudioRegion>, framecnt_t, ArdourCanvas::Points&, double);
120         void redraw_end_xfade_to (boost::shared_ptr<ARDOUR::AudioRegion>, framecnt_t, ArdourCanvas::Points&, double);
121         void redraw_start_xfade ();
122         void redraw_end_xfade ();
123         
124         void hide_xfades ();
125         void hide_start_xfade ();
126         void hide_end_xfade ();
127         void show_xfades ();
128         void show_start_xfade ();
129         void show_end_xfade ();
130
131         bool start_xfade_visible () const {
132                 return _start_xfade_visible;
133         }
134
135         bool end_xfade_visible () const {
136                 return _end_xfade_visible;
137         }
138
139   protected:
140
141         /* this constructor allows derived types
142            to specify their visibility requirements
143            to the TimeAxisViewItem parent class
144         */
145
146         enum Flags {
147                 WaveformVisible = 0x4,
148                 WaveformRectified = 0x8,
149                 WaveformLogScaled = 0x10,
150         };
151
152         std::vector<ArdourCanvas::WaveView *> waves;
153         std::vector<ArdourCanvas::WaveView *> tmp_waves; ///< see ::create_waves()
154
155         std::list<std::pair<framepos_t, ArdourCanvas::Line*> > feature_lines;
156
157         ArdourCanvas::Polygon*           sync_mark; ///< polgyon for sync position
158         ArdourCanvas::Polygon*           fade_in_shape;
159         ArdourCanvas::Polygon*           fade_out_shape;
160         ArdourCanvas::Rectangle*        fade_in_handle; ///< fade in handle, or 0
161         ArdourCanvas::Rectangle*        fade_out_handle; ///< fade out handle, or 0
162
163         ArdourCanvas::PolyLine *start_xfade_in;
164         ArdourCanvas::PolyLine *start_xfade_out;
165         ArdourCanvas::Rectangle* start_xfade_rect;
166         bool _start_xfade_visible;
167
168         ArdourCanvas::PolyLine *end_xfade_in;
169         ArdourCanvas::PolyLine *end_xfade_out;
170         ArdourCanvas::Rectangle* end_xfade_rect;
171         bool _end_xfade_visible;
172
173         boost::shared_ptr<AudioRegionGainLine> gain_line;
174
175         double _amplitude_above_axis;
176
177         uint32_t fade_color;
178
179         void reset_fade_shapes ();
180         void reset_fade_in_shape ();
181         void reset_fade_out_shape ();
182         void fade_in_changed ();
183         void fade_out_changed ();
184         void fade_in_active_changed ();
185         void fade_out_active_changed ();
186
187         void region_resized (const PBD::PropertyChange&);
188         void region_muted ();
189         void region_scale_amplitude_changed ();
190         void region_renamed ();
191
192         void create_one_wave (uint32_t, bool);
193         void peaks_ready_handler (uint32_t);
194
195         void set_colors ();
196         void set_waveform_colors ();
197         void set_one_waveform_color (ArdourCanvas::WaveView*);
198         void compute_colors (Gdk::Color const &);
199         void reset_width_dependent_items (double pixel_width);
200         void set_frame_color ();
201
202         void color_handler ();
203
204         void transients_changed();
205
206         AutomationLine::VisibleAspects automation_line_visibility () const;
207
208 private:
209         void setup_fade_handle_positions ();
210
211         void parameter_changed (std::string const &);
212         void setup_waveform_visibility ();
213         void setup_waveform_shape ();
214         void setup_waveform_scale ();
215         void setup_waveform_clipping ();
216
217         /** A ScopedConnection for each PeaksReady callback (one per channel).  Each member
218          *  may be 0 if no connection exists.
219          */
220         std::vector<PBD::ScopedConnection*> _data_ready_connections;
221
222         /** RegionViews that we hid the xfades for at the start of the current drag;
223          *  first list is for start xfades, second list is for end xfades.
224          */
225         std::pair<std::list<AudioRegionView*>, std::list<AudioRegionView*> > _hidden_xfades;
226 };
227
228 #endif /* __gtk_ardour_audio_region_view_h__ */