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