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