Optimize automation-event process splitting
[ardour.git] / gtk2_ardour / axis_view.h
1 /*
2     Copyright (C) 2003 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_gtk_axis_view_h__
21 #define __ardour_gtk_axis_view_h__
22
23 #include <list>
24 #include <boost/unordered_map.hpp>
25
26 #include <gtkmm/label.h>
27 #include <gdkmm/color.h>
28
29 #include "pbd/xml++.h"
30 #include "pbd/signals.h"
31
32 #include "ardour/session_handle.h"
33
34 #include "gui_object.h"
35 #include "selectable.h"
36
37 namespace PBD {
38         class Controllable;
39 }
40
41 namespace ARDOUR {
42         class Session;
43         class Stripable;
44         class PresentationInfo;
45 }
46
47 /**
48  * AxisView defines the abstract base class for horizontal and vertical
49  * presentations of Stripables.
50  *
51  */
52 class AxisView : public virtual PBD::ScopedConnectionList, public virtual ARDOUR::SessionHandlePtr, public virtual Selectable
53 {
54 public:
55         virtual std::string name() const = 0;
56         virtual Gdk::Color color() const = 0;
57
58         sigc::signal<void> Hiding;
59
60         virtual boost::shared_ptr<ARDOUR::Stripable> stripable() const = 0;
61         virtual boost::shared_ptr<ARDOUR::AutomationControl> control() const { return boost::shared_ptr<ARDOUR::AutomationControl>(); }
62
63         virtual std::string state_id() const = 0;
64         /* for now, we always return properties in string form.
65         */
66         std::string gui_property (const std::string& property_name) const;
67
68         bool get_gui_property (const std::string& property_name, std::string& value) const;
69
70         template <typename T>
71                 bool get_gui_property (const std::string& property_name, T& value) const
72                 {
73                         std::string str = gui_property (property_name);
74
75                         if (!str.empty ()) {
76                                 return PBD::string_to<T>(str, value);
77                         }
78                         return false;
79                 }
80
81         void set_gui_property (const std::string& property_name, const std::string& value);
82
83         void set_gui_property (const std::string& property_name, const char* value) {
84                 set_gui_property (property_name, std::string(value));
85         }
86
87         template <typename T>
88         void set_gui_property (const std::string& property_name, const T& value)
89         {
90                 set_gui_property (property_name, PBD::to_string(value));
91         }
92
93         void cleanup_gui_properties () {
94                 /* remove related property node from the GUI state */
95                 gui_object_state().remove_node (state_id());
96                 property_hashtable.clear ();
97         }
98
99         void set_selected (bool yn);
100
101         virtual bool marked_for_display () const;
102         virtual bool set_marked_for_display (bool);
103
104         static GUIObjectState& gui_object_state();
105         void clear_property_cache() { property_hashtable.clear(); }
106
107         /**
108          * Generate a new random TrackView color, unique from those colors already used.
109          *
110          * @return the unique random color.
111          */
112         static Gdk::Color unique_random_color();
113
114 protected:
115         AxisView ();
116         virtual ~AxisView();
117
118         static std::list<Gdk::Color> used_colors;
119
120         Gtk::Label name_label;
121
122         mutable boost::unordered_map<std::string, std::string> property_hashtable;
123 }; /* class AxisView */
124
125 #endif /* __ardour_gtk_axis_view_h__ */