Fix crash when X11 is not available for VST UIs
[ardour.git] / gtk2_ardour / audio_region_view.h
1 /*
2  * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
3  * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2007 Doug McLain <doug@nostar.net>
5  * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
6  * Copyright (C) 2012 Ben Loftis <ben@harrisonconsoles.com>
7  * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #ifndef __gtk_ardour_audio_region_view_h__
25 #define __gtk_ardour_audio_region_view_h__
26
27 #ifdef interface
28 #undef interface
29 #endif
30
31 #include <vector>
32
33 #include <sigc++/signal.h>
34 #include "ardour/audioregion.h"
35
36 #include "canvas/fwd.h"
37 #include "canvas/xfade_curve.h"
38
39 #include "waveview/wave_view.h"
40
41 #include "region_view.h"
42 #include "time_axis_view_item.h"
43 #include "automation_line.h"
44 #include "enums.h"
45
46 namespace ARDOUR {
47         class AudioRegion;
48         struct PeakData;
49 };
50
51 class AudioTimeAxisView;
52 class AudioRegionGainLine;
53 class GhostRegion;
54 class AutomationTimeAxisView;
55 class RouteTimeAxisView;
56
57 class AudioRegionView : public RegionView
58 {
59 public:
60         AudioRegionView (ArdourCanvas::Container *,
61                          RouteTimeAxisView&,
62                          boost::shared_ptr<ARDOUR::AudioRegion>,
63                          double initial_samples_per_pixel,
64                          uint32_t base_color);
65
66         AudioRegionView (ArdourCanvas::Container *,
67                          RouteTimeAxisView&,
68                          boost::shared_ptr<ARDOUR::AudioRegion>,
69                          double samples_per_pixel,
70                          uint32_t base_color,
71                          bool recording,
72                          TimeAxisViewItem::Visibility);
73
74         AudioRegionView (const AudioRegionView& other, boost::shared_ptr<ARDOUR::AudioRegion>);
75
76         ~AudioRegionView ();
77
78         void init (bool wait_for_data);
79
80         boost::shared_ptr<ARDOUR::AudioRegion> audio_region() const;
81
82         void create_waves ();
83         void delete_waves ();
84
85         void set_height (double);
86         void set_samples_per_pixel (double);
87
88         void set_amplitude_above_axis (gdouble spp);
89
90         void temporarily_hide_envelope (); ///< Dangerous!
91         void unhide_envelope ();           ///< Dangerous!
92
93         void update_envelope_visibility ();
94
95         void add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event, bool with_guard_points);
96         void remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event);
97
98         boost::shared_ptr<AudioRegionGainLine> get_gain_line() const { return gain_line; }
99
100         void region_changed (const PBD::PropertyChange&);
101         void envelope_active_changed ();
102
103         GhostRegion* add_ghost (TimeAxisView&);
104
105         void reset_fade_in_shape_width (boost::shared_ptr<ARDOUR::AudioRegion> ar, samplecnt_t, bool drag_active = false);
106         void reset_fade_out_shape_width (boost::shared_ptr<ARDOUR::AudioRegion> ar, samplecnt_t, bool drag_active = false);
107
108         samplepos_t get_fade_in_shape_width ();
109         samplepos_t get_fade_out_shape_width ();
110
111         void set_fade_visibility (bool);
112         void update_coverage_frame (LayerDisplay);
113
114         void update_transient(float old_pos, float new_pos);
115         void remove_transient(float pos);
116
117         void show_region_editor ();
118
119         virtual void entered ();
120         virtual void exited ();
121
122         void thaw_after_trim ();
123
124         void drag_start ();
125         void drag_end ();
126
127         void redraw_start_xfade_to (boost::shared_ptr<ARDOUR::AudioRegion>, samplecnt_t, ArdourCanvas::Points&, double, double);
128         void redraw_end_xfade_to (boost::shared_ptr<ARDOUR::AudioRegion>, samplecnt_t, ArdourCanvas::Points&, double, double, double);
129         void redraw_start_xfade ();
130         void redraw_end_xfade ();
131
132         void hide_xfades ();
133         void hide_start_xfade ();
134         void hide_end_xfade ();
135         void show_xfades ();
136         void show_start_xfade ();
137         void show_end_xfade ();
138
139         bool start_xfade_visible () const {
140                 return _start_xfade_visible;
141         }
142
143         bool end_xfade_visible () const {
144                 return _end_xfade_visible;
145         }
146
147 protected:
148
149         /* this constructor allows derived types
150          * to specify their visibility requirements
151          * to the TimeAxisViewItem parent class
152          */
153
154         enum Flags {
155                 WaveformVisible = 0x4,
156                 WaveformRectified = 0x8,
157                 WaveformLogScaled = 0x10,
158         };
159
160         std::vector<ArdourWaveView::WaveView *> waves;
161         std::vector<ArdourWaveView::WaveView *> tmp_waves; ///< see \ref create_waves()
162
163         std::list<std::pair<samplepos_t, ArdourCanvas::Line*> > feature_lines;
164
165         ArdourCanvas::Polygon*          sync_mark; ///< polgyon for sync position
166         ArdourCanvas::Rectangle*        fade_in_handle; ///< fade in handle, or 0
167         ArdourCanvas::Rectangle*        fade_out_handle; ///< fade out handle, or 0
168         ArdourCanvas::Rectangle*        fade_in_trim_handle; ///< fade in trim handle, or 0
169         ArdourCanvas::Rectangle*        fade_out_trim_handle; ///< fade out trim handle, or 0
170         ArdourCanvas::Rectangle*        pending_peak_data;
171
172         static Cairo::RefPtr<Cairo::Pattern> pending_peak_pattern;
173
174         ArdourCanvas::XFadeCurve* start_xfade_curve;
175         ArdourCanvas::Rectangle*  start_xfade_rect;
176         bool _start_xfade_visible;
177
178         ArdourCanvas::XFadeCurve* end_xfade_curve;
179         ArdourCanvas::Rectangle*  end_xfade_rect;
180         bool _end_xfade_visible;
181
182         boost::shared_ptr<AudioRegionGainLine> gain_line;
183
184         double _amplitude_above_axis;
185
186         void reset_fade_shapes ();
187         void reset_fade_in_shape ();
188         void reset_fade_out_shape ();
189         void fade_in_changed ();
190         void fade_out_changed ();
191         void fade_in_active_changed ();
192         void fade_out_active_changed ();
193
194         void region_resized (const PBD::PropertyChange&);
195         void region_muted ();
196         void region_scale_amplitude_changed ();
197         void region_renamed ();
198
199         void create_one_wave (uint32_t, bool);
200         void peaks_ready_handler (uint32_t);
201
202         void set_colors ();
203         void set_waveform_colors ();
204         void reset_width_dependent_items (double pixel_width);
205         void set_frame_color ();
206
207         void color_handler ();
208
209         void transients_changed();
210
211         AutomationLine::VisibleAspects automation_line_visibility () const;
212
213 private:
214         void setup_fade_handle_positions ();
215
216         void parameter_changed (std::string const &);
217         void setup_waveform_visibility ();
218         void set_some_waveform_colors (std::vector<ArdourWaveView::WaveView*>& waves_to_color);
219
220         /** A ScopedConnection for each PeaksReady callback (one per channel).  Each member
221          *  may be 0 if no connection exists.
222          */
223         std::vector<PBD::ScopedConnection*> _data_ready_connections;
224
225         /** RegionViews that we hid the xfades for at the start of the current drag;
226          *  first list is for start xfades, second list is for end xfades.
227          */
228         std::pair<std::list<AudioRegionView*>, std::list<AudioRegionView*> > _hidden_xfades;
229
230         bool trim_fade_in_drag_active;
231         bool trim_fade_out_drag_active;
232 };
233
234 #endif /* __gtk_ardour_audio_region_view_h__ */