e69fdf0540fe48611585b3b6e661e2ff8797b1db
[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     $Id$
19 */
20
21 #include <cstdlib>
22 #include <cmath>
23
24 #include <algorithm>
25 #include <string>
26
27 #include <list>
28
29 #include <pbd/error.h>
30
31 #include <gtkmm2ext/utils.h>
32 #include <gtkmm2ext/selector.h>
33 #include <gtkmm2ext/gtk_ui.h>
34
35 #include <ardour/session.h>
36 #include <ardour/utils.h>
37
38 #include "public_editor.h"
39 #include "axis_view.h"
40 #include "i18n.h"
41
42 using namespace Gtk;
43 using namespace Gtkmm2ext;
44
45
46 list<Gdk::Color> AxisView::used_colors;
47
48 AxisView::AxisView (ARDOUR::Session& sess) : _session(sess)
49 {
50         _selected = false;
51         _marked_for_display = true;
52 }
53
54 AxisView::~AxisView()
55 {
56
57 }
58
59 Gdk::Color
60 AxisView::unique_random_color()
61 {
62         Gdk::Color newcolor;
63         
64         while (1) {
65
66                 /* avoid neon/glowing tones by limiting them to the
67                    "inner section" (paler) of a color wheel/circle.
68                 */
69
70                 const int32_t max_saturation = 48000; // 65535 would open up the whole color wheel
71
72                 newcolor.set_red (random() % max_saturation);
73                 newcolor.set_blue (random() % max_saturation);
74                 newcolor.set_green (random() % max_saturation);
75
76                 if (used_colors.size() == 0) {
77                         used_colors.push_back (newcolor);
78                         return newcolor;
79                 }
80                 
81                 for (list<Gdk::Color>::iterator i = used_colors.begin(); i != used_colors.end(); ++i) {
82                   Gdk::Color c = *i;
83                         float rdelta, bdelta, gdelta;
84                         
85                         rdelta = newcolor.get_red() - c.get_red();
86                         bdelta = newcolor.get_blue() - c.get_blue();
87                         gdelta = newcolor.get_green() - c.get_green();
88
89                         if (sqrt (rdelta*rdelta + bdelta*bdelta + gdelta*gdelta) > 25.0) {
90                                 used_colors.push_back (newcolor);
91                                 return newcolor;
92                         }
93                 }
94
95                 /* XXX need throttle here to make sure we don't spin for ever */
96         }
97 }