use ActionManager namespace, rather than ActionMap objects, and remove all per-contex...
[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/xfade_curve.h"
33
34 #include "waveview/wave_view.h"
35
36 #include "region_view.h"
37 #include "time_axis_view_item.h"
38 #include "automation_line.h"
39 #include "enums.h"
40
41 namespace ARDOUR {
42         class AudioRegion;
43         struct PeakData;
44 };
45
46 class AudioTimeAxisView;
47 class AudioRegionGainLine;
48 class GhostRegion;
49 class AutomationTimeAxisView;
50 class RouteTimeAxisView;
51
52 class AudioRegionView : public RegionView
53 {
54 public:
55         AudioRegionView (ArdourCanvas::Container *,
56                          RouteTimeAxisView&,
57                          boost::shared_ptr<ARDOUR::AudioRegion>,
58                          double initial_samples_per_pixel,
59                          uint32_t base_color);
60
61         AudioRegionView (ArdourCanvas::Container *,
62                          RouteTimeAxisView&,
63                          boost::shared_ptr<ARDOUR::AudioRegion>,
64                          double samples_per_pixel,
65                          uint32_t base_color,
66                          bool recording,
67                          TimeAxisViewItem::Visibility);
68
69         AudioRegionView (const AudioRegionView& other, boost::shared_ptr<ARDOUR::AudioRegion>);
70
71         ~AudioRegionView ();
72
73         void init (bool wait_for_data);
74
75         boost::shared_ptr<ARDOUR::AudioRegion> audio_region() const;
76
77         void create_waves ();
78         void delete_waves ();
79
80         void set_height (double);
81         void set_samples_per_pixel (double);
82
83         void set_amplitude_above_axis (gdouble spp);
84
85         void temporarily_hide_envelope (); ///< Dangerous!
86         void unhide_envelope ();           ///< Dangerous!
87
88         void update_envelope_visibility ();
89
90         void add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event, bool with_guard_points);
91         void remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event);
92
93         boost::shared_ptr<AudioRegionGainLine> get_gain_line() const { return gain_line; }
94
95         void region_changed (const PBD::PropertyChange&);
96         void envelope_active_changed ();
97
98         GhostRegion* add_ghost (TimeAxisView&);
99
100         void reset_fade_in_shape_width (boost::shared_ptr<ARDOUR::AudioRegion> ar, samplecnt_t, bool drag_active = false);
101         void reset_fade_out_shape_width (boost::shared_ptr<ARDOUR::AudioRegion> ar, samplecnt_t, bool drag_active = false);
102
103         samplepos_t get_fade_in_shape_width ();
104         samplepos_t get_fade_out_shape_width ();
105
106         void set_fade_visibility (bool);
107         void update_coverage_samples (LayerDisplay);
108
109         void update_transient(float old_pos, float new_pos);
110         void remove_transient(float pos);
111
112         void show_region_editor ();
113
114         virtual void entered ();
115         virtual void exited ();
116
117         void thaw_after_trim ();
118
119         void drag_start ();
120         void drag_end ();
121
122         void redraw_start_xfade_to (boost::shared_ptr<ARDOUR::AudioRegion>, samplecnt_t, ArdourCanvas::Points&, double, double);
123         void redraw_end_xfade_to (boost::shared_ptr<ARDOUR::AudioRegion>, samplecnt_t, ArdourCanvas::Points&, double, double, double);
124         void redraw_start_xfade ();
125         void redraw_end_xfade ();
126
127         void hide_xfades ();
128         void hide_start_xfade ();
129         void hide_end_xfade ();
130         void show_xfades ();
131         void show_start_xfade ();
132         void show_end_xfade ();
133
134         bool start_xfade_visible () const {
135                 return _start_xfade_visible;
136         }
137
138         bool end_xfade_visible () const {
139                 return _end_xfade_visible;
140         }
141
142 protected:
143
144         /* this constructor allows derived types
145          * to specify their visibility requirements
146          * to the TimeAxisViewItem parent class
147          */
148
149         enum Flags {
150                 WaveformVisible = 0x4,
151                 WaveformRectified = 0x8,
152                 WaveformLogScaled = 0x10,
153         };
154
155         std::vector<ArdourWaveView::WaveView *> waves;
156         std::vector<ArdourWaveView::WaveView *> tmp_waves; ///< see ::create_waves()
157
158         std::list<std::pair<samplepos_t, ArdourCanvas::Line*> > feature_lines;
159
160         ArdourCanvas::Polygon*          sync_mark; ///< polgyon for sync position
161         ArdourCanvas::Rectangle*        fade_in_handle; ///< fade in handle, or 0
162         ArdourCanvas::Rectangle*        fade_out_handle; ///< fade out handle, or 0
163         ArdourCanvas::Rectangle*        fade_in_trim_handle; ///< fade in trim handle, or 0
164         ArdourCanvas::Rectangle*        fade_out_trim_handle; ///< fade out trim handle, or 0
165         ArdourCanvas::Rectangle*        pending_peak_data;
166
167         static Cairo::RefPtr<Cairo::Pattern> pending_peak_pattern;
168
169         ArdourCanvas::XFadeCurve* start_xfade_curve;
170         ArdourCanvas::Rectangle*  start_xfade_rect;
171         bool _start_xfade_visible;
172
173         ArdourCanvas::XFadeCurve* end_xfade_curve;
174         ArdourCanvas::Rectangle*  end_xfade_rect;
175         bool _end_xfade_visible;
176
177         boost::shared_ptr<AudioRegionGainLine> gain_line;
178
179         double _amplitude_above_axis;
180
181         void reset_fade_shapes ();
182         void reset_fade_in_shape ();
183         void reset_fade_out_shape ();
184         void fade_in_changed ();
185         void fade_out_changed ();
186         void fade_in_active_changed ();
187         void fade_out_active_changed ();
188
189         void region_resized (const PBD::PropertyChange&);
190         void region_muted ();
191         void region_scale_amplitude_changed ();
192         void region_renamed ();
193
194         void create_one_wave (uint32_t, bool);
195         void peaks_ready_handler (uint32_t);
196
197         void set_colors ();
198         void set_waveform_colors ();
199         void reset_width_dependent_items (double pixel_width);
200         void set_sample_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 set_some_waveform_colors (std::vector<ArdourWaveView::WaveView*>& waves_to_color);
214
215         /** A ScopedConnection for each PeaksReady callback (one per channel).  Each member
216          *  may be 0 if no connection exists.
217          */
218         std::vector<PBD::ScopedConnection*> _data_ready_connections;
219
220         /** RegionViews that we hid the xfades for at the start of the current drag;
221          *  first list is for start xfades, second list is for end xfades.
222          */
223         std::pair<std::list<AudioRegionView*>, std::list<AudioRegionView*> > _hidden_xfades;
224
225         bool trim_fade_in_drag_active;
226         bool trim_fade_out_drag_active;
227 };
228
229 #endif /* __gtk_ardour_audio_region_view_h__ */