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