fix crash when copy'ing latent plugins
[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 #include "pbd/cartesian.h"
36
37 #include "ardour_window.h"
38
39 namespace ARDOUR {
40         class PannerShell;
41 }
42
43 namespace Gtk {
44         class Menu;
45         class CheckMenuItem;
46 }
47
48 namespace Pango {
49         class Container;
50 }
51
52 class Panner2dWindow;
53
54 class Panner2d : public Gtk::DrawingArea
55 {
56         public:
57         Panner2d (boost::shared_ptr<ARDOUR::PannerShell>, int32_t height);
58         ~Panner2d ();
59
60         void allow_target_motion (bool);
61
62         int  add_speaker (const PBD::AngularVector&);
63         int  add_signal (const char* text, const PBD::AngularVector&);
64         void move_signal (int which, const PBD::AngularVector&);
65         void reset (uint32_t n_inputs);
66         void set_send_drawing_mode (bool);
67
68         boost::shared_ptr<ARDOUR::PannerShell> get_panner_shell() const { return panner_shell; }
69
70         void cart_to_gtk (PBD::CartesianVector&) const;
71         void gtk_to_cart (PBD::CartesianVector&) const;
72
73         protected:
74         bool on_expose_event (GdkEventExpose *);
75         bool on_button_press_event (GdkEventButton *);
76         bool on_button_release_event (GdkEventButton *);
77         bool on_motion_notify_event (GdkEventMotion *);
78         bool on_scroll_event (GdkEventScroll *);
79         void on_size_allocate (Gtk::Allocation& alloc);
80
81         private:
82         class Target {
83                 public:
84                 PBD::AngularVector position;
85                 bool visible;
86                 std::string text;
87
88                 Target (const PBD::AngularVector&, const char* txt = 0);
89                 ~Target ();
90
91                 void set_text (const char*);
92                 void set_selected (bool yn) {
93                         _selected = yn;
94                 }
95                 bool selected() const {
96                         return _selected;
97                 }
98
99                 private:
100                 bool _selected;
101         };
102
103         struct ColorScheme {
104                 uint32_t background;
105                 uint32_t crosshairs;
106                 uint32_t signalcircle_border;
107                 uint32_t signalcircle;
108                 uint32_t diffusion;
109                 uint32_t diffusion_inv;
110                 uint32_t pos_outline;
111                 uint32_t pos_fill;
112                 uint32_t signal_outline;
113                 uint32_t signal_fill;
114                 uint32_t speaker_fill;
115                 uint32_t text;
116         };
117
118         static ColorScheme colors;
119         static void set_colors ();
120         static bool have_colors;
121         void color_handler ();
122
123         boost::shared_ptr<ARDOUR::PannerShell> panner_shell;
124         Glib::RefPtr<Pango::Layout> layout;
125
126         typedef std::vector<Target*> Targets;
127         Targets speakers;
128         Targets signals;
129         Target  position;
130
131         Target *drag_target;
132         int     width;
133         int     height;
134         double  radius;
135         double  border;
136         double  hoffset;
137         double  voffset;
138         double  last_width;
139         bool    did_move;
140         bool    have_elevation;
141         bool    _send_mode;
142
143         Target *find_closest_object (gdouble x, gdouble y, bool& is_signal);
144
145         gint handle_motion (gint, gint, GdkModifierType);
146
147         void toggle_bypass ();
148         void handle_state_change ();
149         void handle_position_change ();
150         void label_signals ();
151
152         PBD::ScopedConnectionList panshell_connections;
153         PBD::ScopedConnectionList panner_connections;
154
155         /* cartesian coordinates in GTK units ; adjust to same but on a circle of radius 1.0
156            and centered in the middle of our area
157         */
158         void clamp_to_circle (double& x, double& y);
159         void sphere_project (double& x, double& y, double& z);
160 };
161
162 class Panner2dWindow : public ArdourWindow
163 {
164         public:
165         Panner2dWindow (boost::shared_ptr<ARDOUR::PannerShell>, int32_t height, uint32_t inputs);
166
167         void reset (uint32_t n_inputs);
168
169         private:
170         Panner2d widget;
171
172         Gtk::HBox         hpacker;
173         Gtk::VBox         button_box;
174         Gtk::ToggleButton bypass_button;
175         Gtk::VBox         spinner_box;
176         Gtk::VBox         left_side;
177
178         Gtk::Adjustment   width_adjustment;
179         Gtk::SpinButton   width_spinner;
180
181         PBD::ScopedConnectionList panshell_connections;
182         PBD::ScopedConnectionList panvalue_connections;
183         void set_bypassed();
184         void set_width();
185
186         void pannable_handler ();
187         void bypass_toggled ();
188         void width_changed ();
189         bool on_key_press_event (GdkEventKey*);
190         bool on_key_release_event (GdkEventKey*);
191 };
192
193 #endif /* __ardour_panner_2d_h__ */