fixes for libsndfile conversion issues, tape track waveform display and overloaded...
[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     $Id$
19 */
20
21 #ifndef __ardour_panner_2d_h__
22 #define __ardour_panner_2d_h__
23
24 #include <sys/types.h>
25 #include <map>
26 #include <string>
27
28 #include <glibmm/refptr.h>
29 #include <gtkmm/drawingarea.h>
30
31 using std::map;
32 using std::string;
33
34 namespace ARDOUR {
35         class Panner;
36 }
37
38 namespace Gtk {
39         class Menu;
40         class CheckMenuItem;
41 }
42
43 namespace Pango {
44         class Layout;
45 }
46
47 class Panner2d : public Gtk::DrawingArea
48 {
49   public:
50         Panner2d (ARDOUR::Panner&, int32_t width, int32_t height);
51         ~Panner2d ();
52         
53         int puck_position (int which_puck, float& x, float& y);
54         int target_position (int which_target, float& x, float& y);
55
56         void allow_x_motion(bool);
57         void allow_y_motion(bool);
58         void allow_target_motion (bool);
59
60         void hide_puck (int which);
61         void show_puck (int which);
62         int  add_target (float x, float y);
63         int  add_puck (const char* text, float x, float y);
64         void hide_target (int);
65         void show_target (int);
66         void remove_target (int);
67         void drop_targets ();
68         void drop_pucks ();
69         void move_target (int, float x, float y);
70         void move_puck (int, float x, float y);
71         void reset (uint32_t n_inputs);
72
73         sigc::signal<void,int> PuckMoved;
74         sigc::signal<void,int> TargetMoved;
75
76   protected:
77         bool on_expose_event (GdkEventExpose *);
78         bool on_button_press_event (GdkEventButton *);
79         bool on_button_release_event (GdkEventButton *);
80         bool on_motion_notify_event (GdkEventMotion *);
81         void on_size_allocate (Gtk::Allocation& alloc);
82
83   private:
84         struct Target {
85             float x;
86             float y;
87             bool visible;
88             char* text;
89             size_t textlen;
90
91             Target (float xa, float ya, const char* txt = 0);
92             ~Target ();
93         };
94
95         ARDOUR::Panner& panner;
96         Gtk::Menu* context_menu;
97         Gtk::CheckMenuItem* bypass_menu_item;
98         Glib::RefPtr<Pango::Layout> layout;
99
100         typedef std::map<int,Target *> Targets;
101         Targets targets;
102         Targets pucks;
103
104         Target *drag_target;
105         int     drag_index;
106         bool    drag_is_puck;
107         bool  allow_x;
108         bool  allow_y;
109         bool  allow_target;
110         int width;
111         int height;
112
113         bool bypassflag;
114         
115         gint compute_x (float);
116         gint compute_y (float);
117
118         Target *find_closest_object (gdouble x, gdouble y, int& which, bool& is_puck) const;
119
120         gint handle_motion (gint, gint, GdkModifierType);
121
122         void toggle_bypass ();
123         void show_context_menu ();
124         void handle_state_change ();
125 };
126
127 #endif /* __ardour_panner_2d_h__ */