Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
25 
26 #include <list>
27 
28 #include <gtkmm/box.h>
29 #include <gtkmm/button.h>
30 #include <gtkmm/radiobutton.h>
31 #include <gtkmm/table.h>
32 
33 #include "canvas/canvas.h"
34 #include "canvas/poly_line.h"
35 
36 #include "evoral/Curve.h"
37 #include "ardour/automation_list.h"
38 #include "ardour/session_handle.h"
39 
40 #include "waveview/wave_view.h"
41 
42 #include "ardour_dialog.h"
43 
44 namespace ARDOUR
45 {
46  class Session;
47  class AutomationList;
48  class Crossfade;
49 }
50 
51 namespace ArdourCanvas {
52  class Rectangle;
53  class Line;
54  class Polygon;
55 }
56 
57 namespace ArdourWaveview {
58  class WaveView;
59 }
60 
62 {
63 public:
64  CrossfadeEditor (ARDOUR::Session*, std::shared_ptr<ARDOUR::Crossfade>, double miny, double maxy);
66 
67  void apply ();
68 
69  static const double canvas_border;
70 
71  /* these are public so that a caller/subclass can make them do the right thing. */
72 
75 
76  struct PresetPoint {
77  double x;
78  double y;
79 
80  PresetPoint (double a, double b)
81  : x (a), y (b) {}
82  };
83 
84  struct Preset : public std::list<PresetPoint> {
85  const char* name;
86  const char* image_name;
87 
88  Preset (const char* n, const char* x) : name (n), image_name (x) {}
89  };
90 
91  typedef std::list<Preset*> Presets;
92 
95 
96 protected:
99 
100 private:
101  std::shared_ptr<ARDOUR::Crossfade> xfade;
102 
104 
105  struct Point {
107 
110  double x;
111  double y;
112 
113  static const int32_t size;
114 
115  void move_to (double x, double y, double xfract, double yfract);
116  };
117 
118  struct PointSorter {
120  return a->x < b->x;
121  }
122  };
123 
126 
127  struct Half {
130  std::list<Point*> points;
132  ARDOUR::AutomationList gain_curve; /* 0 - 2.0, gain mapping */
133  std::vector<ArdourWaveView::WaveView*> waves;
134 
135  Half();
136  };
137 
138  enum WhichFade {
139  In = 0,
140  Out = 1
141  };
142 
143  Half fade[2];
145 
147  std::vector<Gtk::Button*> fade_out_buttons;
148  std::vector<Gtk::Button*> fade_in_buttons;
149 
151 
154 
160 
163 
165 
167 
171 
173  void add_control_point (double x, double y);
175  void redraw ();
176 
177  double effective_width () const { return canvas->get_allocation().get_width() - (2.0 * canvas_border); }
178  double effective_height () const { return canvas->get_allocation().get_height() - (2.0 * canvas_border); }
179 
180  void clear ();
181  void reset ();
182 
183  double miny;
184  double maxy;
185 
188 
189  void build_presets ();
191 
196 
198 
199  double x_coordinate (double& xfract) const;
200  double y_coordinate (double& yfract) const;
201 
202  void set (const ARDOUR::AutomationList& alist, WhichFade);
203 
206 
207  void make_waves (std::shared_ptr<ARDOUR::AudioRegion>, WhichFade);
208  void peaks_ready (std::weak_ptr<ARDOUR::AudioRegion> r, WhichFade);
209 
210  void _apply_to (std::shared_ptr<ARDOUR::Crossfade> xf);
211  void setup (std::shared_ptr<ARDOUR::Crossfade>);
214 
215  enum Audition {
218  Right
219  };
220 
226 
228  void audition_both ();
230  void audition_left ();
232  void audition_right ();
233 
235 
236  void dump ();
237 };
238 
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()
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)