1 /*
2  * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
4  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
6  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
7  * Copyright (C) 2016 Tim Mayberry <mojofunk@gmail.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef __ardour_gtk_axis_view_h__
25 #define __ardour_gtk_axis_view_h__
26 
27 #include <list>
28 #include <boost/unordered_map.hpp>
29 
30 #include <gtkmm/label.h>
31 #include <gtkmm/table.h>
32 #include <gdkmm/color.h>
33 
34 #include "pbd/xml++.h"
35 #include "pbd/signals.h"
36 
37 #include "ardour/session_handle.h"
38 
39 #include "gui_object.h"
40 #include "selectable.h"
41 
42 namespace PBD {
43 	class Controllable;
44 }
45 
46 namespace ARDOUR {
47 	class Session;
48 	class Stripable;
49 	class PresentationInfo;
50 }
51 
52 /**
53  * AxisView defines the abstract base class for horizontal and vertical
54  * presentations of Stripables.
55  *
56  */
57 class AxisView : public virtual PBD::ScopedConnectionList, public virtual ARDOUR::SessionHandlePtr, public virtual Selectable
58 {
59 public:
60 	virtual std::string name() const = 0;
61 	virtual Gdk::Color color() const = 0;
62 
63 	sigc::signal<void> Hiding;
64 
65 	virtual boost::shared_ptr<ARDOUR::Stripable> stripable() const = 0;
control()66 	virtual boost::shared_ptr<ARDOUR::AutomationControl> control() const { return boost::shared_ptr<ARDOUR::AutomationControl>(); }
67 
68 	virtual std::string state_id() const = 0;
69 	/* for now, we always return properties in string form.
70 	*/
71 	std::string gui_property (const std::string& property_name) const;
72 
73 	bool get_gui_property (const std::string& property_name, std::string& value) const;
74 
75 	template <typename T>
get_gui_property(const std::string & property_name,T & value)76 		bool get_gui_property (const std::string& property_name, T& value) const
77 		{
78 			std::string str = gui_property (property_name);
79 
80 			if (!str.empty ()) {
81 				return PBD::string_to<T>(str, value);
82 			}
83 			return false;
84 		}
85 
86 	template <typename T>
get_gui_property(const std::string & state_id,const std::string & property_name,T & value)87 		bool get_gui_property (const std::string& state_id, const std::string& property_name, T& value) const
88 		{
89 			std::string str = gui_object_state().get_string (state_id, property_name);
90 
91 			if (!str.empty ()) {
92 				return PBD::string_to<T>(str, value);
93 			}
94 			return false;
95 		}
96 
97 
98 	void set_gui_property (const std::string& property_name, const std::string& value);
99 	void remove_gui_property (const std::string& property_name);
100 
set_gui_property(const std::string & property_name,const char * value)101 	void set_gui_property (const std::string& property_name, const char* value) {
102 		set_gui_property (property_name, std::string(value));
103 	}
104 
105 	template <typename T>
set_gui_property(const std::string & property_name,const T & value)106 	void set_gui_property (const std::string& property_name, const T& value)
107 	{
108 		set_gui_property (property_name, PBD::to_string(value));
109 	}
110 
cleanup_gui_properties()111 	void cleanup_gui_properties () {
112 		/* remove related property node from the GUI state */
113 		gui_object_state().remove_node (state_id());
114 		property_hashtable.clear ();
115 	}
116 
117 	void set_selected (bool yn);
118 
119 	virtual bool marked_for_display () const;
120 	virtual bool set_marked_for_display (bool);
121 
122 	static GUIObjectState& gui_object_state();
clear_property_cache()123 	void clear_property_cache() { property_hashtable.clear(); }
124 
125 	/**
126 	 * Generate a new random TrackView color, unique from those colors already used.
127 	 *
128 	 * @return the unique random color.
129 	 */
130 	static Gdk::Color unique_random_color();
131 
132 protected:
133 	AxisView ();
134 	virtual ~AxisView();
135 
136 	static std::list<Gdk::Color> used_colors;
137 
138 	Gtk::Label name_label;
139 	void set_name_ellipsize_mode ();
140 
141 	Gtk::Label inactive_label;
142 	Gtk::Table inactive_table;
143 
144 	mutable boost::unordered_map<std::string, std::string> property_hashtable;
145 }; /* class AxisView */
146 
147 #endif /* __ardour_gtk_axis_view_h__ */
148