Remove attempt to retrieve invalid Meterbridge properties
[ardour.git] / gtk2_ardour / ui_config.cc
1 /*
2     Copyright (C) 1999-2014 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 #if !defined USE_CAIRO_IMAGE_SURFACE && !defined NDEBUG
21 #define OPTIONAL_CAIRO_IMAGE_SURFACE
22 #endif
23
24 #include <iostream>
25 #include <sstream>
26 #include <unistd.h>
27 #include <cstdlib>
28 #include <cstdio> /* for snprintf, grrr */
29
30 #include <cairo/cairo.h>
31
32 #include <pango/pangoft2.h> // for fontmap resolution control for GnomeCanvas
33 #include <pango/pangocairo.h> // for fontmap resolution control for GnomeCanvas
34
35 #include <glibmm/miscutils.h>
36
37 #include <gtkmm/settings.h>
38
39 #include "pbd/convert.h"
40 #include "pbd/error.h"
41 #include "pbd/failed_constructor.h"
42 #include "pbd/file_utils.h"
43 #include "pbd/gstdio_compat.h"
44 #include "pbd/locale_guard.h"
45 #include "pbd/unwind.h"
46 #include "pbd/xml++.h"
47
48 #include "ardour/filesystem_paths.h"
49 #include "ardour/search_paths.h"
50 #include "ardour/revision.h"
51 #include "ardour/utils.h"
52 #include "ardour/types_convert.h"
53
54 #include "gtkmm2ext/rgb_macros.h"
55 #include "gtkmm2ext/gtk_ui.h"
56
57 #include "ui_config.h"
58
59 #include "pbd/i18n.h"
60
61 using namespace std;
62 using namespace PBD;
63 using namespace ARDOUR;
64 using namespace ArdourCanvas;
65
66 static const char* ui_config_file_name = "ui_config";
67 static const char* default_ui_config_file_name = "default_ui_config";
68
69 static const double hue_width = 18.0;
70 std::string UIConfiguration::color_file_suffix = X_(".colors");
71
72 UIConfiguration&
73 UIConfiguration::instance ()
74 {
75         static UIConfiguration s_instance;
76         return s_instance;
77 }
78
79 UIConfiguration::UIConfiguration ()
80         :
81 #undef  UI_CONFIG_VARIABLE
82 #define UI_CONFIG_VARIABLE(Type,var,name,val) var (name,val),
83 #define CANVAS_FONT_VARIABLE(var,name) var (name),
84 #include "ui_config_vars.h"
85 #include "canvas_vars.h"
86 #undef  UI_CONFIG_VARIABLE
87 #undef  CANVAS_FONT_VARIABLE
88
89         _dirty (false),
90         aliases_modified (false),
91         colors_modified (false),
92         modifiers_modified (false),
93         block_save (0)
94 {
95         load_state();
96
97         ColorsChanged.connect (boost::bind (&UIConfiguration::colors_changed, this));
98
99         ParameterChanged.connect (sigc::mem_fun (*this, &UIConfiguration::parameter_changed));
100 }
101
102 UIConfiguration::~UIConfiguration ()
103 {
104 }
105
106 void
107 UIConfiguration::colors_changed ()
108 {
109         reset_gtk_theme ();
110
111         /* In theory, one of these ought to work:
112
113            gtk_rc_reparse_all_for_settings (gtk_settings_get_default(), true);
114            gtk_rc_reset_styles (gtk_settings_get_default());
115
116            but in practice, neither of them do. So just reload the current
117            GTK RC file, which causes a reset of all styles and a redraw
118         */
119
120         parameter_changed ("ui-rc-file");
121 }
122
123 void
124 UIConfiguration::parameter_changed (string param)
125 {
126         _dirty = true;
127
128         if (param == "ui-rc-file") {
129                 load_rc_file (true);
130         } else if (param == "color-file") {
131                 load_color_theme (true);
132         }
133
134         save_state ();
135 }
136
137 void
138 UIConfiguration::reset_gtk_theme ()
139 {
140         LocaleGuard lg;
141         std::string color_scheme_string("gtk_color_scheme = \"");
142
143         for (ColorAliases::iterator g = color_aliases.begin(); g != color_aliases.end(); ++g) {
144
145                 if (g->first.find ("gtk_") == 0) {
146                         const string gtk_name = g->first.substr (4);
147                         ArdourCanvas::Color a_color = color (g->second);
148
149                         color_scheme_string += gtk_name + ":#" + color_to_hex_string_no_alpha (a_color) + ';';
150                 }
151         }
152
153         color_scheme_string += '"';
154
155         /* reset GTK color scheme */
156
157         Gtk::Settings::get_default()->property_gtk_color_scheme() = color_scheme_string;
158 }
159
160 void
161 UIConfiguration::reset_dpi ()
162 {
163         long val = get_font_scale();
164
165         /* FT2 rendering - used by GnomeCanvas, sigh */
166
167 #ifndef PLATFORM_WINDOWS
168         pango_ft2_font_map_set_resolution ((PangoFT2FontMap*) pango_ft2_font_map_new(), val/1024, val/1024); // XXX pango_ft2_font_map_new leaks
169 #endif
170
171         /* Cairo rendering, in case there is any */
172
173         pango_cairo_font_map_set_resolution ((PangoCairoFontMap*) pango_cairo_font_map_get_default(), val/1024);
174
175         /* Xft rendering */
176
177         gtk_settings_set_long_property (gtk_settings_get_default(),
178                                         "gtk-xft-dpi", val, "ardour");
179         DPIReset(); //Emit Signal
180 }
181
182 float
183 UIConfiguration::get_ui_scale ()
184 {
185         return get_font_scale () / 102400.;
186 }
187
188 void
189 UIConfiguration::map_parameters (boost::function<void (std::string)>& functor)
190 {
191 #undef  UI_CONFIG_VARIABLE
192 #define UI_CONFIG_VARIABLE(Type,var,Name,value) functor (Name);
193 #include "ui_config_vars.h"
194 #undef  UI_CONFIG_VARIABLE
195 }
196
197 int
198 UIConfiguration::pre_gui_init ()
199 {
200 #ifdef CAIRO_SUPPORTS_FORCE_BUGGY_GRADIENTS_ENVIRONMENT_VARIABLE
201         if (get_buggy_gradients()) {
202                 g_setenv ("FORCE_BUGGY_GRADIENTS", "1", 1);
203         }
204 #endif
205 #ifdef OPTIONAL_CAIRO_IMAGE_SURFACE
206         if (get_cairo_image_surface()) {
207                 g_setenv ("ARDOUR_IMAGE_SURFACE", "1", 1);
208         }
209 #endif
210         return 0;
211 }
212
213 UIConfiguration*
214 UIConfiguration::post_gui_init ()
215 {
216         load_color_theme (true);
217         return this;
218 }
219
220 int
221 UIConfiguration::load_defaults ()
222 {
223         std::string rcfile;
224         int ret = -1;
225
226         if (find_file (ardour_config_search_path(), default_ui_config_file_name, rcfile) ) {
227                 XMLTree tree;
228
229                 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endmsg;
230
231                 if (!tree.read (rcfile.c_str())) {
232                         error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
233                 } else {
234                         if (set_state (*tree.root(), Stateful::loading_state_version)) {
235                                 error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
236                         } else {
237                                 _dirty = false;
238                                 ret = 0;
239                         }
240                 }
241
242         } else {
243                 warning << string_compose (_("Could not find default UI configuration file %1"), default_ui_config_file_name) << endmsg;
244         }
245
246         if (ret == 0) {
247                 /* reload color theme */
248                 load_color_theme (false);
249         }
250
251         return ret;
252 }
253
254 std::string
255 UIConfiguration::color_file_name (bool use_my, bool with_version) const
256 {
257         string basename;
258
259         if (use_my) {
260                 basename += "my-";
261         }
262
263         std::string color_name = color_file.get();
264         size_t sep = color_name.find_first_of("-");
265         if (sep != string::npos) {
266                 color_name = color_name.substr (0, sep);
267         }
268
269         basename += color_name;
270         basename += "-";
271         basename += downcase(std::string(PROGRAM_NAME));
272
273         std::string rev (revision);
274         std::size_t pos = rev.find_first_of("-");
275
276         if (with_version && pos != string::npos && pos > 0) {
277                 basename += "-";
278                 basename += rev.substr (0, pos); // COLORFILE_VERSION - program major.minor
279         }
280
281         basename += color_file_suffix;
282         return basename;
283 }
284
285 int
286 UIConfiguration::load_color_file (string const & path)
287 {
288         XMLTree tree;
289
290         info << string_compose (_("Loading color file %1"), path) << endmsg;
291
292         if (!tree.read (path.c_str())) {
293                 error << string_compose(_("cannot read color file \"%1\""), path) << endmsg;
294                 return -1;
295         }
296
297         if (set_state (*tree.root(), Stateful::loading_state_version)) {
298                 error << string_compose(_("color file \"%1\" not loaded successfully."), path) << endmsg;
299                 return -1;
300         }
301
302         return 0;
303 }
304
305 int
306 UIConfiguration::load_color_theme (bool allow_own)
307 {
308         std::string cfile;
309         bool found = false;
310         /* ColorsChanged() will trigger a  parameter_changed () which
311          * in turn calls save_state()
312          */
313         PBD::Unwinder<uint32_t> uw (block_save, block_save + 1);
314
315         if (find_file (theme_search_path(), color_file_name (false, true), cfile)) {
316                 found = true;
317         }
318
319         if (!found) {
320                 if (find_file (theme_search_path(), color_file_name (false, false), cfile)) {
321                         found = true;
322                 }
323         }
324
325         if (!found) {
326                 warning << string_compose (_("Color file for %1 not found along %2"), color_file.get(), theme_search_path().to_string()) << endmsg;
327                 return -1;
328         }
329
330         (void) load_color_file (cfile);
331
332         if (allow_own) {
333
334                 found = false;
335
336                 PBD::Searchpath sp (user_config_directory());
337
338                 /* user's own color files never have the program name in them */
339
340                 if (find_file (sp, color_file_name (true, true), cfile)) {
341                         found = true;
342                 }
343
344                 if (!found) {
345                         if (find_file (sp, color_file_name (true, false), cfile)) {
346                                 found = true;
347                         }
348                 }
349
350                 if (found) {
351                         (void) load_color_file (cfile);
352                 }
353
354         }
355
356         ColorsChanged ();
357
358         return 0;
359 }
360
361 int
362 UIConfiguration::store_color_theme ()
363 {
364         XMLNode* root;
365         LocaleGuard lg;
366
367         root = new XMLNode("Ardour");
368
369         XMLNode* parent = new XMLNode (X_("Colors"));
370         for (Colors::const_iterator i = colors.begin(); i != colors.end(); ++i) {
371                 XMLNode* node = new XMLNode (X_("Color"));
372                 node->set_property (X_("name"), i->first);
373                 node->set_property (X_("value"), color_to_hex_string (i->second));
374                 parent->add_child_nocopy (*node);
375         }
376         root->add_child_nocopy (*parent);
377
378         parent = new XMLNode (X_("ColorAliases"));
379         for (ColorAliases::const_iterator i = color_aliases.begin(); i != color_aliases.end(); ++i) {
380                 XMLNode* node = new XMLNode (X_("ColorAlias"));
381                 node->set_property (X_("name"), i->first);
382                 node->set_property (X_("alias"), i->second);
383                 parent->add_child_nocopy (*node);
384         }
385         root->add_child_nocopy (*parent);
386
387         parent = new XMLNode (X_("Modifiers"));
388         for (Modifiers::const_iterator i = modifiers.begin(); i != modifiers.end(); ++i) {
389                 XMLNode* node = new XMLNode (X_("Modifier"));
390                 node->set_property (X_("name"), i->first);
391                 node->set_property (X_("modifier"), i->second.to_string());
392                 parent->add_child_nocopy (*node);
393         }
394         root->add_child_nocopy (*parent);
395
396         XMLTree tree;
397         std::string colorfile = Glib::build_filename (user_config_directory(), color_file_name (true, true));;
398
399         tree.set_root (root);
400
401         if (!tree.write (colorfile.c_str())){
402                 error << string_compose (_("Color file %1 not saved"), colorfile) << endmsg;
403                 return -1;
404         }
405
406         return 0;
407 }
408
409 int
410 UIConfiguration::load_state ()
411 {
412         LocaleGuard lg; // a single guard for all 3 configs
413         bool found = false;
414
415         std::string rcfile;
416
417         if (find_file (ardour_config_search_path(), default_ui_config_file_name, rcfile)) {
418                 XMLTree tree;
419                 found = true;
420
421                 info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endmsg;
422
423                 if (!tree.read (rcfile.c_str())) {
424                         error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
425                         return -1;
426                 }
427
428                 if (set_state (*tree.root(), Stateful::loading_state_version)) {
429                         error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
430                         return -1;
431                 }
432         }
433
434         if (find_file (ardour_config_search_path(), ui_config_file_name, rcfile)) {
435                 XMLTree tree;
436                 found = true;
437
438                 info << string_compose (_("Loading user ui configuration file %1"), rcfile) << endmsg;
439
440                 if (!tree.read (rcfile)) {
441                         error << string_compose(_("cannot read ui configuration file \"%1\""), rcfile) << endmsg;
442                         return -1;
443                 }
444
445                 if (set_state (*tree.root(), Stateful::loading_state_version)) {
446                         error << string_compose(_("user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
447                         return -1;
448                 }
449
450                 _dirty = false;
451         }
452
453         if (!found) {
454                 error << _("could not find any ui configuration file, canvas will look broken.") << endmsg;
455         }
456
457         return 0;
458 }
459
460 int
461 UIConfiguration::save_state()
462 {
463         if (block_save != 0) {
464                 return -1;
465         }
466
467         if (_dirty) {
468                 std::string rcfile = Glib::build_filename (user_config_directory(), ui_config_file_name);
469
470                 XMLTree tree;
471
472                 tree.set_root (&get_state());
473
474                 if (!tree.write (rcfile.c_str())){
475                         error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
476                         return -1;
477                 }
478
479                 _dirty = false;
480         }
481
482         if (aliases_modified || colors_modified || modifiers_modified) {
483
484                 if (store_color_theme ()) {
485                         error << string_compose (_("Color file %1 not saved"), color_file.get()) << endmsg;
486                         return -1;
487                 }
488
489                 aliases_modified = false;
490                 colors_modified = false;
491                 modifiers_modified = false;
492         }
493
494
495         return 0;
496 }
497
498 XMLNode&
499 UIConfiguration::get_state ()
500 {
501         XMLNode* root;
502         LocaleGuard lg;
503
504         root = new XMLNode("Ardour");
505
506         root->add_child_nocopy (get_variables ("UI"));
507         root->add_child_nocopy (get_variables ("Canvas"));
508
509         if (_extra_xml) {
510                 root->add_child_copy (*_extra_xml);
511         }
512
513         return *root;
514 }
515
516 XMLNode&
517 UIConfiguration::get_variables (std::string which_node)
518 {
519         XMLNode* node;
520         LocaleGuard lg;
521
522         node = new XMLNode (which_node);
523
524 #undef  UI_CONFIG_VARIABLE
525 #undef  CANVAS_FONT_VARIABLE
526 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
527 #define CANVAS_FONT_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
528 #include "ui_config_vars.h"
529 #include "canvas_vars.h"
530 #undef  UI_CONFIG_VARIABLE
531 #undef  CANVAS_FONT_VARIABLE
532
533         return *node;
534 }
535
536 int
537 UIConfiguration::set_state (const XMLNode& root, int /*version*/)
538 {
539         LocaleGuard lg;
540         /* this can load a generic UI configuration file or a colors file */
541
542         if (root.name() != "Ardour") {
543                 return -1;
544         }
545
546         Stateful::save_extra_xml (root);
547
548         XMLNodeList nlist = root.children();
549         XMLNodeConstIterator niter;
550         XMLNode *node;
551
552         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
553
554                 node = *niter;
555
556                 if (node->name() == "Canvas" ||  node->name() == "UI") {
557                         set_variables (*node);
558
559                 }
560         }
561
562         XMLNode* colors = find_named_node (root, X_("Colors"));
563
564         if (colors) {
565                 load_colors (*colors);
566         }
567
568         XMLNode* aliases = find_named_node (root, X_("ColorAliases"));
569
570         if (aliases) {
571                 load_color_aliases (*aliases);
572         }
573
574         XMLNode* modifiers = find_named_node (root, X_("Modifiers"));
575
576         if (modifiers) {
577                 load_modifiers (*modifiers);
578         }
579
580         return 0;
581 }
582
583 void
584 UIConfiguration::load_color_aliases (XMLNode const & node)
585 {
586         XMLNodeList const nlist = node.children();
587         XMLNodeConstIterator niter;
588         XMLProperty const *name;
589         XMLProperty const *alias;
590
591         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
592                 XMLNode const * child = *niter;
593                 if (child->name() != X_("ColorAlias")) {
594                         continue;
595                 }
596                 name = child->property (X_("name"));
597                 alias = child->property (X_("alias"));
598
599                 if (name && alias) {
600                         color_aliases[name->value()] = alias->value();
601                 }
602         }
603 }
604
605 void
606 UIConfiguration::load_colors (XMLNode const & node)
607 {
608         XMLNodeList const nlist = node.children();
609         XMLNodeConstIterator niter;
610         XMLProperty const *name;
611         XMLProperty const *color;
612
613         /* don't clear colors, so that we can load > 1 color file and have
614            the subsequent ones overwrite the later ones.
615         */
616
617         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
618                 XMLNode const * child = *niter;
619                 if (child->name() != X_("Color")) {
620                         continue;
621                 }
622                 name = child->property (X_("name"));
623                 color = child->property (X_("value"));
624
625                 if (name && color) {
626                         ArdourCanvas::Color c;
627                         c = strtoul (color->value().c_str(), 0, 16);
628                         /* insert or replace color name definition */
629                         colors[name->value()] =  c;
630                 }
631         }
632 }
633
634 void
635 UIConfiguration::load_modifiers (XMLNode const & node)
636 {
637         PBD::LocaleGuard lg;
638         XMLNodeList const nlist = node.children();
639         XMLNodeConstIterator niter;
640         XMLProperty const *name;
641         XMLProperty const *mod;
642
643         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
644                 XMLNode const * child = *niter;
645                 if (child->name() != X_("Modifier")) {
646                         continue;
647                 }
648
649                 name = child->property (X_("name"));
650                 mod = child->property (X_("modifier"));
651
652                 if (name && mod) {
653                         SVAModifier svam (mod->value());
654                         modifiers[name->value()] = svam;
655                 }
656         }
657 }
658
659 void
660 UIConfiguration::set_variables (const XMLNode& node)
661 {
662 #undef  UI_CONFIG_VARIABLE
663 #define UI_CONFIG_VARIABLE(Type,var,name,val) if (var.set_from_node (node)) { ParameterChanged (name); }
664 #define CANVAS_FONT_VARIABLE(var,name)        if (var.set_from_node (node)) { ParameterChanged (name); }
665 #include "ui_config_vars.h"
666 #include "canvas_vars.h"
667 #undef  UI_CONFIG_VARIABLE
668 #undef  CANVAS_FONT_VARIABLE
669 }
670
671 ArdourCanvas::SVAModifier
672 UIConfiguration::modifier (string const & name) const
673 {
674         Modifiers::const_iterator m = modifiers.find (name);
675         if (m != modifiers.end()) {
676                 return m->second;
677         }
678         return SVAModifier ();
679 }
680
681 ArdourCanvas::Color
682 UIConfiguration::color_mod (std::string const & colorname, std::string const & modifiername) const
683 {
684         return HSV (color (colorname)).mod (modifier (modifiername)).color ();
685 }
686
687 ArdourCanvas::Color
688 UIConfiguration::color_mod (const ArdourCanvas::Color& color, std::string const & modifiername) const
689 {
690         return HSV (color).mod (modifier (modifiername)).color ();
691 }
692
693 ArdourCanvas::Color
694 UIConfiguration::color (const std::string& name, bool* failed) const
695 {
696         ColorAliases::const_iterator e = color_aliases.find (name);
697
698         if (failed) {
699                 *failed = false;
700         }
701
702         if (e != color_aliases.end ()) {
703                 Colors::const_iterator rc = colors.find (e->second);
704                 if (rc != colors.end()) {
705                         return rc->second;
706                 }
707         } else {
708                 /* not an alias, try directly */
709                 Colors::const_iterator rc = colors.find (name);
710                 if (rc != colors.end()) {
711                         return rc->second;
712                 }
713         }
714
715         if (!failed) {
716                 /* only show this message if the caller wasn't interested in
717                    the fail status.
718                 */
719                 cerr << string_compose (_("Color %1 not found"), name) << endl;
720         }
721
722         if (failed) {
723                 *failed = true;
724         }
725
726         return rgba_to_color ((g_random_int()%256)/255.0,
727                               (g_random_int()%256)/255.0,
728                               (g_random_int()%256)/255.0,
729                               0xff);
730 }
731
732 Color
733 UIConfiguration::quantized (Color c) const
734 {
735         HSV hsv (c);
736         hsv.h = hue_width * (round (hsv.h/hue_width));
737         return hsv.color ();
738 }
739
740 void
741 UIConfiguration::set_color (string const& name, ArdourCanvas::Color color)
742 {
743         Colors::iterator i = colors.find (name);
744         if (i == colors.end()) {
745                 return;
746         }
747         i->second = color;
748         colors_modified = true;
749
750         ColorsChanged (); /* EMIT SIGNAL */
751 }
752
753 void
754 UIConfiguration::set_alias (string const & name, string const & alias)
755 {
756         ColorAliases::iterator i = color_aliases.find (name);
757         if (i == color_aliases.end()) {
758                 return;
759         }
760
761         i->second = alias;
762         aliases_modified = true;
763
764         ColorsChanged (); /* EMIT SIGNAL */
765 }
766
767 void
768 UIConfiguration::set_modifier (string const & name, SVAModifier svam)
769 {
770         Modifiers::iterator m = modifiers.find (name);
771
772         if (m == modifiers.end()) {
773                 return;
774         }
775
776         m->second = svam;
777         modifiers_modified = true;
778
779         ColorsChanged (); /* EMIT SIGNAL */
780 }
781
782 void
783 UIConfiguration::load_rc_file (bool themechange, bool allow_own)
784 {
785         string basename = ui_rc_file.get();
786         std::string rc_file_path;
787
788         if (!find_file (ardour_config_search_path(), basename, rc_file_path)) {
789                 warning << string_compose (_("Unable to find UI style file %1 in search path %2. %3 will look strange"),
790                                            basename, ardour_config_search_path().to_string(), PROGRAM_NAME)
791                                 << endmsg;
792                 return;
793         }
794
795         info << "Loading ui configuration file " << rc_file_path << endmsg;
796
797         Gtkmm2ext::UI::instance()->load_rcfile (rc_file_path, themechange);
798 }
799
800 std::string
801 UIConfiguration::color_to_hex_string (ArdourCanvas::Color c)
802 {
803         char buf[16];
804         int retval = g_snprintf (buf, sizeof(buf), "%08x", c);
805
806         if (retval < 0 || retval >= (int)sizeof(buf)) {
807                 assert(false);
808         }
809         return buf;
810 }
811
812 std::string
813 UIConfiguration::color_to_hex_string_no_alpha (ArdourCanvas::Color c)
814 {
815         c >>= 8; // shift/remove alpha
816         char buf[16];
817         int retval = g_snprintf (buf, sizeof(buf), "%06x", c);
818
819         if (retval < 0 || retval >= (int)sizeof(buf)) {
820                 assert(false);
821         }
822         return buf;
823 }