Merge with 2.0-ongoing R3071.
[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 "route_time_axis.h"
31 #include "time_axis_view_item.h"
32 #include "automation_line.h"
33 #include "enums.h"
34 #include "waveview.h"
35 #include "canvas.h"
36
37 namespace ARDOUR {
38         class AudioRegion;
39         class PeakData;
40 };
41
42 class AudioTimeAxisView;
43 class AudioRegionGainLine;
44 class AudioRegionEditor;
45 class GhostRegion;
46 class AutomationTimeAxisView;
47
48 class AudioRegionView : public RegionView
49 {
50   public:
51         AudioRegionView (ArdourCanvas::Group *, 
52                          RouteTimeAxisView&,
53                          boost::shared_ptr<ARDOUR::AudioRegion>,
54                          double initial_samples_per_unit,
55                          Gdk::Color& basic_color);
56
57         AudioRegionView (const AudioRegionView& other);
58
59         ~AudioRegionView ();
60         
61         virtual void init (Gdk::Color& base_color, bool wait_for_data);
62         
63         boost::shared_ptr<ARDOUR::AudioRegion> audio_region() const;
64         
65         void set_y_position_and_height (double, double);
66         void set_samples_per_unit (double);
67         
68         void set_amplitude_above_axis (gdouble spp);
69         
70         void temporarily_hide_envelope (); ///< Dangerous!
71         void unhide_envelope ();           ///< Dangerous!
72         
73         void set_envelope_visible (bool);
74         void set_waveform_visible (bool yn);
75         void set_waveform_shape (WaveformShape);
76         void set_waveform_scale (WaveformScale);
77         
78         bool waveform_rectified() const { return _flags & WaveformRectified; }
79         bool waveform_logscaled() const { return _flags & WaveformLogScaled; }
80         bool waveform_visible()   const { return _flags & WaveformVisible; }
81         bool envelope_visible()   const { return _flags & EnvelopeVisible; }
82         
83         void show_region_editor ();
84         
85         void add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event);
86         void remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event);
87         
88         AudioRegionGainLine* get_gain_line() const { return gain_line; }
89         
90         void region_changed (ARDOUR::Change);
91         void envelope_active_changed ();
92         
93         GhostRegion* add_ghost (TimeAxisView&);
94         
95         void reset_fade_in_shape_width (nframes_t);
96         void reset_fade_out_shape_width (nframes_t);
97
98         virtual void entered ();
99         virtual void exited ();
100         
101   protected:
102
103     /* this constructor allows derived types
104        to specify their visibility requirements
105        to the TimeAxisViewItem parent class
106     */
107     
108     AudioRegionView (ArdourCanvas::Group *, 
109                      RouteTimeAxisView&,
110                      boost::shared_ptr<ARDOUR::AudioRegion>,
111                      double      samples_per_unit,
112                      Gdk::Color& basic_color,
113                      TimeAxisViewItem::Visibility);
114     
115     enum Flags {
116             EnvelopeVisible = 0x1,
117             WaveformVisible = 0x4,
118             WaveformRectified = 0x8,
119             WaveformLogScaled = 0x10,
120     };
121
122     vector<ArdourCanvas::WaveView *> waves;
123     vector<ArdourCanvas::WaveView *> tmp_waves; ///< see ::create_waves()
124     ArdourCanvas::Polygon*           sync_mark; ///< polgyon for sync position 
125     ArdourCanvas::SimpleLine*        zero_line;
126     ArdourCanvas::Polygon*           fade_in_shape;
127     ArdourCanvas::Polygon*           fade_out_shape;
128     ArdourCanvas::SimpleRect*        fade_in_handle;
129     ArdourCanvas::SimpleRect*        fade_out_handle;
130     
131     AudioRegionGainLine * gain_line;
132
133     double _amplitude_above_axis;
134     double _y_position;
135     double _height;
136
137     uint32_t _flags;
138     uint32_t fade_color;
139     
140     void reset_fade_shapes ();
141     void reset_fade_in_shape ();
142     void reset_fade_out_shape ();
143     void fade_in_changed ();
144     void fade_out_changed ();
145     void fade_in_active_changed ();
146     void fade_out_active_changed ();
147
148     void region_resized (ARDOUR::Change);
149     void region_muted ();
150     void region_scale_amplitude_changed ();
151         void region_renamed ();
152
153     void create_waves ();
154     void create_one_wave (uint32_t, bool);
155     void manage_zero_line ();
156     void peaks_ready_handler (uint32_t);
157     void set_flags (XMLNode *);
158     void store_flags ();
159
160     void set_colors ();
161     void compute_colors (Gdk::Color&);
162     void reset_width_dependent_items (double pixel_width);
163     void set_waveview_data_src();
164     void set_frame_color ();
165
166     void color_handler ();
167
168     vector<GnomeCanvasWaveViewCache*> wave_caches;
169
170   private:
171
172     void setup_fade_handle_positions ();
173 };
174
175 #endif /* __gtk_ardour_audio_region_view_h__ */