Fix up state save/load of location lock/glue settings.
[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         class 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);
65         AudioRegionView (const AudioRegionView& other, boost::shared_ptr<ARDOUR::AudioRegion>);
66
67         ~AudioRegionView ();
68
69         virtual void init (Gdk::Color const & base_color, bool wait_for_data);
70
71         boost::shared_ptr<ARDOUR::AudioRegion> audio_region() const;
72
73         void create_waves ();
74
75         void set_height (double);
76         void set_samples_per_unit (double);
77
78         void set_amplitude_above_axis (gdouble spp);
79
80         void temporarily_hide_envelope (); ///< Dangerous!
81         void unhide_envelope ();           ///< Dangerous!
82
83         void set_envelope_visible (bool);
84         void set_waveform_visible (bool yn);
85         void set_waveform_shape (ARDOUR::WaveformShape);
86         void set_waveform_scale (ARDOUR::WaveformScale);
87
88         bool waveform_rectified() const { return _flags & WaveformRectified; }
89         bool waveform_logscaled() const { return _flags & WaveformLogScaled; }
90         bool waveform_visible()   const { return _flags & WaveformVisible; }
91         bool envelope_visible()   const { return _flags & EnvelopeVisible; }
92
93         void add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event);
94         void remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event);
95
96         AudioRegionGainLine* get_gain_line() const { return gain_line; }
97
98         void region_changed (const PBD::PropertyChange&);
99         void envelope_active_changed ();
100
101         GhostRegion* add_ghost (TimeAxisView&);
102
103         void reset_fade_in_shape_width (nframes_t);
104         void reset_fade_out_shape_width (nframes_t);
105
106         void set_fade_visibility (bool);
107         void update_coverage_frames (LayerDisplay);
108         
109         void update_transient(float old_pos, float new_pos);
110         void remove_transient(float pos);
111
112         void show_region_editor ();
113
114         virtual void entered (bool);
115         virtual void exited ();
116
117   protected:
118
119     /* this constructor allows derived types
120        to specify their visibility requirements
121        to the TimeAxisViewItem parent class
122     */
123
124     enum Flags {
125             EnvelopeVisible = 0x1,
126             WaveformVisible = 0x4,
127             WaveformRectified = 0x8,
128             WaveformLogScaled = 0x10,
129     };
130
131     std::vector<ArdourCanvas::WaveView *> waves;
132     std::vector<ArdourCanvas::WaveView *> tmp_waves; ///< see ::create_waves()
133     
134     std::list<std::pair<nframes64_t, ArdourCanvas::SimpleLine*> > feature_lines;
135     
136     ArdourCanvas::Polygon*           sync_mark; ///< polgyon for sync position
137     ArdourCanvas::SimpleLine*        zero_line;
138     ArdourCanvas::Polygon*           fade_in_shape;
139     ArdourCanvas::Polygon*           fade_out_shape;
140     ArdourCanvas::SimpleRect*        fade_in_handle; ///< fade in handle, or 0
141     ArdourCanvas::SimpleRect*        fade_out_handle; ///< fade out handle, or 0
142
143     AudioRegionGainLine * gain_line;
144
145     double _amplitude_above_axis;
146
147     uint32_t _flags;
148     uint32_t fade_color;
149
150     void reset_fade_shapes ();
151     void reset_fade_in_shape ();
152     void reset_fade_out_shape ();
153     void fade_in_changed ();
154     void fade_out_changed ();
155     void fade_in_active_changed ();
156     void fade_out_active_changed ();
157
158     void region_resized (const PBD::PropertyChange&);
159     void region_muted ();
160     void region_scale_amplitude_changed ();
161         void region_renamed ();
162
163     void create_one_wave (uint32_t, bool);
164     void manage_zero_line ();
165     void peaks_ready_handler (uint32_t);
166     void set_flags (XMLNode *);
167     void store_flags ();
168
169     void set_colors ();
170     void compute_colors (Gdk::Color const &);
171     void reset_width_dependent_items (double pixel_width);
172     void set_waveview_data_src();
173     void set_frame_color ();
174
175     void color_handler ();
176
177     std::vector<GnomeCanvasWaveViewCache*> wave_caches;
178     
179     void transients_changed();
180
181   private:
182
183     void setup_fade_handle_positions ();
184
185         /** A ScopedConnection for each PeaksReady callback (one per channel).  Each member
186          *  may be 0 if no connection exists.
187          */
188         std::vector<PBD::ScopedConnection*> _data_ready_connections;
189 };
190
191 #endif /* __gtk_ardour_audio_region_view_h__ */