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