summaryrefslogtreecommitdiff
path: root/gtk2_ardour/crossfade_edit.h
blob: 0c496660959545a24cf59d47ac60bc52bf12dab1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
 * Copyright (C) 2005-2013 Paul Davis <paul@linuxaudiosystems.com>
 * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
 * Copyright (C) 2006 Doug McLain <doug@nostar.net>
 * Copyright (C) 2007-2009 David Robillard <d@drobilla.net>
 * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef __gtk_ardour_xfade_edit_h__
#define __gtk_ardour_xfade_edit_h__

#include <list>

#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include <gtkmm/radiobutton.h>

#include "canvas/canvas.h"

#include "evoral/Curve.h"
#include "ardour/session_handle.h"

#include "ardour_dialog.h"

namespace ARDOUR
{
	class Session;
	class AutomationList;
	class Crossfade;
}

namespace ArdourCanvas {
	class Rectangle;
	class Line;
	class Polygon;
}

namespace ArdourWaveview {
	class WaveView;
}

class CrossfadeEditor : public ArdourDialog
{
public:
	CrossfadeEditor (ARDOUR::Session*, boost::shared_ptr<ARDOUR::Crossfade>, double miny, double maxy);
	~CrossfadeEditor ();

	void apply ();

	static const double canvas_border;

	/* these are public so that a caller/subclass can make them do the right thing. */

	Gtk::Button* cancel_button;
	Gtk::Button* ok_button;

	struct PresetPoint {
		double x;
		double y;

		PresetPoint (double a, double b)
			: x (a), y (b) {}
	};

	struct Preset : public std::list<PresetPoint> {
		const char* name;
		const char* image_name;

		Preset (const char* n, const char* x) : name (n), image_name (x) {}
	};

	typedef std::list<Preset*> Presets;

	static Presets* fade_in_presets;
	static Presets* fade_out_presets;

protected:
	bool on_key_press_event (GdkEventKey*);
	bool on_key_release_event (GdkEventKey*);

private:
	boost::shared_ptr<ARDOUR::Crossfade> xfade;

	Gtk::VBox vpacker;

	struct Point {
		~Point();

		ArdourCanvas::Rectangle* box;
		ArdourCanvas::PolyLine* curve;
		double x;
		double y;

		static const int32_t size;

		void move_to (double x, double y, double xfract, double yfract);
	};

	struct PointSorter {
		bool operator() (const CrossfadeEditor::Point* a, const CrossfadeEditor::Point *b) {
			return a->x < b->x;
		}
	};

	ArdourCanvas::Rectangle*   toplevel;
	ArdourCanvas::GtkCanvas* canvas;

	struct Half {
		ArdourCanvas::PolyLine* line;
		ArdourCanvas::Polygon*  shading;
		std::list<Point*>       points;
		ARDOUR::AutomationList  normative_curve; /* 0 - 1.0, linear */
		ARDOUR::AutomationList  gain_curve;      /* 0 - 2.0, gain mapping */
		std::vector<ArdourWaveView::WaveView*>  waves;

		Half();
	};

	enum WhichFade {
		In = 0,
		Out = 1
	};

	Half fade[2];
	WhichFade current;

	bool point_grabbed;
	std::vector<Gtk::Button*> fade_out_buttons;
	std::vector<Gtk::Button*> fade_in_buttons;

	Gtk::VBox vpacker2;

	Gtk::Button clear_button;
	Gtk::Button revert_button;

	Gtk::ToggleButton audition_both_button;
	Gtk::ToggleButton audition_left_dry_button;
	Gtk::ToggleButton audition_left_button;
	Gtk::ToggleButton audition_right_dry_button;
	Gtk::ToggleButton audition_right_button;

	Gtk::ToggleButton preroll_button;
	Gtk::ToggleButton postroll_button;

	Gtk::HBox roll_box;

	gint event_handler (GdkEvent*);

	bool canvas_event (GdkEvent* event);
	bool point_event (GdkEvent* event, Point*);
	bool curve_event (GdkEvent* event);

	void canvas_allocation (Gtk::Allocation&);
	void add_control_point (double x, double y);
	Point* make_point ();
	void redraw ();

	double effective_width () const { return canvas->get_allocation().get_width() - (2.0 * canvas_border); }
	double effective_height () const { return canvas->get_allocation().get_height() - (2.0 * canvas_border); }

	void clear ();
	void reset ();

	double miny;
	double maxy;

	Gtk::Table fade_in_table;
	Gtk::Table fade_out_table;

	void build_presets ();
	void apply_preset (Preset*);

	Gtk::RadioButton select_in_button;
	Gtk::RadioButton select_out_button;
	Gtk::HBox   curve_button_box;
	Gtk::HBox   audition_box;

	void curve_select_clicked (WhichFade);

	double x_coordinate (double& xfract) const;
	double y_coordinate (double& yfract) const;

	void set (const ARDOUR::AutomationList& alist, WhichFade);

	PBD::ScopedConnection* _peaks_ready_connection;
	PBD::ScopedConnection state_connection;

	void make_waves (boost::shared_ptr<ARDOUR::AudioRegion>, WhichFade);
	void peaks_ready (boost::weak_ptr<ARDOUR::AudioRegion> r, WhichFade);

	void _apply_to (boost::shared_ptr<ARDOUR::Crossfade> xf);
	void setup (boost::shared_ptr<ARDOUR::Crossfade>);
	void cancel_audition ();
	void audition_state_changed (bool);

	enum Audition {
		Both,
		Left,
		Right
	};

	void audition_toggled ();
	void audition_right_toggled ();
	void audition_right_dry_toggled ();
	void audition_left_toggled ();
	void audition_left_dry_toggled ();

	void audition (Audition);
	void audition_both ();
	void audition_left_dry ();
	void audition_left ();
	void audition_right_dry ();
	void audition_right ();

	void xfade_changed (const PBD::PropertyChange&);

	void dump ();
};

#endif /* __gtk_ardour_xfade_edit_h__ */