Assume axis views with no set visible property are visible.
[ardour.git] / gtk2_ardour / axis_view.cc
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 #include <cstdlib>
21 #include <cmath>
22
23 #include <algorithm>
24 #include <string>
25
26 #include <list>
27
28 #include "pbd/error.h"
29
30 #include <gtkmm2ext/utils.h>
31 #include <gtkmm2ext/selector.h>
32 #include <gtkmm2ext/gtk_ui.h>
33
34 #include "ardour/session.h"
35 #include "ardour/utils.h"
36
37 #include "public_editor.h"
38 #include "ardour_ui.h"
39 #include "gui_object.h"
40 #include "axis_view.h"
41 #include "i18n.h"
42
43 using namespace std;
44 using namespace Gtk;
45 using namespace Gtkmm2ext;
46 using namespace ARDOUR;
47
48 list<Gdk::Color> AxisView::used_colors;
49
50 AxisView::AxisView (ARDOUR::Session* sess)
51         : SessionHandlePtr (sess)
52 {
53         _selected = false;
54 }
55
56 AxisView::~AxisView()
57 {
58 }
59
60 Gdk::Color
61 AxisView::unique_random_color()
62 {
63         Gdk::Color newcolor;
64
65         while (1) {
66
67                 /* avoid neon/glowing tones by limiting them to the
68                    "inner section" (paler) of a color wheel/circle.
69                 */
70
71                 const int32_t max_saturation = 48000; // 65535 would open up the whole color wheel
72
73                 newcolor.set_red (random() % max_saturation);
74                 newcolor.set_blue (random() % max_saturation);
75                 newcolor.set_green (random() % max_saturation);
76
77                 if (used_colors.size() == 0) {
78                         used_colors.push_back (newcolor);
79                         return newcolor;
80                 }
81
82                 for (list<Gdk::Color>::iterator i = used_colors.begin(); i != used_colors.end(); ++i) {
83                   Gdk::Color c = *i;
84                         float rdelta, bdelta, gdelta;
85
86                         rdelta = newcolor.get_red() - c.get_red();
87                         bdelta = newcolor.get_blue() - c.get_blue();
88                         gdelta = newcolor.get_green() - c.get_green();
89
90                         if (sqrt (rdelta*rdelta + bdelta*bdelta + gdelta*gdelta) > 25.0) {
91                                 used_colors.push_back (newcolor);
92                                 return newcolor;
93                         }
94                 }
95
96                 /* XXX need throttle here to make sure we don't spin for ever */
97         }
98 }
99
100 string
101 AxisView::gui_property (const string& property_name) const
102 {
103         return gui_object_state().get_string (state_id(), property_name);
104 }
105
106 bool
107 AxisView::marked_for_display () const
108 {
109         string const v = gui_property ("visible");
110         return (v == "" || string_is_affirmative (v));
111 }
112
113 bool
114 AxisView::set_marked_for_display (bool yn)
115 {
116         if (yn != marked_for_display()) {
117                 if (yn) {
118                         set_gui_property ("visible", true);
119                 } else {
120                         set_gui_property ("visible", false);
121                 }
122                 return true; // things changed
123         }
124
125         return false;
126 }
127
128 GUIObjectState&
129 AxisView::gui_object_state() 
130 {
131         return *ARDOUR_UI::instance()->gui_object_state;
132 }