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