The great audio processing overhaul.
[ardour.git] / gtk2_ardour / panner2d.h
1 /*
2     Copyright (C) 2002 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 __ardour_panner_2d_h__
21 #define __ardour_panner_2d_h__
22
23 #include <sys/types.h>
24 #include <map>
25 #include <string>
26 #include <vector>
27
28 #include <glibmm/refptr.h>
29 #include <gtkmm/drawingarea.h>
30 #include <gtkmm/window.h>
31 #include <gtkmm/box.h>
32 #include <gtkmm/button.h>
33 #include <gtkmm/spinbutton.h>
34 #include <gtkmm/adjustment.h>
35
36 using std::map;
37 using std::string;
38
39 namespace ARDOUR {
40         class Panner;
41 }
42
43 namespace Gtk {
44         class Menu;
45         class CheckMenuItem;
46 }
47
48 namespace Pango {
49         class Layout;
50 }
51
52 class Panner2dWindow;
53
54 class Panner2d : public Gtk::DrawingArea
55 {
56   public:
57         Panner2d (boost::shared_ptr<ARDOUR::Panner>, int32_t height);
58         ~Panner2d ();
59         
60         void allow_x_motion(bool);
61         void allow_y_motion(bool);
62         void allow_target_motion (bool);
63
64         void hide_puck (int which);
65         void show_puck (int which);
66         int  add_target (float x, float y);
67         int  add_puck (const char* text, float x, float y);
68         void hide_target (int);
69         void show_target (int);
70         void remove_target (int);
71         void drop_targets ();
72         void drop_pucks ();
73         void move_target (int, float x, float y);
74         void move_puck (int, float x, float y);
75         void reset (uint32_t n_inputs);
76
77         Gtk::Adjustment& azimuth (uint32_t which);
78
79         boost::shared_ptr<ARDOUR::Panner> get_panner() const { return panner; }
80         
81         sigc::signal<void,int> PuckMoved;
82         sigc::signal<void,int> TargetMoved;
83
84   protected:
85         bool on_expose_event (GdkEventExpose *);
86         bool on_button_press_event (GdkEventButton *);
87         bool on_button_release_event (GdkEventButton *);
88         bool on_motion_notify_event (GdkEventMotion *);
89         void on_size_allocate (Gtk::Allocation& alloc);
90
91   private:
92         struct Target {
93             Gtk::Adjustment x;
94             Gtk::Adjustment y;
95             Gtk::Adjustment azimuth;
96             bool visible;
97             char* text;
98
99             Target (float xa, float ya, const char* txt = 0);
100             ~Target ();
101
102             void set_text (const char*);
103         };
104
105         boost::shared_ptr<ARDOUR::Panner> panner;
106         Glib::RefPtr<Pango::Layout> layout;
107
108         typedef std::map<int,Target *> Targets;
109         Targets targets;
110         Targets pucks;
111
112         Target *drag_target;
113         int drag_x;
114         int drag_y;
115         int     drag_index;
116         bool    drag_is_puck;
117         bool  allow_x;
118         bool  allow_y;
119         bool  allow_target;
120         int width;
121         int height;
122
123         bool bypassflag;
124         
125         gint compute_x (float);
126         gint compute_y (float);
127
128         Target *find_closest_object (gdouble x, gdouble y, int& which, bool& is_puck) const;
129
130         gint handle_motion (gint, gint, GdkModifierType);
131
132         void toggle_bypass ();
133         void handle_state_change ();
134         void handle_position_change ();
135 };
136
137 class Panner2dWindow : public Gtk::Window
138 {
139   public:
140         Panner2dWindow (boost::shared_ptr<ARDOUR::Panner>, int32_t height, uint32_t inputs);
141         
142         void reset (uint32_t n_inputs);
143
144   private:
145         Panner2d widget;
146
147         Gtk::HBox   hpacker;
148         Gtk::VBox   button_box;
149         Gtk::Button reset_button;
150         Gtk::ToggleButton bypass_button;
151         Gtk::ToggleButton mute_button;
152         Gtk::VBox   spinner_box;
153         Gtk::VBox   left_side;
154
155         std::vector<Gtk::SpinButton*> spinners;
156 };
157
158 #endif /* __ardour_panner_2d_h__ */