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