Unconditionally save instant.xml on session-close
[ardour.git] / gtk2_ardour / axis_view.cc
1 /*
2  * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
4  * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
6  * Copyright (C) 2014-2018 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 #include <cstdlib>
25 #include <cmath>
26
27 #include <algorithm>
28 #include <string>
29
30 #include <list>
31
32 #include "pbd/error.h"
33 #include "pbd/convert.h"
34
35 #include <gtkmm2ext/utils.h>
36 #include <gtkmm2ext/gtk_ui.h>
37
38 #include "ardour/selection.h"
39
40 #include "public_editor.h"
41 #include "ardour_ui.h"
42 #include "gui_object.h"
43 #include "axis_view.h"
44 #include "utils.h"
45
46 #include "pbd/i18n.h"
47
48 using namespace std;
49 using namespace Gtk;
50 using namespace Gtkmm2ext;
51 using namespace ARDOUR;
52 using namespace ARDOUR_UI_UTILS;
53
54 list<Gdk::Color> AxisView::used_colors;
55
56 AxisView::AxisView ()
57 {
58 }
59
60 AxisView::~AxisView()
61 {
62 }
63
64 Gdk::Color
65 AxisView::unique_random_color()
66 {
67         return ::unique_random_color (used_colors);
68 }
69
70 string
71 AxisView::gui_property (const string& property_name) const
72 {
73         if (property_hashtable.count(property_name)) {
74                 return property_hashtable[property_name];
75         } else {
76                 string rv = gui_object_state().get_string (state_id(), property_name);
77                 property_hashtable.erase(property_name);
78                 property_hashtable.emplace(property_name, rv);
79                 return rv;
80         }
81 }
82
83 bool
84 AxisView::get_gui_property (const std::string& property_name, std::string& value) const
85 {
86         std::string str = gui_property(property_name);
87
88         if (!str.empty()) {
89                 value = str;
90                 return true;
91         }
92
93         return false;
94 }
95
96 void
97 AxisView::set_gui_property (const std::string& property_name, const std::string& value)
98 {
99         property_hashtable.erase (property_name);
100         property_hashtable.emplace (property_name, value);
101         gui_object_state ().set_property (state_id (), property_name, value);
102 }
103
104 bool
105 AxisView::marked_for_display () const
106 {
107         bool visible;
108         if (!get_gui_property ("visible", visible)) {
109                 return true;
110         }
111         return visible;
112 }
113
114 bool
115 AxisView::set_marked_for_display (bool yn)
116 {
117         bool visible;
118         if (get_gui_property ("visible", visible) && visible == yn) {
119                 return false; // nothing changed
120         }
121
122         set_gui_property ("visible", yn);
123         return true; // things changed
124 }
125
126 GUIObjectState&
127 AxisView::gui_object_state()
128 {
129         return *ARDOUR_UI::instance()->gui_object_state;
130 }
131
132 void
133 AxisView::set_selected (bool yn)
134 {
135         if (selected() == yn) {
136                 return;
137         }
138
139         Selectable::set_selected (yn);
140 }