Fix DSP load sorting with inactive plugins
[ardour.git] / gtk2_ardour / crossfade_edit.h
1 /*
2  * Copyright (C) 2005-2013 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
4  * Copyright (C) 2006 Doug McLain <doug@nostar.net>
5  * Copyright (C) 2007-2009 David Robillard <d@drobilla.net>
6  * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
7  * Copyright (C) 2017 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_xfade_edit_h__
25 #define __gtk_ardour_xfade_edit_h__
26
27 #include <list>
28
29 #include <gtkmm/box.h>
30 #include <gtkmm/button.h>
31 #include <gtkmm/radiobutton.h>
32
33 #include "canvas/canvas.h"
34
35 #include "evoral/Curve.h"
36 #include "ardour/session_handle.h"
37
38 #include "ardour_dialog.h"
39
40 namespace ARDOUR
41 {
42         class Session;
43         class AutomationList;
44         class Crossfade;
45 }
46
47 namespace ArdourCanvas {
48         class Rectangle;
49         class Line;
50         class Polygon;
51 }
52
53 namespace ArdourWaveview {
54         class WaveView;
55 }
56
57 class CrossfadeEditor : public ArdourDialog
58 {
59 public:
60         CrossfadeEditor (ARDOUR::Session*, boost::shared_ptr<ARDOUR::Crossfade>, double miny, double maxy);
61         ~CrossfadeEditor ();
62
63         void apply ();
64
65         static const double canvas_border;
66
67         /* these are public so that a caller/subclass can make them do the right thing. */
68
69         Gtk::Button* cancel_button;
70         Gtk::Button* ok_button;
71
72         struct PresetPoint {
73                 double x;
74                 double y;
75
76                 PresetPoint (double a, double b)
77                         : x (a), y (b) {}
78         };
79
80         struct Preset : public std::list<PresetPoint> {
81                 const char* name;
82                 const char* image_name;
83
84                 Preset (const char* n, const char* x) : name (n), image_name (x) {}
85         };
86
87         typedef std::list<Preset*> Presets;
88
89         static Presets* fade_in_presets;
90         static Presets* fade_out_presets;
91
92 protected:
93         bool on_key_press_event (GdkEventKey*);
94         bool on_key_release_event (GdkEventKey*);
95
96 private:
97         boost::shared_ptr<ARDOUR::Crossfade> xfade;
98
99         Gtk::VBox vpacker;
100
101         struct Point {
102                 ~Point();
103
104                 ArdourCanvas::Rectangle* box;
105                 ArdourCanvas::PolyLine* curve;
106                 double x;
107                 double y;
108
109                 static const int32_t size;
110
111                 void move_to (double x, double y, double xfract, double yfract);
112         };
113
114         struct PointSorter {
115                 bool operator() (const CrossfadeEditor::Point* a, const CrossfadeEditor::Point *b) {
116                         return a->x < b->x;
117                 }
118         };
119
120         ArdourCanvas::Rectangle*   toplevel;
121         ArdourCanvas::GtkCanvas* canvas;
122
123         struct Half {
124                 ArdourCanvas::PolyLine* line;
125                 ArdourCanvas::Polygon*  shading;
126                 std::list<Point*>       points;
127                 ARDOUR::AutomationList  normative_curve; /* 0 - 1.0, linear */
128                 ARDOUR::AutomationList  gain_curve;      /* 0 - 2.0, gain mapping */
129                 std::vector<ArdourWaveView::WaveView*>  waves;
130
131                 Half();
132         };
133
134         enum WhichFade {
135                 In = 0,
136                 Out = 1
137         };
138
139         Half fade[2];
140         WhichFade current;
141
142         bool point_grabbed;
143         std::vector<Gtk::Button*> fade_out_buttons;
144         std::vector<Gtk::Button*> fade_in_buttons;
145
146         Gtk::VBox vpacker2;
147
148         Gtk::Button clear_button;
149         Gtk::Button revert_button;
150
151         Gtk::ToggleButton audition_both_button;
152         Gtk::ToggleButton audition_left_dry_button;
153         Gtk::ToggleButton audition_left_button;
154         Gtk::ToggleButton audition_right_dry_button;
155         Gtk::ToggleButton audition_right_button;
156
157         Gtk::ToggleButton preroll_button;
158         Gtk::ToggleButton postroll_button;
159
160         Gtk::HBox roll_box;
161
162         gint event_handler (GdkEvent*);
163
164         bool canvas_event (GdkEvent* event);
165         bool point_event (GdkEvent* event, Point*);
166         bool curve_event (GdkEvent* event);
167
168         void canvas_allocation (Gtk::Allocation&);
169         void add_control_point (double x, double y);
170         Point* make_point ();
171         void redraw ();
172
173         double effective_width () const { return canvas->get_allocation().get_width() - (2.0 * canvas_border); }
174         double effective_height () const { return canvas->get_allocation().get_height() - (2.0 * canvas_border); }
175
176         void clear ();
177         void reset ();
178
179         double miny;
180         double maxy;
181
182         Gtk::Table fade_in_table;
183         Gtk::Table fade_out_table;
184
185         void build_presets ();
186         void apply_preset (Preset*);
187
188         Gtk::RadioButton select_in_button;
189         Gtk::RadioButton select_out_button;
190         Gtk::HBox   curve_button_box;
191         Gtk::HBox   audition_box;
192
193         void curve_select_clicked (WhichFade);
194
195         double x_coordinate (double& xfract) const;
196         double y_coordinate (double& yfract) const;
197
198         void set (const ARDOUR::AutomationList& alist, WhichFade);
199
200         PBD::ScopedConnection* _peaks_ready_connection;
201         PBD::ScopedConnection state_connection;
202
203         void make_waves (boost::shared_ptr<ARDOUR::AudioRegion>, WhichFade);
204         void peaks_ready (boost::weak_ptr<ARDOUR::AudioRegion> r, WhichFade);
205
206         void _apply_to (boost::shared_ptr<ARDOUR::Crossfade> xf);
207         void setup (boost::shared_ptr<ARDOUR::Crossfade>);
208         void cancel_audition ();
209         void audition_state_changed (bool);
210
211         enum Audition {
212                 Both,
213                 Left,
214                 Right
215         };
216
217         void audition_toggled ();
218         void audition_right_toggled ();
219         void audition_right_dry_toggled ();
220         void audition_left_toggled ();
221         void audition_left_dry_toggled ();
222
223         void audition (Audition);
224         void audition_both ();
225         void audition_left_dry ();
226         void audition_left ();
227         void audition_right_dry ();
228         void audition_right ();
229
230         void xfade_changed (const PBD::PropertyChange&);
231
232         void dump ();
233 };
234
235 #endif /* __gtk_ardour_xfade_edit_h__ */