Ardour  8.12
crossfade_edit.h
Go to the documentation of this file.
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 
58 {
59 public:
60  CrossfadeEditor (ARDOUR::Session*, std::shared_ptr<ARDOUR::Crossfade>, double miny, double maxy);
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 
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 
91 
92 protected:
95 
96 private:
97  std::shared_ptr<ARDOUR::Crossfade> xfade;
98 
100 
101  struct Point {
103 
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 {
116  return a->x < b->x;
117  }
118  };
119 
122 
123  struct Half {
126  std::list<Point*> points;
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];
141 
143  std::vector<Gtk::Button*> fade_out_buttons;
144  std::vector<Gtk::Button*> fade_in_buttons;
145 
147 
150 
156 
159 
161 
163 
167 
169  void add_control_point (double x, double y);
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 
184 
185  void build_presets ();
187 
192 
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 
202 
203  void make_waves (std::shared_ptr<ARDOUR::AudioRegion>, WhichFade);
204  void peaks_ready (std::weak_ptr<ARDOUR::AudioRegion> r, WhichFade);
205 
206  void _apply_to (std::shared_ptr<ARDOUR::Crossfade> xf);
207  void setup (std::shared_ptr<ARDOUR::Crossfade>);
210 
211  enum Audition {
214  Right
215  };
216 
222 
224  void audition_both ();
226  void audition_left ();
228  void audition_right ();
229 
231 
232  void dump ();
233 };
234 
235 #endif /* __gtk_ardour_xfade_edit_h__ */
Declaration of the main canvas classes.
static Presets * fade_out_presets
void setup(std::shared_ptr< ARDOUR::Crossfade >)
void audition_left_dry_toggled()
bool on_key_press_event(GdkEventKey *)
This is a default handler for the signal signal_key_press_event().
Gtk::ToggleButton audition_both_button
void peaks_ready(std::weak_ptr< ARDOUR::AudioRegion > r, WhichFade)
gint event_handler(GdkEvent *)
Gtk::Table fade_out_table
Gtk::Button * ok_button
std::vector< Gtk::Button * > fade_out_buttons
Gtk::Button clear_button
PBD::ScopedConnection * _peaks_ready_connection
void audition_right()
bool canvas_event(GdkEvent *event)
void audition_right_toggled()
bool point_event(GdkEvent *event, Point *)
Gtk::ToggleButton preroll_button
void cancel_audition()
void audition_right_dry_toggled()
Gtk::VBox vpacker
PBD::ScopedConnection state_connection
void set(const ARDOUR::AutomationList &alist, WhichFade)
Gtk::HBox audition_box
void add_control_point(double x, double y)
void audition(Audition)
Gtk::ToggleButton audition_left_button
Gtk::ToggleButton audition_left_dry_button
Gtk::ToggleButton audition_right_dry_button
bool on_key_release_event(GdkEventKey *)
This is a default handler for the signal signal_key_release_event().
double y_coordinate(double &yfract) const
bool curve_event(GdkEvent *event)
void audition_state_changed(bool)
Gtk::Button revert_button
void canvas_allocation(Gtk::Allocation &)
std::shared_ptr< ARDOUR::Crossfade > xfade
double effective_height() const
Gtk::ToggleButton postroll_button
static Presets * fade_in_presets
double x_coordinate(double &xfract) const
void apply_preset(Preset *)
Gtk::RadioButton select_out_button
Gtk::HBox curve_button_box
Gtk::HBox roll_box
Gtk::VBox vpacker2
static const double canvas_border
void audition_toggled()
void make_waves(std::shared_ptr< ARDOUR::AudioRegion >, WhichFade)
void audition_left_dry()
std::vector< Gtk::Button * > fade_in_buttons
void _apply_to(std::shared_ptr< ARDOUR::Crossfade > xf)
void curve_select_clicked(WhichFade)
void audition_left_toggled()
void build_presets()
void audition_both()
Gtk::Table fade_in_table
Gtk::RadioButton select_in_button
CrossfadeEditor(ARDOUR::Session *, std::shared_ptr< ARDOUR::Crossfade >, double miny, double maxy)
ArdourCanvas::Rectangle * toplevel
void audition_right_dry()
double effective_width() const
void xfade_changed(const PBD::PropertyChange &)
void audition_left()
Point * make_point()
std::list< Preset * > Presets
Gtk::Button * cancel_button
ArdourCanvas::GtkCanvas * canvas
Gtk::ToggleButton audition_right_button
int get_width() const
int get_height() const
Allocation get_allocation() const
bool event(GdkEvent *event)
DebugBits WaveView
ArdourCanvas::Polygon * shading
std::vector< ArdourWaveView::WaveView * > waves
ARDOUR::AutomationList gain_curve
ArdourCanvas::PolyLine * line
ARDOUR::AutomationList normative_curve
std::list< Point * > points
bool operator()(const CrossfadeEditor::Point *a, const CrossfadeEditor::Point *b)
ArdourCanvas::PolyLine * curve
ArdourCanvas::Rectangle * box
void move_to(double x, double y, double xfract, double yfract)
static const int32_t size
PresetPoint(double a, double b)
Preset(const char *n, const char *x)