switch to using boost::signals2 instead of sigc++, at least for libardour. not finish...
[ardour.git] / gtk2_ardour / crossfade_edit.h
1 /*
2     Copyright (C) 2000-2007 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __gtk_ardour_xfade_edit_h__
21 #define __gtk_ardour_xfade_edit_h__
22
23 #include <list>
24
25 #include <gtkmm/box.h>
26 #include <gtkmm/button.h>
27 #include <gtkmm/radiobutton.h>
28
29 #include "evoral/Curve.hpp"
30 #include "ardour/session_handle.h"
31
32 #include "ardour_dialog.h"
33 #include "canvas.h"
34
35 namespace ARDOUR
36 {
37         class Session;
38         class AutomationList;
39         class Crossfade;
40 }
41
42 class CrossfadeEditor : public ArdourDialog
43 {
44   public:
45         CrossfadeEditor (ARDOUR::Session*, boost::shared_ptr<ARDOUR::Crossfade>, double miny, double maxy);
46         ~CrossfadeEditor ();
47
48         void apply ();
49
50         static const double canvas_border;
51
52         /* these are public so that a caller/subclass can make them do the right thing.
53          */
54
55         Gtk::Button* cancel_button;
56         Gtk::Button* ok_button;
57
58         struct PresetPoint {
59             double x;
60             double y;
61
62             PresetPoint (double a, double b)
63                     : x (a), y (b) {}
64         };
65
66         struct Preset : public std::list<PresetPoint> {
67             const char* name;
68             const char* image_name;
69
70             Preset (const char* n, const char* x) : name (n), image_name (x) {}
71         };
72
73         typedef std::list<Preset*> Presets;
74
75         static Presets* fade_in_presets;
76         static Presets* fade_out_presets;
77
78   protected:
79         bool on_key_press_event (GdkEventKey*);
80         bool on_key_release_event (GdkEventKey*);
81
82   private:
83         boost::shared_ptr<ARDOUR::Crossfade> xfade;
84
85         Gtk::VBox vpacker;
86
87         struct Point {
88             ~Point();
89
90             ArdourCanvas::SimpleRect* box;
91             ArdourCanvas::Line* curve;
92             double x;
93             double y;
94
95             static const int32_t size;
96
97             void move_to (double x, double y, double xfract, double yfract);
98         };
99
100         struct PointSorter {
101             bool operator() (const CrossfadeEditor::Point* a, const CrossfadeEditor::Point *b) {
102                     return a->x < b->x;
103             }
104         };
105
106         ArdourCanvas::SimpleRect*   toplevel;
107         ArdourCanvas::Canvas* canvas;
108
109         struct Half {
110             ArdourCanvas::Line*     line;
111             ArdourCanvas::Polygon*  shading;
112             std::list<Point*>       points;
113             ARDOUR::AutomationList  normative_curve; /* 0 - 1.0, linear */
114             ARDOUR::AutomationList  gain_curve;      /* 0 - 2.0, gain mapping */
115             std::vector<ArdourCanvas::WaveView*>  waves;
116
117             Half();
118         };
119
120         enum WhichFade {
121                 In = 0,
122                 Out = 1
123         };
124
125         Half fade[2];
126         WhichFade current;
127
128         bool point_grabbed;
129         std::vector<Gtk::Button*> fade_out_buttons;
130         std::vector<Gtk::Button*> fade_in_buttons;
131
132         Gtk::VBox vpacker2;
133
134         Gtk::Button clear_button;
135         Gtk::Button revert_button;
136
137         Gtk::ToggleButton audition_both_button;
138         Gtk::ToggleButton audition_left_dry_button;
139         Gtk::ToggleButton audition_left_button;
140         Gtk::ToggleButton audition_right_dry_button;
141         Gtk::ToggleButton audition_right_button;
142
143         Gtk::ToggleButton preroll_button;
144         Gtk::ToggleButton postroll_button;
145
146         Gtk::HBox roll_box;
147
148         gint event_handler (GdkEvent*);
149
150         bool canvas_event (GdkEvent* event);
151         bool point_event (GdkEvent* event, Point*);
152         bool curve_event (GdkEvent* event);
153
154         void canvas_allocation (Gtk::Allocation&);
155         void add_control_point (double x, double y);
156         Point* make_point ();
157         void redraw ();
158
159         double effective_width () const { return canvas->get_allocation().get_width() - (2.0 * canvas_border); }
160         double effective_height () const { return canvas->get_allocation().get_height() - (2.0 * canvas_border); }
161
162         void clear ();
163         void reset ();
164
165         double miny;
166         double maxy;
167
168         Gtk::Table fade_in_table;
169         Gtk::Table fade_out_table;
170
171         void build_presets ();
172         void apply_preset (Preset*);
173
174         Gtk::RadioButton select_in_button;
175         Gtk::RadioButton select_out_button;
176         Gtk::HBox   curve_button_box;
177         Gtk::HBox   audition_box;
178
179         void curve_select_clicked (WhichFade);
180
181         double x_coordinate (double& xfract) const;
182         double y_coordinate (double& yfract) const;
183
184         void set (const ARDOUR::AutomationList& alist, WhichFade);
185
186         boost::signals2::scoped_connection peaks_ready_connection;
187
188         void make_waves (boost::shared_ptr<ARDOUR::AudioRegion>, WhichFade);
189         void peaks_ready (boost::weak_ptr<ARDOUR::AudioRegion> r, WhichFade);
190
191         void _apply_to (boost::shared_ptr<ARDOUR::Crossfade> xf);
192         void setup (boost::shared_ptr<ARDOUR::Crossfade>);
193         void cancel_audition ();
194         void audition_state_changed (bool);
195
196         enum Audition {
197                 Both,
198                 Left,
199                 Right
200         };
201
202         void audition_toggled ();
203         void audition_right_toggled ();
204         void audition_right_dry_toggled ();
205         void audition_left_toggled ();
206         void audition_left_dry_toggled ();
207
208         void audition (Audition);
209         void audition_both ();
210         void audition_left_dry ();
211         void audition_left ();
212         void audition_right_dry ();
213         void audition_right ();
214
215         void xfade_changed (ARDOUR::Change);
216
217         void dump ();
218 };
219
220 #endif /* __gtk_ardour_xfade_edit_h__ */