fix various aspects of knob function
[ardour.git] / libs / surfaces / push2 / knob.h
1 #ifndef __ardour_push2_knob_h__
2 #define __ardour_push2_knob_h__
3
4 #include <boost/shared_ptr.hpp>
5 #include <sigc++/trackable.h>
6
7 #include <cairomm/refptr.h>
8
9 #include "pbd/signals.h"
10
11 #include "canvas/container.h"
12
13 namespace ArdourCanvas {
14         class Text;
15 }
16
17 namespace ARDOUR {
18         class AutomationControl;
19 }
20
21 namespace Cairo {
22         class Context;
23         class Region;
24 }
25
26 namespace ArdourSurface {
27
28 class Push2;
29
30 class Push2Knob : public sigc::trackable, public ArdourCanvas::Container
31 {
32 public:
33         enum Element {
34                 Arc = 0x1,
35                 Bevel = 0x2,
36                 unused2 = 0x4,
37                 unused3 = 0x8,
38                 unused4 = 0x10,
39                 unused5 = 0x20,
40         };
41
42         enum Flags {
43                 NoFlags = 0,
44                 Detent = 0x1,
45                 ArcToZero = 0x2,
46         };
47
48         Push2Knob (Push2& p, ArdourCanvas::Item*, Element e = default_elements, Flags flags = NoFlags);
49         virtual ~Push2Knob ();
50
51         static Element default_elements;
52
53         void add_flag (Flags);
54         void remove_flag (Flags);
55
56         void set_controllable (boost::shared_ptr<ARDOUR::AutomationControl> c);
57         boost::shared_ptr<ARDOUR::AutomationControl> controllable() const { return _controllable; }
58
59         void set_text_color (ArdourCanvas::Color);
60         void set_arc_start_color (ArdourCanvas::Color);
61         void set_arc_end_color (ArdourCanvas::Color);
62         void set_radius (double r);
63
64         void render (ArdourCanvas::Rect const &, Cairo::RefPtr<Cairo::Context>) const;
65         void compute_bounding_box() const;
66
67   protected:
68         void controllable_changed ();
69         PBD::ScopedConnection watch_connection;
70         boost::shared_ptr<ARDOUR::AutomationControl> _controllable;
71
72   private:
73         Push2& p2;
74         Element _elements;
75         Flags   _flags;
76         double  _r;
77         float   _val; // current value [0..1]
78         float   _normal; // default value, arc
79
80         ArdourCanvas::Color text_color;
81         ArdourCanvas::Color arc_start_color;
82         ArdourCanvas::Color arc_end_color;
83         ArdourCanvas::Text* text;
84
85         void set_pan_azimuth_text (double);
86         void set_pan_width_text (double);
87         void set_gain_text (double);
88 };
89
90 } // namespace
91
92 #endif /* __ardour_push2_knob_h__ */