dbe62dea66d03b583f1d4332a98537f49ffbaf8d
[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 <gtk--/box.h>
7 #include <gtk--/button.h>
8 #include <gtk--/radiobutton.h>
9 #include <gtk-canvas.h>
10
11 #include <ardour/curve.h>
12 #include "ardour_dialog.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         GtkCanvasItem* box;
67         GtkCanvasItem* 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     GtkWidget*    _canvas;
84     GtkCanvasItem* toplevel;
85     Gtk::Widget*   canvas;
86
87     struct Half {
88         GtkCanvasItem*          line;
89         GtkCanvasItem*          shading;
90         list<Point*>            points;
91         ARDOUR::Curve           normative_curve; /* 0 - 1.0, linear */
92         ARDOUR::Curve           gain_curve;      /* 0 - 2.0, gain mapping */
93         vector<GtkCanvasItem*>  waves;
94
95         Half();
96     };
97
98     enum WhichFade {
99             In = 0,
100             Out = 1
101     };
102
103     Half fade[2];
104     WhichFade current;
105
106     bool point_grabbed;
107     vector<Gtk::Button*> fade_out_buttons;
108     vector<Gtk::Button*> fade_in_buttons;
109
110     Gtk::HBox action_box;
111
112     Gtk::VBox vpacker2;
113
114     Gtk::Button clear_button;
115     Gtk::Button revert_button;
116
117     Gtk::ToggleButton audition_both_button;
118     Gtk::ToggleButton audition_left_dry_button;
119     Gtk::ToggleButton audition_left_button;
120     Gtk::ToggleButton audition_right_dry_button;
121     Gtk::ToggleButton audition_right_button;
122
123     Gtk::ToggleButton preroll_button;
124     Gtk::ToggleButton postroll_button;
125
126     Gtk::HBox roll_box;
127
128     gint event_handler (GdkEvent*);
129
130     static gint _canvas_event (GtkCanvasItem*, GdkEvent* event, gpointer data);
131     static gint _point_event (GtkCanvasItem*, GdkEvent* event, gpointer data);
132     static gint _curve_event (GtkCanvasItem*, GdkEvent* event, gpointer data);
133
134     gint canvas_event (GtkCanvasItem*, GdkEvent* event);
135     gint point_event (GtkCanvasItem*, GdkEvent* event);
136     gint curve_event (GtkCanvasItem*, GdkEvent* event);
137
138     void canvas_allocation (GtkAllocation*);
139     void add_control_point (double x, double y);
140     Point* make_point ();
141     void redraw ();
142     
143     double effective_width () const { return _canvas->allocation.width - (2.0 * canvas_border); }
144     double effective_height () const { return _canvas->allocation.height - (2.0 * canvas_border); }
145
146     void clear ();
147     void reset ();
148
149     double miny;
150     double maxy;
151
152     Gtk::Table fade_in_table;
153     Gtk::Table fade_out_table;
154
155     void build_presets ();
156     void apply_preset (Preset*);
157     
158     Gtk::RadioButton select_in_button;
159     Gtk::RadioButton select_out_button;
160     Gtk::HBox   curve_button_box;
161     Gtk::HBox   audition_box;
162
163     void curve_select_clicked (WhichFade);
164
165     double x_coordinate (double& xfract) const;
166     double y_coordinate (double& yfract) const;
167     
168     void set (const ARDOUR::Curve& alist, WhichFade);
169
170     void make_waves (ARDOUR::AudioRegion&, WhichFade);
171     void peaks_ready (ARDOUR::AudioRegion* r, WhichFade);
172     
173     void _apply_to (ARDOUR::Crossfade* xf);
174     void setup (ARDOUR::Crossfade*);
175     void cancel_audition ();
176     void audition_state_changed (bool);
177
178     void audition_toggled ();
179     void audition_right_toggled ();
180     void audition_right_dry_toggled ();
181     void audition_left_toggled ();
182     void audition_left_dry_toggled ();
183
184     void audition_both ();
185     void audition_left_dry ();
186     void audition_left ();
187     void audition_right_dry ();
188     void audition_right ();
189
190     void xfade_changed (ARDOUR::Change);
191
192     void dump ();
193 };
194
195 #endif /* __gtk_ardour_xfade_edit_h__ */