715aa1a3607da3f6fe3765d9dd0aa66c4d4af110
[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 <ardour/curve.h>
30 #include "ardour_dialog.h"
31 #include "canvas.h"
32
33 namespace ARDOUR
34 {
35         class Session;
36         class Curve;
37         class Crossfade;
38 }
39
40 class CrossfadeEditor : public ArdourDialog
41 {
42   public:
43         CrossfadeEditor (ARDOUR::Session&, boost::shared_ptr<ARDOUR::Crossfade>, double miny, double maxy);
44         ~CrossfadeEditor ();
45         
46         void apply ();
47         
48         static const double canvas_border;
49         
50         /* these are public so that a caller/subclass can make them do the right thing.
51          */
52         
53         Gtk::Button* cancel_button;
54         Gtk::Button* ok_button;
55         
56         struct PresetPoint {
57             double x;
58             double y;
59             
60             PresetPoint (double a, double b) 
61                     : x (a), y (b) {}
62         };
63         
64         struct Preset : public list<PresetPoint> {
65             const char* image_name;
66             
67             Preset (const char* x) : image_name (x) {}
68         };
69         
70         typedef list<Preset*> Presets;
71         
72         static Presets* fade_in_presets;
73         static Presets* fade_out_presets;
74         
75   private:
76         boost::shared_ptr<ARDOUR::Crossfade> xfade;
77         ARDOUR::Session& session;
78         
79         Gtk::VBox vpacker;
80         
81         struct Point {
82             ~Point();
83             
84             ArdourCanvas::SimpleRect* box;
85             ArdourCanvas::Line* curve;
86             double x;
87             double y;
88             
89             static const int32_t size;
90             
91             void move_to (double x, double y, double xfract, double yfract);
92         };
93         
94         struct PointSorter 
95         {
96             bool operator() (const CrossfadeEditor::Point* a, const CrossfadeEditor::Point *b) {
97                     return a->x < b->x;
98             }
99         };
100         
101         ArdourCanvas::SimpleRect*   toplevel;
102         ArdourCanvas::Canvas* canvas;
103         
104         struct Half {
105             ArdourCanvas::Line*     line;
106             ArdourCanvas::Polygon*  shading;
107             list<Point*>            points;
108             ARDOUR::Curve           normative_curve; /* 0 - 1.0, linear */
109             ARDOUR::Curve           gain_curve;      /* 0 - 2.0, gain mapping */
110             vector<ArdourCanvas::WaveView*>  waves;
111             
112             Half();
113         };
114         
115         enum WhichFade {
116                 In = 0,
117                 Out = 1
118         };
119         
120         Half fade[2];
121         WhichFade current;
122         
123         bool point_grabbed;
124         vector<Gtk::Button*> fade_out_buttons;
125         vector<Gtk::Button*> fade_in_buttons;
126
127         Gtk::VBox vpacker2;
128
129         Gtk::Button clear_button;
130         Gtk::Button revert_button;
131
132         Gtk::ToggleButton audition_both_button;
133         Gtk::ToggleButton audition_left_dry_button;
134         Gtk::ToggleButton audition_left_button;
135         Gtk::ToggleButton audition_right_dry_button;
136         Gtk::ToggleButton audition_right_button;
137
138         Gtk::ToggleButton preroll_button;
139         Gtk::ToggleButton postroll_button;
140
141         Gtk::HBox roll_box;
142
143         gint event_handler (GdkEvent*);
144
145         bool canvas_event (GdkEvent* event);
146         bool point_event (GdkEvent* event, Point*);
147         bool curve_event (GdkEvent* event);
148
149         void canvas_allocation (Gtk::Allocation&);
150         void add_control_point (double x, double y);
151         Point* make_point ();
152         void redraw ();
153     
154         double effective_width () const { return canvas->get_allocation().get_width() - (2.0 * canvas_border); }
155         double effective_height () const { return canvas->get_allocation().get_height() - (2.0 * canvas_border); }
156
157         void clear ();
158         void reset ();
159
160         double miny;
161         double maxy;
162
163         Gtk::Table fade_in_table;
164         Gtk::Table fade_out_table;
165
166         void build_presets ();
167         void apply_preset (Preset*);
168     
169         Gtk::RadioButton select_in_button;
170         Gtk::RadioButton select_out_button;
171         Gtk::HBox   curve_button_box;
172         Gtk::HBox   audition_box;
173
174         void curve_select_clicked (WhichFade);
175
176         double x_coordinate (double& xfract) const;
177         double y_coordinate (double& yfract) const;
178     
179         void set (const ARDOUR::Curve& alist, WhichFade);
180
181         sigc::connection peaks_ready_connection;
182
183         void make_waves (boost::shared_ptr<ARDOUR::AudioRegion>, WhichFade);
184         void peaks_ready (boost::shared_ptr<ARDOUR::AudioRegion> r, WhichFade);
185     
186         void _apply_to (boost::shared_ptr<ARDOUR::Crossfade> xf);
187         void setup (boost::shared_ptr<ARDOUR::Crossfade>);
188         void cancel_audition ();
189         void audition_state_changed (bool);
190
191         void audition_toggled ();
192         void audition_right_toggled ();
193         void audition_right_dry_toggled ();
194         void audition_left_toggled ();
195         void audition_left_dry_toggled ();
196
197         void audition_both ();
198         void audition_left_dry ();
199         void audition_left ();
200         void audition_right_dry ();
201         void audition_right ();
202
203         void xfade_changed (ARDOUR::Change);
204
205         void dump ();
206 };
207
208 #endif /* __gtk_ardour_xfade_edit_h__ */