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>
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.
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.
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.
24 #ifndef __gtk_ardour_xfade_edit_h__
25 #define __gtk_ardour_xfade_edit_h__
29 #include <gtkmm/box.h>
30 #include <gtkmm/button.h>
31 #include <gtkmm/radiobutton.h>
33 #include "canvas/canvas.h"
35 #include "evoral/Curve.h"
36 #include "ardour/session_handle.h"
38 #include "ardour_dialog.h"
47 namespace ArdourCanvas {
53 namespace ArdourWaveview {
57 class CrossfadeEditor : public ArdourDialog
60 CrossfadeEditor (ARDOUR::Session*, boost::shared_ptr<ARDOUR::Crossfade>, double miny, double maxy);
65 static const double canvas_border;
67 /* these are public so that a caller/subclass can make them do the right thing. */
69 Gtk::Button* cancel_button;
70 Gtk::Button* ok_button;
76 PresetPoint (double a, double b)
80 struct Preset : public std::list<PresetPoint> {
82 const char* image_name;
84 Preset (const char* n, const char* x) : name (n), image_name (x) {}
87 typedef std::list<Preset*> Presets;
89 static Presets* fade_in_presets;
90 static Presets* fade_out_presets;
93 bool on_key_press_event (GdkEventKey*);
94 bool on_key_release_event (GdkEventKey*);
97 boost::shared_ptr<ARDOUR::Crossfade> xfade;
104 ArdourCanvas::Rectangle* box;
105 ArdourCanvas::PolyLine* curve;
109 static const int32_t size;
111 void move_to (double x, double y, double xfract, double yfract);
115 bool operator() (const CrossfadeEditor::Point* a, const CrossfadeEditor::Point *b) {
120 ArdourCanvas::Rectangle* toplevel;
121 ArdourCanvas::GtkCanvas* canvas;
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;
143 std::vector<Gtk::Button*> fade_out_buttons;
144 std::vector<Gtk::Button*> fade_in_buttons;
148 Gtk::Button clear_button;
149 Gtk::Button revert_button;
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;
157 Gtk::ToggleButton preroll_button;
158 Gtk::ToggleButton postroll_button;
162 gint event_handler (GdkEvent*);
164 bool canvas_event (GdkEvent* event);
165 bool point_event (GdkEvent* event, Point*);
166 bool curve_event (GdkEvent* event);
168 void canvas_allocation (Gtk::Allocation&);
169 void add_control_point (double x, double y);
170 Point* make_point ();
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); }
182 Gtk::Table fade_in_table;
183 Gtk::Table fade_out_table;
185 void build_presets ();
186 void apply_preset (Preset*);
188 Gtk::RadioButton select_in_button;
189 Gtk::RadioButton select_out_button;
190 Gtk::HBox curve_button_box;
191 Gtk::HBox audition_box;
193 void curve_select_clicked (WhichFade);
195 double x_coordinate (double& xfract) const;
196 double y_coordinate (double& yfract) const;
198 void set (const ARDOUR::AutomationList& alist, WhichFade);
200 PBD::ScopedConnection* _peaks_ready_connection;
201 PBD::ScopedConnection state_connection;
203 void make_waves (boost::shared_ptr<ARDOUR::AudioRegion>, WhichFade);
204 void peaks_ready (boost::weak_ptr<ARDOUR::AudioRegion> r, WhichFade);
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);
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 ();
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 ();
230 void xfade_changed (const PBD::PropertyChange&);
235 #endif /* __gtk_ardour_xfade_edit_h__ */