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