X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fui_config.cc;h=354539b57b07cadfe446a7299bea55171b5b617e;hb=3dc7728038860bda6eb4b0de1f4a3e14ec9e86cc;hp=28d7fcc392dea1c235684e539c14abeecc2ba5f7;hpb=318a9edab99606d7fbf7eb21d816c7416c76b894;p=ardour.git diff --git a/gtk2_ardour/ui_config.cc b/gtk2_ardour/ui_config.cc index 28d7fcc392..354539b57b 100644 --- a/gtk2_ardour/ui_config.cc +++ b/gtk2_ardour/ui_config.cc @@ -17,23 +17,40 @@ */ +#if !defined USE_CAIRO_IMAGE_SURFACE && !defined NDEBUG +#define OPTIONAL_CAIRO_IMAGE_SURFACE +#endif + +#include +#include #include #include #include /* for snprintf, grrr */ +#include + +#include // for fontmap resolution control for GnomeCanvas +#include // for fontmap resolution control for GnomeCanvas + +#include "pbd/gstdio_compat.h" #include +#include + +#include "pbd/convert.h" #include "pbd/failed_constructor.h" #include "pbd/xml++.h" #include "pbd/file_utils.h" +#include "pbd/locale_guard.h" #include "pbd/error.h" +#include "pbd/stacktrace.h" #include "gtkmm2ext/rgb_macros.h" +#include "gtkmm2ext/gtk_ui.h" #include "ardour/filesystem_paths.h" +#include "ardour/utils.h" -#include "ardour_ui.h" -#include "global_signals.h" #include "ui_config.h" #include "i18n.h" @@ -45,582 +62,128 @@ using namespace ArdourCanvas; static const char* ui_config_file_name = "ui_config"; static const char* default_ui_config_file_name = "default_ui_config"; -UIConfiguration* UIConfiguration::_instance = 0; -static std::map full_palette; -static const double hue_cnt = 18.0; +static const double hue_width = 18.0; +UIConfiguration& +UIConfiguration::instance () +{ + static UIConfiguration s_instance; + return s_instance; +} UIConfiguration::UIConfiguration () : #undef UI_CONFIG_VARIABLE #define UI_CONFIG_VARIABLE(Type,var,name,val) var (name,val), -#define CANVAS_STRING_VARIABLE(var,name) var (name), #define CANVAS_FONT_VARIABLE(var,name) var (name), #include "ui_config_vars.h" #include "canvas_vars.h" #undef UI_CONFIG_VARIABLE -#undef CANVAS_STRING_VARIABLE #undef CANVAS_FONT_VARIABLE - /* initialize all the base colors using default - colors for now. these will be reset when/if - we load the UI config file. - */ + _dirty (false), + aliases_modified (false), + colors_modified (false), + modifiers_modified (false), + block_save (0) +{ + load_state(); -#undef CANVAS_BASE_COLOR -#define CANVAS_BASE_COLOR(var,name,val) var (name,val), -#include "base_colors.h" -#undef CANVAS_BASE_COLOR + ColorsChanged.connect (boost::bind (&UIConfiguration::colors_changed, this)); -#undef CANVAS_COLOR -#define CANVAS_COLOR(var,name,base,modifier) var (base,modifier), -#include "colors.h" -#undef CANVAS_COLOR + ParameterChanged.connect (sigc::mem_fun (*this, &UIConfiguration::parameter_changed)); +} - _dirty (false) +UIConfiguration::~UIConfiguration () { - _instance = this; +} - /* pack all base colors into the configurable color map so that - derived colors can use them. - */ - -#undef CANVAS_BASE_COLOR -#define CANVAS_BASE_COLOR(var,name,color) configurable_colors.insert (make_pair (name,&var)); -#include "base_colors.h" -#undef CANVAS_BASE_COLOR - -#undef CANVAS_COLOR -#define CANVAS_COLOR(var,name,base,modifier) relative_colors.insert (make_pair (name,var)); -#include "colors.h" -#undef CANVAS_COLOR - - /* load up full palette with opposites */ - - map*>::iterator f; - - for (f = configurable_colors.begin(); f != configurable_colors.end(); ++f) { - /* first the base tone */ - full_palette.insert (make_pair (f->first, HSV (f->second->get()))); - /* now its opposite */ - // full_palette.insert (make_pair (f->first + " opposite", HSV (f->second->get()) + HSV(180.0, 0, 0))); - } +void +UIConfiguration::colors_changed () +{ + reset_gtk_theme (); - /* now quantize the hues */ + /* In theory, one of these ought to work: - for (map::iterator fp = full_palette.begin(); fp != full_palette.end(); ++fp) { - fp->second.h = hue_cnt * (round (fp->second.h/hue_cnt)); - } + gtk_rc_reparse_all_for_settings (gtk_settings_get_default(), true); + gtk_rc_reset_styles (gtk_settings_get_default()); - load_state(); + but in practice, neither of them do. So just reload the current + GTK RC file, which causes a reset of all styles and a redraw + */ + + parameter_changed ("ui-rc-file"); +} - // original_colors (); +void +UIConfiguration::parameter_changed (string param) +{ + _dirty = true; - color_compute (); + if (param == "ui-rc-file") { + load_rc_file (true); + } else if (param == "color-file") { + load_color_theme (); + } - ARDOUR_UI_UTILS::ColorsChanged.connect (boost::bind (&UIConfiguration::color_theme_changed, this)); + save_state (); } -UIConfiguration::~UIConfiguration () +void +UIConfiguration::reset_gtk_theme () { + stringstream ss; + + ss << "gtk_color_scheme = \"" << hex; + + for (ColorAliases::iterator g = color_aliases.begin(); g != color_aliases.end(); ++g) { + + if (g->first.find ("gtk_") == 0) { + const string gtk_name = g->first.substr (4); + ss << gtk_name << ":#" << std::setw (6) << setfill ('0') << (color (g->second) >> 8) << ';'; + } + } + + ss << '"' << dec << endl; + + /* reset GTK color scheme */ + + Gtk::Settings::get_default()->property_gtk_color_scheme() = ss.str(); } -void -UIConfiguration::original_colors () +void +UIConfiguration::reset_dpi () { - map c; - c.insert (make_pair ("active crossfade", HSV (0x20b2af2e))); - c.insert (make_pair ("arrange base", HSV (0x595959ff))); - c.insert (make_pair ("audio bus base", HSV (0x73829968))); - c.insert (make_pair ("audio master bus base", HSV (0x00000000))); - c.insert (make_pair ("audio track base", HSV (0x9daac468))); - c.insert (make_pair ("automation line", HSV (0x44bc59ff))); - c.insert (make_pair ("automation track fill", HSV (0xa0a0ce68))); - c.insert (make_pair ("automation track outline", HSV (0x282828ff))); - c.insert (make_pair ("cd marker bar", HSV (0x9496a3cc))); - c.insert (make_pair ("crossfade editor base", HSV (0x282d49ff))); - c.insert (make_pair ("crossfade editor line", HSV (0x000000ff))); - c.insert (make_pair ("crossfade editor line shading", HSV (0x00a0d154))); - c.insert (make_pair ("crossfade editor point fill", HSV (0x00ff00ff))); - c.insert (make_pair ("crossfade editor point outline", HSV (0x0000ffff))); - c.insert (make_pair ("crossfade editor wave", HSV (0xffffff28))); - c.insert (make_pair ("selected crossfade editor wave fill", HSV (0x00000000))); - c.insert (make_pair ("crossfade line", HSV (0x000000ff))); - c.insert (make_pair ("edit point", HSV (0x0000ffff))); - c.insert (make_pair ("entered automation line", HSV (0xdd6363ff))); - c.insert (make_pair ("control point fill", HSV (0xffffff66))); - c.insert (make_pair ("control point outline", HSV (0xff0000ee))); - c.insert (make_pair ("control point selected", HSV (0x55ccccff))); - c.insert (make_pair ("entered gain line", HSV (0xdd6363ff))); - c.insert (make_pair ("entered marker", HSV (0xdd6363ff))); - c.insert (make_pair ("frame handle", HSV (0x7c00ff96))); - c.insert (make_pair ("gain line", HSV (0x00bc20ff))); - c.insert (make_pair ("gain line inactive", HSV (0x9fbca4c5))); - c.insert (make_pair ("ghost track base", HSV (0x603e7cc6))); - c.insert (make_pair ("ghost track midi outline", HSV (0x00000000))); - c.insert (make_pair ("ghost track wave", HSV (0x202020d9))); - c.insert (make_pair ("ghost track wave fill", HSV (0x20202060))); - c.insert (make_pair ("ghost track wave clip", HSV (0x202020d9))); - c.insert (make_pair ("ghost track zero line", HSV (0xe500e566))); - c.insert (make_pair ("image track", HSV (0xddddd8ff))); - c.insert (make_pair ("inactive crossfade", HSV (0xe8ed3d77))); - c.insert (make_pair ("inactive fade handle", HSV (0xbbbbbbaa))); - c.insert (make_pair ("inactive group tab", HSV (0x434343ff))); - c.insert (make_pair ("location cd marker", HSV (0x1ee8c4ff))); - c.insert (make_pair ("location loop", HSV (0x35964fff))); - c.insert (make_pair ("location marker", HSV (0xc4f411ff))); - c.insert (make_pair ("location punch", HSV (0x7c3a3aff))); - c.insert (make_pair ("location range", HSV (0x497a59ff))); - c.insert (make_pair ("marker bar", HSV (0x99a1adcc))); - c.insert (make_pair ("marker bar separator", HSV (0x555555ff))); - c.insert (make_pair ("marker drag line", HSV (0x004f00f9))); - c.insert (make_pair ("marker label", HSV (0x000000ff))); - c.insert (make_pair ("marker track", HSV (0xddddd8ff))); - c.insert (make_pair ("measure line bar", HSV (0xffffff9c))); - c.insert (make_pair ("measure line beat", HSV (0xa29e9e76))); - c.insert (make_pair ("meter bar", HSV (0x626470cc))); - c.insert (make_pair ("meter fill: 0", HSV (0x008800ff))); - c.insert (make_pair ("meter fill: 1", HSV (0x00aa00ff))); - c.insert (make_pair ("meter fill: 2", HSV (0x00ff00ff))); - c.insert (make_pair ("meter fill: 3", HSV (0x00ff00ff))); - c.insert (make_pair ("meter fill: 4", HSV (0xfff000ff))); - c.insert (make_pair ("meter fill: 5", HSV (0xfff000ff))); - c.insert (make_pair ("meter fill: 6", HSV (0xff8000ff))); - c.insert (make_pair ("meter fill: 7", HSV (0xff8000ff))); - c.insert (make_pair ("meter fill: 8", HSV (0xff0000ff))); - c.insert (make_pair ("meter fill: 9", HSV (0xff0000ff))); - c.insert (make_pair ("meter background: bottom", HSV (0x333333ff))); - c.insert (make_pair ("meter background: top", HSV (0x444444ff))); - c.insert (make_pair ("midi meter fill: 0", HSV (0xeffaa1ff))); - c.insert (make_pair ("midi meter fill: 1", HSV (0xf2c97dff))); - c.insert (make_pair ("midi meter fill: 2", HSV (0xf2c97dff))); - c.insert (make_pair ("midi meter fill: 3", HSV (0xf48f52ff))); - c.insert (make_pair ("midi meter fill: 4", HSV (0xf48f52ff))); - c.insert (make_pair ("midi meter fill: 5", HSV (0xf83913ff))); - c.insert (make_pair ("midi meter fill: 6", HSV (0xf83913ff))); - c.insert (make_pair ("midi meter fill: 7", HSV (0x8fc78eff))); - c.insert (make_pair ("midi meter fill: 8", HSV (0x8fc78eff))); - c.insert (make_pair ("midi meter fill: 9", HSV (0x00f45600))); - c.insert (make_pair ("meterbridge peakindicator: fill", HSV (0x444444ff))); - c.insert (make_pair ("meterbridge peakindicator: fill active", HSV (0xff0000ff))); - c.insert (make_pair ("meterbridge label: fill", HSV (0x444444ff))); - c.insert (make_pair ("meterbridge label: fill active", HSV (0x333333ff))); - c.insert (make_pair ("meterbridge label: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("meter marker", HSV (0xf2425bff))); - c.insert (make_pair ("midi bus base", HSV (0x00000000))); - c.insert (make_pair ("midi frame base", HSV (0x393d3766))); - c.insert (make_pair ("midi note inactive channel", HSV (0x00000000))); - c.insert (make_pair ("midi note color min", HSV (0x3f542aff))); - c.insert (make_pair ("midi note color mid", HSV (0x7ea854ff))); - c.insert (make_pair ("midi note color max", HSV (0xbfff80ff))); - c.insert (make_pair ("selected midi note color min", HSV (0x1e1e33ff))); - c.insert (make_pair ("selected midi note color mid", HSV (0x51518aff))); - c.insert (make_pair ("selected midi note color max", HSV (0x8383deff))); - c.insert (make_pair ("midi note selected", HSV (0xb2b2ffff))); - c.insert (make_pair ("midi note velocity text", HSV (0xf4f214bc))); - c.insert (make_pair ("midi patch change fill", HSV (0x50555aa0))); - c.insert (make_pair ("midi patch change outline", HSV (0xc0c5caff))); - c.insert (make_pair ("midi patch change inactive channel fill", HSV (0x50555ac0))); - c.insert (make_pair ("midi patch change inactive channel outline", HSV (0x20252ac0))); - c.insert (make_pair ("midi sysex fill", HSV (0xf1e139a0))); - c.insert (make_pair ("midi sysex outline", HSV (0xa7a7d4ff))); - c.insert (make_pair ("midi select rect fill", HSV (0x8888ff88))); - c.insert (make_pair ("midi select rect outline", HSV (0x5555ffff))); - c.insert (make_pair ("midi track base", HSV (0xb3cca35f))); - c.insert (make_pair ("name highlight fill", HSV (0x0000ffff))); - c.insert (make_pair ("name highlight outline", HSV (0x7c00ff96))); - c.insert (make_pair ("piano roll black outline", HSV (0xf4f4f476))); - c.insert (make_pair ("piano roll black", HSV (0x6c6e6a6b))); - c.insert (make_pair ("piano roll white", HSV (0x979b9565))); - c.insert (make_pair ("play head", HSV (0xff0000ff))); - c.insert (make_pair ("processor automation line", HSV (0x7aa3f9ff))); - c.insert (make_pair ("punch line", HSV (0xa80000ff))); - c.insert (make_pair ("range drag bar rect", HSV (0x969696c6))); - c.insert (make_pair ("range drag rect", HSV (0x82c696c6))); - c.insert (make_pair ("range marker bar", HSV (0x7d7f8ccc))); - c.insert (make_pair ("recording rect", HSV (0xcc2828ff))); - c.insert (make_pair ("recorded waveform fill", HSV (0xffffffd9))); - c.insert (make_pair ("recorded waveform outline", HSV (0x0f0f1fff))); - c.insert (make_pair ("rubber band rect", HSV (0xc6c6c659))); - c.insert (make_pair ("ruler base", HSV (0x2c2121ff))); - c.insert (make_pair ("ruler text", HSV (0xe5e5e5ff))); - c.insert (make_pair ("selected crossfade editor line", HSV (0x00dbdbff))); - c.insert (make_pair ("selected crossfade editor wave", HSV (0xf9ea14a0))); - c.insert (make_pair ("selected region base", HSV (0x585c61ff))); - c.insert (make_pair ("selected waveform fill", HSV (0xffa500d9))); - c.insert (make_pair ("selected waveform outline", HSV (0x0f0f0fcc))); - c.insert (make_pair ("selection rect", HSV (0xe8f4d377))); - c.insert (make_pair ("selection", HSV (0x636363b2))); - c.insert (make_pair ("shuttle", HSV (0x6bb620ff))); - c.insert (make_pair ("silence", HSV (0x9efffd7a))); - c.insert (make_pair ("silence text", HSV (0x0e066cff))); - c.insert (make_pair ("mono panner outline", HSV (0x33445eff))); - c.insert (make_pair ("mono panner fill", HSV (0x7a9bccc9))); - c.insert (make_pair ("mono panner text", HSV (0x000000ff))); - c.insert (make_pair ("mono panner bg", HSV (0x2e2929ff))); - c.insert (make_pair ("mono panner position fill", HSV (0x7a89b3ff))); - c.insert (make_pair ("mono panner position outline", HSV (0x33445eff))); - c.insert (make_pair ("stereo panner outline", HSV (0x33445eff))); - c.insert (make_pair ("stereo panner fill", HSV (0x7a9accc9))); - c.insert (make_pair ("stereo panner text", HSV (0x000000ff))); - c.insert (make_pair ("stereo panner bg", HSV (0x2e2929ff))); - c.insert (make_pair ("stereo panner rule", HSV (0x455c7fff))); - c.insert (make_pair ("stereo panner mono outline", HSV (0xa05600ff))); - c.insert (make_pair ("stereo panner mono fill", HSV (0xe99668ca))); - c.insert (make_pair ("stereo panner mono text", HSV (0x000000ff))); - c.insert (make_pair ("stereo panner mono bg", HSV (0x2e2929ff))); - c.insert (make_pair ("stereo panner inverted outline", HSV (0xbf0a00ff))); - c.insert (make_pair ("stereo panner inverted fill", HSV (0xe4a19cc9))); - c.insert (make_pair ("stereo panner inverted text", HSV (0x000000ff))); - c.insert (make_pair ("stereo panner inverted bg", HSV (0x2e2929ff))); - c.insert (make_pair ("tempo bar", HSV (0x70727fcc))); - c.insert (make_pair ("tempo marker", HSV (0xf2425bff))); - c.insert (make_pair ("time axis frame", HSV (0x000000ff))); - c.insert (make_pair ("selected time axis frame", HSV (0xee0000ff))); - c.insert (make_pair ("time stretch fill", HSV (0xe2b5b596))); - c.insert (make_pair ("time stretch outline", HSV (0x63636396))); - c.insert (make_pair ("tracknumber label: fill", HSV (0x444444ff))); - c.insert (make_pair ("tracknumber label: fill active", HSV (0x333333ff))); - c.insert (make_pair ("tracknumber label: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("transport drag rect", HSV (0x969696c6))); - c.insert (make_pair ("transport loop rect", HSV (0x1e7728f9))); - c.insert (make_pair ("transport marker bar", HSV (0x8c8e98cc))); - c.insert (make_pair ("transport punch rect", HSV (0x6d2828e5))); - c.insert (make_pair ("trim handle locked", HSV (0xea0f0f28))); - c.insert (make_pair ("trim handle", HSV (0x1900ff44))); - c.insert (make_pair ("verbose canvas cursor", HSV (0xfffd2ebc))); - c.insert (make_pair ("vestigial frame", HSV (0x0000000f))); - c.insert (make_pair ("video timeline bar", HSV (0x303030ff))); - c.insert (make_pair ("region base", HSV (0x838890ff))); - c.insert (make_pair ("region area covered by another region", HSV (0x505050b0))); - c.insert (make_pair ("waveform outline", HSV (0x000000ff))); - c.insert (make_pair ("clipped waveform", HSV (0xff0000e5))); - c.insert (make_pair ("waveform fill", HSV (0xffffffd9))); - c.insert (make_pair ("zero line", HSV (0x7f7f7fe0))); - c.insert (make_pair ("zoom rect", HSV (0xc6d1b26d))); - c.insert (make_pair ("monitor knob", HSV (0x555050ff))); - c.insert (make_pair ("monitor knob: arc start", HSV (0x5d90b0ff))); - c.insert (make_pair ("monitor knob: arc end", HSV (0x154c6eff))); - c.insert (make_pair ("button border", HSV (0x000000f0))); - c.insert (make_pair ("border color", HSV (0x00000000))); - c.insert (make_pair ("processor prefader: fill", HSV (0x873c3cff))); - c.insert (make_pair ("processor prefader: fill active", HSV (0x603535ff))); - c.insert (make_pair ("processor prefader: led", HSV (0x26550eff))); - c.insert (make_pair ("processor prefader: led active", HSV (0x78cb4eff))); - c.insert (make_pair ("processor prefader: text", HSV (0xaaaaa3ff))); - c.insert (make_pair ("processor prefader: text active", HSV (0xeeeeecff))); - c.insert (make_pair ("processor fader: fill", HSV (0x5d90b0ff))); - c.insert (make_pair ("processor fader: fill active", HSV (0x256d8fff))); - c.insert (make_pair ("processor fader: led", HSV (0x26550eff))); - c.insert (make_pair ("processor fader: led active", HSV (0x78cb4eff))); - c.insert (make_pair ("processor fader: text", HSV (0xaaaaa3ff))); - c.insert (make_pair ("processor fader: text active", HSV (0xeeeeecff))); - c.insert (make_pair ("processor postfader: fill", HSV (0x455a3cff))); - c.insert (make_pair ("processor postfader: fill active", HSV (0x254528ff))); - c.insert (make_pair ("processor postfader: led", HSV (0x26550eff))); - c.insert (make_pair ("processor postfader: led active", HSV (0x78cb4eff))); - c.insert (make_pair ("processor postfader: text", HSV (0xaaaaa3ff))); - c.insert (make_pair ("processor postfader: text active", HSV (0xeeeeecff))); - c.insert (make_pair ("processor control button: fill", HSV (0x222222ff))); - c.insert (make_pair ("processor control button: fill active", HSV (0x333333ff))); - c.insert (make_pair ("processor control button: led", HSV (0x101010ff))); - c.insert (make_pair ("processor control button: led active", HSV (0x5d90b0ff))); - c.insert (make_pair ("processor control button: text", HSV (0xffffffff))); - c.insert (make_pair ("processor control button: text active", HSV (0xffffffff))); - c.insert (make_pair ("midi device: fill", HSV (0x54555dff))); - c.insert (make_pair ("midi device: fill active", HSV (0x45464cff))); - c.insert (make_pair ("midi device: led", HSV (0x006600ff))); - c.insert (make_pair ("midi device: led active", HSV (0x00ff00ff))); - c.insert (make_pair ("midi device: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("midi device: text active", HSV (0xeeeeecff))); - c.insert (make_pair ("monitor button: fill", HSV (0x616268ff))); - c.insert (make_pair ("monitor button: fill active", HSV (0xc56505ff))); - c.insert (make_pair ("monitor button: led", HSV (0x660000ff))); - c.insert (make_pair ("monitor button: led active", HSV (0xff0000ff))); - c.insert (make_pair ("monitor button: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("monitor button: text active", HSV (0x1a1a1aff))); - c.insert (make_pair ("solo isolate: fill", HSV (0x616268ff))); - c.insert (make_pair ("solo isolate: fill active", HSV (0x564d48ff))); - c.insert (make_pair ("solo isolate: led", HSV (0x660000ff))); - c.insert (make_pair ("solo isolate: led active", HSV (0xff0000ff))); - c.insert (make_pair ("solo isolate: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("solo isolate: text active", HSV (0xc8c8d9ff))); - c.insert (make_pair ("solo safe: fill", HSV (0x616268ff))); - c.insert (make_pair ("solo safe: fill active", HSV (0x564d48ff))); - c.insert (make_pair ("solo safe: led", HSV (0x660000ff))); - c.insert (make_pair ("solo safe: led active", HSV (0xff0000ff))); - c.insert (make_pair ("solo safe: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("solo safe: text active", HSV (0xc8c8d9ff))); - c.insert (make_pair ("meterbridge peaklabel", HSV (0xff1111ff))); - c.insert (make_pair ("meter color BBC", HSV (0xffa500ff))); - c.insert (make_pair ("monitor section cut: fill", HSV (0x5f5a58ff))); - c.insert (make_pair ("monitor section cut: fill active", HSV (0xffa500ff))); - c.insert (make_pair ("monitor section cut: led", HSV (0x473812ff))); - c.insert (make_pair ("monitor section cut: led active", HSV (0x78cb4eff))); - c.insert (make_pair ("monitor section cut: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("monitor section cut: text active", HSV (0x000000ff))); - c.insert (make_pair ("monitor section dim: fill", HSV (0x5f5a58ff))); - c.insert (make_pair ("monitor section dim: fill active", HSV (0xe58505ff))); - c.insert (make_pair ("monitor section dim: led", HSV (0x00000000))); - c.insert (make_pair ("monitor section dim: led active", HSV (0x78cb4eff))); - c.insert (make_pair ("monitor section dim: text", HSV (0xc8c8d9ff))); - c.insert (make_pair ("monitor section dim: text active", HSV (0xc8c8d9ff))); - c.insert (make_pair ("monitor section solo: fill", HSV (0x5f5a58ff))); - c.insert (make_pair ("monitor section solo: fill active", HSV (0x4dbb00ff))); - c.insert (make_pair ("monitor section solo: led", HSV (0x473812ff))); - c.insert (make_pair ("monitor section solo: led active", HSV (0xffa500ff))); - c.insert (make_pair ("monitor section solo: text", HSV (0x00000000))); - c.insert (make_pair ("monitor section solo: text active", HSV (0x00000000))); - c.insert (make_pair ("monitor section invert: fill", HSV (0x5f5a58ff))); - c.insert (make_pair ("monitor section invert: fill active", HSV (0x4242d0ff))); - c.insert (make_pair ("monitor section invert: led", HSV (0x473812ff))); - c.insert (make_pair ("monitor section invert: led active", HSV (0x78cb4eff))); - c.insert (make_pair ("monitor section invert: text", HSV (0x00000000))); - c.insert (make_pair ("monitor section invert: text active", HSV (0x00000000))); - c.insert (make_pair ("monitor section mono: fill", HSV (0x5f5a58ff))); - c.insert (make_pair ("monitor section mono: fill active", HSV (0x3232c0ff))); - c.insert (make_pair ("monitor section mono: led", HSV (0x473812ff))); - c.insert (make_pair ("monitor section mono: led active", HSV (0x78cb4eff))); - c.insert (make_pair ("monitor section mono: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("monitor section mono: text active", HSV (0xc8c8d9ff))); - c.insert (make_pair ("monitor section solo model: fill", HSV (0x5d5856ff))); - c.insert (make_pair ("monitor section solo model: fill active", HSV (0x564d48ff))); - c.insert (make_pair ("monitor section solo model: led", HSV (0x4f3300ff))); - c.insert (make_pair ("monitor section solo model: led active", HSV (0xffa500ff))); - c.insert (make_pair ("monitor section solo model: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("monitor section solo model: text active", HSV (0xc8c8d9ff))); - c.insert (make_pair ("monitor solo override: fill", HSV (0x5d5856ff))); - c.insert (make_pair ("monitor solo override: fill active", HSV (0x564d48ff))); - c.insert (make_pair ("monitor solo override: led", HSV (0x4f3300ff))); - c.insert (make_pair ("monitor solo override: led active", HSV (0xffa500ff))); - c.insert (make_pair ("monitor solo override: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("monitor solo override: text active", HSV (0xc8c8d9ff))); - c.insert (make_pair ("monitor solo exclusive: fill", HSV (0x5d5856ff))); - c.insert (make_pair ("monitor solo exclusive: fill active", HSV (0x564c47ff))); - c.insert (make_pair ("monitor solo exclusive: led", HSV (0x4f3300ff))); - c.insert (make_pair ("monitor solo exclusive: led active", HSV (0xffa500ff))); - c.insert (make_pair ("monitor solo exclusive: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("monitor solo exclusive: text active", HSV (0xc8c8d9ff))); - c.insert (make_pair ("rude solo: fill", HSV (0x684d4dff))); - c.insert (make_pair ("rude solo: fill active", HSV (0xe21b1bff))); - c.insert (make_pair ("rude solo: led", HSV (0x00000000))); - c.insert (make_pair ("rude solo: led active", HSV (0x00000000))); - c.insert (make_pair ("rude solo: text", HSV (0x969696ff))); - c.insert (make_pair ("rude solo: text active", HSV (0xe5e5e5ff))); - c.insert (make_pair ("rude isolate: fill", HSV (0x21414fff))); - c.insert (make_pair ("rude isolate: fill active", HSV (0xb6e5fdff))); - c.insert (make_pair ("rude isolate: led", HSV (0x00000000))); - c.insert (make_pair ("rude isolate: led active", HSV (0x000000ff))); - c.insert (make_pair ("rude isolate: text", HSV (0x979797ff))); - c.insert (make_pair ("rude isolate: text active", HSV (0x000000ff))); - c.insert (make_pair ("rude audition: fill", HSV (0x684d4dff))); - c.insert (make_pair ("rude audition: fill active", HSV (0xe21b1bff))); - c.insert (make_pair ("rude audition: led", HSV (0x00000000))); - c.insert (make_pair ("rude audition: led active", HSV (0x00000000))); - c.insert (make_pair ("rude audition: text", HSV (0x979797ff))); - c.insert (make_pair ("rude audition: text active", HSV (0xffffffff))); - c.insert (make_pair ("feedback alert: fill", HSV (0x684d4dff))); - c.insert (make_pair ("feedback alert: fill active", HSV (0xe21b1bff))); - c.insert (make_pair ("feedback alert: led", HSV (0x00000000))); - c.insert (make_pair ("feedback alert: led active", HSV (0x00000000))); - c.insert (make_pair ("feedback alert: text", HSV (0x969696ff))); - c.insert (make_pair ("feedback alert: text active", HSV (0xe5e5e5ff))); - c.insert (make_pair ("mute button: fill", HSV (0x616268ff))); - c.insert (make_pair ("mute button: fill active", HSV (0xbbbb00ff))); - c.insert (make_pair ("mute button: led", HSV (0x00000000))); - c.insert (make_pair ("mute button: led active", HSV (0x00000000))); - c.insert (make_pair ("mute button: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("mute button: text active", HSV (0x191919ff))); - c.insert (make_pair ("solo button: fill", HSV (0x616268ff))); - c.insert (make_pair ("solo button: fill active", HSV (0x4dbb00ff))); - c.insert (make_pair ("solo button: led", HSV (0x00000000))); - c.insert (make_pair ("solo button: led active", HSV (0x00000000))); - c.insert (make_pair ("solo button: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("solo button: text active", HSV (0x191919ff))); - c.insert (make_pair ("invert button: fill", HSV (0x616268ff))); - c.insert (make_pair ("invert button: fill active", HSV (0x4242d0ff))); - c.insert (make_pair ("invert button: led", HSV (0x473812ff))); - c.insert (make_pair ("invert button: led active", HSV (0x78cb4eff))); - c.insert (make_pair ("invert button: text", HSV (0xd7d7e8ff))); - c.insert (make_pair ("invert button: text active", HSV (0xbfbfbfff))); - c.insert (make_pair ("record enable button: fill", HSV (0x616268ff))); - c.insert (make_pair ("record enable button: fill active", HSV (0xb50e0eff))); - c.insert (make_pair ("record enable button: led", HSV (0x7b3541ff))); - c.insert (make_pair ("record enable button: led active", HSV (0xffa3b3ff))); - c.insert (make_pair ("record enable button: text", HSV (0xa5a5a5ff))); - c.insert (make_pair ("record enable button: text active", HSV (0x000000ff))); - c.insert (make_pair ("generic button: fill", HSV (0x616268ff))); - c.insert (make_pair ("generic button: fill active", HSV (0xfd0000ff))); - c.insert (make_pair ("generic button: led", HSV (0x22224fff))); - c.insert (make_pair ("generic button: led active", HSV (0x2222ffff))); - c.insert (make_pair ("generic button: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("generic button: text active", HSV (0x191919ff))); - c.insert (make_pair ("send alert button: fill", HSV (0x4e5647ff))); - c.insert (make_pair ("send alert button: fill active", HSV (0x85e524ff))); - c.insert (make_pair ("send alert button: led", HSV (0x00000000))); - c.insert (make_pair ("send alert button: led active", HSV (0x00000000))); - c.insert (make_pair ("send alert button: text", HSV (0xccccccff))); - c.insert (make_pair ("send alert button: text active", HSV (0x000000ff))); - c.insert (make_pair ("transport button: fill", HSV (0x616268ff))); - c.insert (make_pair ("transport button: fill active", HSV (0x00a300ff))); - c.insert (make_pair ("transport button: led", HSV (0x00000000))); - c.insert (make_pair ("transport button: led active", HSV (0x00000000))); - c.insert (make_pair ("transport button: text", HSV (0x00000000))); - c.insert (make_pair ("transport button: text active", HSV (0x00000000))); - c.insert (make_pair ("transport recenable button: fill", HSV (0x5f3f3fff))); - c.insert (make_pair ("transport recenable button: fill active", HSV (0xb50e0eff))); - c.insert (make_pair ("transport recenable button: led", HSV (0x00000000))); - c.insert (make_pair ("transport recenable button: led active", HSV (0x00000000))); - c.insert (make_pair ("transport recenable button: text", HSV (0x00000000))); - c.insert (make_pair ("transport recenable button: text active", HSV (0x00000000))); - c.insert (make_pair ("transport option button: fill", HSV (0x616268ff))); - c.insert (make_pair ("transport option button: fill active", HSV (0x4a4b51ff))); - c.insert (make_pair ("transport option button: led", HSV (0x4f3300ff))); - c.insert (make_pair ("transport option button: led active", HSV (0xffa500ff))); - c.insert (make_pair ("transport option button: text", HSV (0xd7d7e8ff))); - c.insert (make_pair ("transport option button: text active", HSV (0xc8c8d9ff))); - c.insert (make_pair ("transport active option button: fill", HSV (0x616268ff))); - c.insert (make_pair ("transport active option button: fill active", HSV (0x00a300ff))); - c.insert (make_pair ("transport active option button: led", HSV (0x4f3300ff))); - c.insert (make_pair ("transport active option button: led active", HSV (0xffa500ff))); - c.insert (make_pair ("transport active option button: text", HSV (0xd7d7e8ff))); - c.insert (make_pair ("transport active option button: text active", HSV (0x000000ff))); - c.insert (make_pair ("plugin bypass button: fill", HSV (0x5d5856ff))); - c.insert (make_pair ("plugin bypass button: fill active", HSV (0x564d48ff))); - c.insert (make_pair ("plugin bypass button: led", HSV (0x660000ff))); - c.insert (make_pair ("plugin bypass button: led active", HSV (0xff0000ff))); - c.insert (make_pair ("plugin bypass button: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("plugin bypass button: text active", HSV (0xc8c8d9ff))); - c.insert (make_pair ("punch button: fill", HSV (0x603f3fff))); - c.insert (make_pair ("punch button: fill active", HSV (0xf03020ff))); - c.insert (make_pair ("punch button: led", HSV (0x00000000))); - c.insert (make_pair ("punch button: led active", HSV (0x00000000))); - c.insert (make_pair ("punch button: text", HSV (0xa5a5a5ff))); - c.insert (make_pair ("punch button: text active", HSV (0xd8d8d8ff))); - c.insert (make_pair ("mouse mode button: fill", HSV (0x616268ff))); - c.insert (make_pair ("mouse mode button: fill active", HSV (0x00b200ff))); - c.insert (make_pair ("mouse mode button: led", HSV (0x4f3300ff))); - c.insert (make_pair ("mouse mode button: led active", HSV (0xffa500ff))); - c.insert (make_pair ("mouse mode button: text", HSV (0xd7d7e8ff))); - c.insert (make_pair ("mouse mode button: text active", HSV (0x000000ff))); - c.insert (make_pair ("nudge button: fill", HSV (0x684744ff))); - c.insert (make_pair ("nudge button: fill active", HSV (0x404045ff))); - c.insert (make_pair ("nudge button: led", HSV (0x4f3300ff))); - c.insert (make_pair ("nudge button: led active", HSV (0xffa500ff))); - c.insert (make_pair ("nudge button: text", HSV (0xc7c7d8ff))); - c.insert (make_pair ("nudge button: text active", HSV (0xc8c8d9ff))); - c.insert (make_pair ("zoom menu: fill", HSV (0x99997950))); - c.insert (make_pair ("zoom menu: fill active", HSV (0x404045ff))); - c.insert (make_pair ("zoom menu: led", HSV (0x4f3300ff))); - c.insert (make_pair ("zoom menu: led active", HSV (0xffa500ff))); - c.insert (make_pair ("zoom menu: text", HSV (0xd7d7e8ff))); - c.insert (make_pair ("zoom menu: text active", HSV (0xc8c8d9ff))); - c.insert (make_pair ("zoom button: fill", HSV (0x616268ff))); - c.insert (make_pair ("zoom button: fill active", HSV (0x00a300ff))); - c.insert (make_pair ("zoom button: led", HSV (0x4f3300ff))); - c.insert (make_pair ("zoom button: led active", HSV (0xffa500ff))); - c.insert (make_pair ("zoom button: text", HSV (0xd7d7e8ff))); - c.insert (make_pair ("zoom button: text active", HSV (0x000000ff))); - c.insert (make_pair ("route button: fill", HSV (0x616268ff))); - c.insert (make_pair ("route button: fill active", HSV (0x121212ff))); - c.insert (make_pair ("route button: led", HSV (0x4f3300ff))); - c.insert (make_pair ("route button: led active", HSV (0xffa500ff))); - c.insert (make_pair ("route button: text", HSV (0xd7d7e8ff))); - c.insert (make_pair ("route button: text active", HSV (0x191919ff))); - c.insert (make_pair ("mixer strip button: fill", HSV (0x616268ff))); - c.insert (make_pair ("mixer strip button: fill active", HSV (0xffa500ff))); - c.insert (make_pair ("mixer strip button: led", HSV (0x4f3300ff))); - c.insert (make_pair ("mixer strip button: led active", HSV (0xffa500ff))); - c.insert (make_pair ("mixer strip button: text", HSV (0xd7d7e8ff))); - c.insert (make_pair ("mixer strip button: text active", HSV (0x000000ff))); - c.insert (make_pair ("mixer strip name button: fill", HSV (0x616268ff))); - c.insert (make_pair ("mixer strip name button: fill active", HSV (0x121212ff))); - c.insert (make_pair ("mixer strip name button: led", HSV (0x4f3300ff))); - c.insert (make_pair ("mixer strip name button: led active", HSV (0xffa500ff))); - c.insert (make_pair ("mixer strip name button: text", HSV (0xd7d7e8ff))); - c.insert (make_pair ("mixer strip name button: text active", HSV (0xc8c8d9ff))); - c.insert (make_pair ("midi input button: fill", HSV (0x656867ff))); - c.insert (make_pair ("midi input button: fill active", HSV (0x00a300ff))); - c.insert (make_pair ("midi input button: led", HSV (0x00000000))); - c.insert (make_pair ("midi input button: led active", HSV (0x00000000))); - c.insert (make_pair ("midi input button: text", HSV (0x00000000))); - c.insert (make_pair ("midi input button: text active", HSV (0x00000000))); - c.insert (make_pair ("transport clock: background", HSV (0x262626ff))); - c.insert (make_pair ("transport clock: text", HSV (0x8df823ff))); - c.insert (make_pair ("transport clock: edited text", HSV (0xffa500ff))); - c.insert (make_pair ("transport clock: cursor", HSV (0xffa500ff))); - c.insert (make_pair ("secondary clock: background", HSV (0x262626ff))); - c.insert (make_pair ("secondary clock: text", HSV (0x8df823ff))); - c.insert (make_pair ("secondary clock: edited text", HSV (0xffa500ff))); - c.insert (make_pair ("secondary clock: cursor", HSV (0xffa500ff))); - c.insert (make_pair ("transport delta clock: background", HSV (0x000000ff))); - c.insert (make_pair ("transport delta clock: edited text", HSV (0xff0000ff))); - c.insert (make_pair ("transport delta clock: cursor", HSV (0xf11000ff))); - c.insert (make_pair ("transport delta clock: text", HSV (0x8ce1f8ff))); - c.insert (make_pair ("secondary delta clock: edited text", HSV (0xff0000ff))); - c.insert (make_pair ("secondary delta clock: cursor", HSV (0xf11000ff))); - c.insert (make_pair ("secondary delta clock: background", HSV (0x000000ff))); - c.insert (make_pair ("secondary delta clock: text", HSV (0x8ce1f8ff))); - c.insert (make_pair ("big clock: background", HSV (0x020202ff))); - c.insert (make_pair ("big clock: text", HSV (0xf0f0f0ff))); - c.insert (make_pair ("big clock: edited text", HSV (0xffa500ff))); - c.insert (make_pair ("big clock: cursor", HSV (0xffa500ff))); - c.insert (make_pair ("big clock active: background", HSV (0x020202ff))); - c.insert (make_pair ("big clock active: text", HSV (0xf11000ff))); - c.insert (make_pair ("big clock active: edited text", HSV (0xffa500ff))); - c.insert (make_pair ("big clock active: cursor", HSV (0xffa500ff))); - c.insert (make_pair ("punch clock: background", HSV (0x000000ff))); - c.insert (make_pair ("punch clock: text", HSV (0x6bb620ff))); - c.insert (make_pair ("punch clock: edited text", HSV (0xff0000ff))); - c.insert (make_pair ("punch clock: cursor", HSV (0xf11000ff))); - c.insert (make_pair ("selection clock: background", HSV (0x000000ff))); - c.insert (make_pair ("selection clock: text", HSV (0x6bb620ff))); - c.insert (make_pair ("selection clock: edited text", HSV (0xff0000ff))); - c.insert (make_pair ("selection clock: cursor", HSV (0xf11000ff))); - c.insert (make_pair ("nudge clock: background", HSV (0x262626ff))); - c.insert (make_pair ("nudge clock: text", HSV (0x6bb620ff))); - c.insert (make_pair ("nudge clock: edited text", HSV (0xffa500ff))); - c.insert (make_pair ("nudge clock: cursor", HSV (0xffa500ff))); - c.insert (make_pair ("clock: background", HSV (0x000000ff))); - c.insert (make_pair ("clock: text", HSV (0x6bb620ff))); - c.insert (make_pair ("clock: edited text", HSV (0xffa500ff))); - c.insert (make_pair ("clock: cursor", HSV (0xffa500ff))); - c.insert (make_pair ("lock button: fill", HSV (0x616268ff))); - c.insert (make_pair ("lock button: fill active", HSV (0x404045ff))); - c.insert (make_pair ("lock button: led", HSV (0x00000000))); - c.insert (make_pair ("lock button: led active", HSV (0x00000000))); - c.insert (make_pair ("lock button: text", HSV (0x000024ff))); - c.insert (make_pair ("lock button: text active", HSV (0xc8c8d9ff))); - - for (map::iterator fp = c.begin(); fp != c.end(); ++fp) { - const double hue_cnt = 18.0; - - fp->second.h = hue_cnt * (round (fp->second.h/hue_cnt)); - } + long val = get_font_scale(); + set_pango_fontsize (); + /* Xft rendering */ -#undef CANVAS_COLOR -#define CANVAS_COLOR(var,name,base,modifier) print_relative_def (#var,name,c[name]); -#include "colors.h" -#undef CANVAS_COLOR + gtk_settings_set_long_property (gtk_settings_get_default(), + "gtk-xft-dpi", val, "ardour"); + DPIReset(); //Emit Signal } void -UIConfiguration::color_theme_changed () +UIConfiguration::set_pango_fontsize () { - map::iterator current_color; + long val = get_font_scale(); - /* we need to reset the quantized hues before we start, because - * otherwise when we call RelativeHSV::get() in color_compute() - * we don't get an answer based on the new base colors, but instead - * based on any existing hue quantization. - */ + /* FT2 rendering - used by GnomeCanvas, sigh */ - for (current_color = relative_colors.begin(); current_color != relative_colors.end(); ++current_color) { - current_color->second.quantized_hue = -1; - } +#ifndef PLATFORM_WINDOWS + pango_ft2_font_map_set_resolution ((PangoFT2FontMap*) pango_ft2_font_map_new(), val/1024, val/1024); +#endif + + /* Cairo rendering, in case there is any */ - color_compute (); + pango_cairo_font_map_set_resolution ((PangoCairoFontMap*) pango_cairo_font_map_get_default(), val/1024); +} + +float +UIConfiguration::get_ui_scale () +{ + return get_font_scale () / 102400.; } void @@ -632,32 +195,163 @@ UIConfiguration::map_parameters (boost::function& functor) #undef UI_CONFIG_VARIABLE } +int +UIConfiguration::pre_gui_init () +{ +#ifdef CAIRO_SUPPORTS_FORCE_BUGGY_GRADIENTS_ENVIRONMENT_VARIABLE + if (get_buggy_gradients()) { + g_setenv ("FORCE_BUGGY_GRADIENTS", "1", 1); + } +#endif +#ifdef OPTIONAL_CAIRO_IMAGE_SURFACE + if (get_cairo_image_surface()) { + g_setenv ("ARDOUR_IMAGE_SURFACE", "1", 1); + } +#endif + return 0; +} + +UIConfiguration* +UIConfiguration::post_gui_init () +{ + load_color_theme (); + return this; +} + int UIConfiguration::load_defaults () { - int found = 0; std::string rcfile; + int ret = -1; if (find_file (ardour_config_search_path(), default_ui_config_file_name, rcfile) ) { XMLTree tree; - found = 1; - info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl; + info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endmsg; if (!tree.read (rcfile.c_str())) { error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg; + } else { + if (set_state (*tree.root(), Stateful::loading_state_version)) { + error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg; + } else { + _dirty = false; + ret = 0; + } + } + + } else { + warning << string_compose (_("Could not find default UI configuration file %1"), default_ui_config_file_name) << endmsg; + } + + + if (ret == 0) { + /* reload color theme */ + load_color_theme (false); + ColorsChanged (); /* EMIT SIGNAL */ + } + + return ret; +} + +int +UIConfiguration::load_color_theme (bool allow_own) +{ + std::string cfile; + string basename; + bool found = false; + + if (allow_own) { + basename = "my-"; + basename += color_file.get(); + basename += ".colors"; + + if (find_file (ardour_config_search_path(), basename, cfile)) { + found = true; + } + } + + if (!found) { + basename = color_file.get(); + basename += ".colors"; + + if (find_file (ardour_config_search_path(), basename, cfile)) { + found = true; + } + } + + if (found) { + + XMLTree tree; + + info << string_compose (_("Loading color file %1"), cfile) << endmsg; + + if (!tree.read (cfile.c_str())) { + error << string_compose(_("cannot read color file \"%1\""), cfile) << endmsg; return -1; } if (set_state (*tree.root(), Stateful::loading_state_version)) { - error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg; + error << string_compose(_("color file \"%1\" not loaded successfully."), cfile) << endmsg; return -1; } - _dirty = false; + ColorsChanged (); + } else { + warning << string_compose (_("Color file %1 not found"), basename) << endmsg; } - return found; + return 0; +} + +int +UIConfiguration::store_color_theme () +{ + XMLNode* root; + LocaleGuard lg (); + + root = new XMLNode("Ardour"); + + XMLNode* parent = new XMLNode (X_("Colors")); + for (Colors::const_iterator i = colors.begin(); i != colors.end(); ++i) { + XMLNode* node = new XMLNode (X_("Color")); + node->add_property (X_("name"), i->first); + stringstream ss; + ss << "0x" << setw (8) << setfill ('0') << hex << i->second; + node->add_property (X_("value"), ss.str()); + parent->add_child_nocopy (*node); + } + root->add_child_nocopy (*parent); + + parent = new XMLNode (X_("ColorAliases")); + for (ColorAliases::const_iterator i = color_aliases.begin(); i != color_aliases.end(); ++i) { + XMLNode* node = new XMLNode (X_("ColorAlias")); + node->add_property (X_("name"), i->first); + node->add_property (X_("alias"), i->second); + parent->add_child_nocopy (*node); + } + root->add_child_nocopy (*parent); + + parent = new XMLNode (X_("Modifiers")); + for (Modifiers::const_iterator i = modifiers.begin(); i != modifiers.end(); ++i) { + XMLNode* node = new XMLNode (X_("Modifier")); + node->add_property (X_("name"), i->first); + node->add_property (X_("modifier"), i->second.to_string()); + parent->add_child_nocopy (*node); + } + root->add_child_nocopy (*parent); + + XMLTree tree; + std::string colorfile = Glib::build_filename (user_config_directory(), (string ("my-") + color_file.get() + ".colors")); + + tree.set_root (root); + + if (!tree.write (colorfile.c_str())){ + error << string_compose (_("Color file %1 not saved"), colorfile) << endmsg; + return -1; + } + + return 0; } int @@ -667,11 +361,11 @@ UIConfiguration::load_state () std::string rcfile; - if ( find_file (ardour_config_search_path(), default_ui_config_file_name, rcfile)) { + if (find_file (ardour_config_search_path(), default_ui_config_file_name, rcfile)) { XMLTree tree; found = true; - info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl; + info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endmsg; if (!tree.read (rcfile.c_str())) { error << string_compose(_("cannot read default ui configuration file \"%1\""), rcfile) << endmsg; @@ -713,21 +407,34 @@ UIConfiguration::load_state () int UIConfiguration::save_state() { - XMLTree tree; - std::string rcfile(user_config_directory()); - rcfile = Glib::build_filename (rcfile, ui_config_file_name); + if (_dirty) { + std::string rcfile = Glib::build_filename (user_config_directory(), ui_config_file_name); + + XMLTree tree; - // this test seems bogus? - if (rcfile.length()) { tree.set_root (&get_state()); + if (!tree.write (rcfile.c_str())){ error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg; return -1; } + + _dirty = false; + } + + if (aliases_modified || colors_modified || modifiers_modified) { + + if (store_color_theme ()) { + error << string_compose (_("Color file %1 not saved"), color_file.get()) << endmsg; + return -1; + } + + aliases_modified = false; + colors_modified = false; + modifiers_modified = false; } - _dirty = false; return 0; } @@ -736,7 +443,7 @@ XMLNode& UIConfiguration::get_state () { XMLNode* root; - LocaleGuard lg (X_("POSIX")); + LocaleGuard lg (); root = new XMLNode("Ardour"); @@ -754,18 +461,17 @@ XMLNode& UIConfiguration::get_variables (std::string which_node) { XMLNode* node; - LocaleGuard lg (X_("POSIX")); + LocaleGuard lg (); - node = new XMLNode(which_node); + node = new XMLNode (which_node); #undef UI_CONFIG_VARIABLE +#undef CANVAS_FONT_VARIABLE #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); } -#define CANVAS_STRING_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); } #define CANVAS_FONT_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); } #include "ui_config_vars.h" #include "canvas_vars.h" #undef UI_CONFIG_VARIABLE -#undef CANVAS_STRING_VARIABLE #undef CANVAS_FONT_VARIABLE return *node; @@ -774,6 +480,8 @@ UIConfiguration::get_variables (std::string which_node) int UIConfiguration::set_state (const XMLNode& root, int /*version*/) { + /* this can load a generic UI configuration file or a colors file */ + if (root.name() != "Ardour") { return -1; } @@ -794,158 +502,170 @@ UIConfiguration::set_state (const XMLNode& root, int /*version*/) } } + XMLNode* colors = find_named_node (root, X_("Colors")); + + if (colors) { + load_colors (*colors); + } + + XMLNode* aliases = find_named_node (root, X_("ColorAliases")); + + if (aliases) { + load_color_aliases (*aliases); + } + + XMLNode* modifiers = find_named_node (root, X_("Modifiers")); + + if (modifiers) { + load_modifiers (*modifiers); + } + return 0; } void -UIConfiguration::print_relative_def (string camelcase, string name, Color c) +UIConfiguration::load_color_aliases (XMLNode const & node) { - HSV variable (c); - HSV closest; - double shortest_distance = DBL_MAX; - string closest_name; - - for (map::iterator f = full_palette.begin(); f != full_palette.end(); ++f) { - - double d; - HSV fixed (f->second); - - // d = variable.distance (fixed); - - d = fabs (variable.h - fixed.h); - - if (d < shortest_distance) { - closest = fixed; - closest_name = f->first; - shortest_distance = d; + XMLNodeList const nlist = node.children(); + XMLNodeConstIterator niter; + XMLProperty const *name; + XMLProperty const *alias; + + color_aliases.clear (); + + for (niter = nlist.begin(); niter != nlist.end(); ++niter) { + XMLNode const * child = *niter; + if (child->name() != X_("ColorAlias")) { + continue; + } + name = child->property (X_("name")); + alias = child->property (X_("alias")); + + if (name && alias) { + color_aliases.insert (make_pair (name->value(), alias->value())); } } - - /* we now know the closest color of the fixed colors to - this variable color. Compute the HSV diff and - use it to redefine the variable color in terms of the - fixed one. - */ - - HSV delta = variable.delta (closest); +} + +void +UIConfiguration::load_colors (XMLNode const & node) +{ + XMLNodeList const nlist = node.children(); + XMLNodeConstIterator niter; + XMLProperty const *name; + XMLProperty const *color; + + colors.clear (); - cerr << "CANVAS_COLOR(" << camelcase << ",\"" << name << "\", \"" << closest_name << "\", HSV(" - << delta.h << ',' << delta.s << ',' << delta.v << ',' << variable.a << ")) /*" - << shortest_distance << " */" << endl; + for (niter = nlist.begin(); niter != nlist.end(); ++niter) { + XMLNode const * child = *niter; + if (child->name() != X_("Color")) { + continue; + } + name = child->property (X_("name")); + color = child->property (X_("value")); + + if (name && color) { + ArdourCanvas::Color c; + c = strtoul (color->value().c_str(), 0, 16); + colors.insert (make_pair (name->value(), c)); + } + } } +void +UIConfiguration::load_modifiers (XMLNode const & node) +{ + PBD::LocaleGuard lg (); + XMLNodeList const nlist = node.children(); + XMLNodeConstIterator niter; + XMLProperty const *name; + XMLProperty const *mod; + + modifiers.clear (); + + for (niter = nlist.begin(); niter != nlist.end(); ++niter) { + XMLNode const * child = *niter; + if (child->name() != X_("Modifier")) { + continue; + } + + name = child->property (X_("name")); + mod = child->property (X_("modifier")); + + if (name && mod) { + SVAModifier svam (mod->value()); + modifiers.insert (make_pair (name->value(), svam)); + } + } +} void UIConfiguration::set_variables (const XMLNode& node) { #undef UI_CONFIG_VARIABLE -#define UI_CONFIG_VARIABLE(Type,var,name,val) \ - if (var.set_from_node (node)) { \ - ParameterChanged (name); \ - } -#define CANVAS_STRING_VARIABLE(var,name) \ - if (var.set_from_node (node)) { \ - ParameterChanged (name); \ - } -#define CANVAS_FONT_VARIABLE(var,name) \ - if (var.set_from_node (node)) { \ - ParameterChanged (name); \ - } +#define UI_CONFIG_VARIABLE(Type,var,name,val) if (var.set_from_node (node)) { ParameterChanged (name); } +#define CANVAS_FONT_VARIABLE(var,name) if (var.set_from_node (node)) { ParameterChanged (name); } #include "ui_config_vars.h" #include "canvas_vars.h" #undef UI_CONFIG_VARIABLE -#undef CANVAS_STRING_VARIABLE #undef CANVAS_FONT_VARIABLE +} - /* Reset base colors */ - -#undef CANVAS_BASE_COLOR -#define CANVAS_BASE_COLOR(var,name,val) \ - var.set_from_node (node); -#include "base_colors.h" -#undef CANVAS_BASE_COLOR - +ArdourCanvas::SVAModifier +UIConfiguration::modifier (string const & name) const +{ + Modifiers::const_iterator m = modifiers.find (name); + if (m != modifiers.end()) { + return m->second; + } + return SVAModifier (); } -void -UIConfiguration::set_dirty () +ArdourCanvas::Color +UIConfiguration::color_mod (std::string const & colorname, std::string const & modifiername) const { - _dirty = true; + return HSV (color (colorname)).mod (modifier (modifiername)).color (); } -bool -UIConfiguration::dirty () const +ArdourCanvas::Color +UIConfiguration::color_mod (const ArdourCanvas::Color& color, std::string const & modifiername) const { - return _dirty; + return HSV (color).mod (modifier (modifiername)).color (); } ArdourCanvas::Color -UIConfiguration::base_color_by_name (const std::string& name) const +UIConfiguration::color (const std::string& name, bool* failed) const { - map* >::const_iterator i = configurable_colors.find (name); + ColorAliases::const_iterator e = color_aliases.find (name); - if (i != configurable_colors.end()) { - return i->second->get(); + if (failed) { + *failed = false; } - string::size_type opp; - - if ((opp = name.find (X_(" opposite"))) != string::npos) { - string base = name.substr (0, opp); - i = configurable_colors.find (base); - if (i != configurable_colors.end()) { - HSV hsv (i->second->get()); - return hsv.opposite().color (); + if (e != color_aliases.end ()) { + Colors::const_iterator rc = colors.find (e->second); + if (rc != colors.end()) { + return rc->second; + } + } else { + /* not an alias, try directly */ + Colors::const_iterator rc = colors.find (name); + if (rc != colors.end()) { + return rc->second; } } -#if 0 // yet unsed experimental style postfix - /* Idea: use identical colors but different font/sizes - * for variants of the same 'widget'. - * - * example: - * set_name("mute button"); // in route_ui.cc - * set_name("mute button small"); // in mixer_strip.cc - * - * ardour3_widget_list.rc: - * widget "*mute button" style:highest "small_button" - * widget "*mute button small" style:highest "very_small_text" - * - * both use color-schema of defined in - * BUTTON_VARS(MuteButton, "mute button") - * - * (in this particular example the widgets should be packed - * vertically shinking the mixer strip ones are currently not) - */ - const size_t name_len = name.size(); - const size_t name_sep = name.find(':'); - for (i = configurable_colors.begin(); i != configurable_colors.end(), name_sep != string::npos; ++i) { - const size_t cmp_len = i->first.size(); - const size_t cmp_sep = i->first.find(':'); - if (cmp_len >= name_len || cmp_sep == string::npos) continue; - if (name.substr(name_sep) != i->first.substr(cmp_sep)) continue; - if (name.substr(0, cmp_sep) != i->first.substr(0, cmp_sep)) continue; - return i->second->get(); + if (!failed) { + /* only show this message if the caller wasn't interested in + the fail status. + */ + cerr << string_compose (_("Color %1 not found"), name) << endl; } -#endif - - cerr << string_compose (_("Color %1 not found"), name) << endl; - return RGBA_TO_UINT (g_random_int()%256,g_random_int()%256,g_random_int()%256,0xff); -} -ArdourCanvas::Color -UIConfiguration::color (const std::string& name) const -{ - map::const_iterator e = color_aliases.find (name); - - if (e != color_aliases.end ()) { - map::const_iterator ac = actual_colors.find (e->second); - if (ac != actual_colors.end()) { - return ac->second; - } - } - - cerr << string_compose (_("Color %1 not found"), name) << endl; + if (failed) { + *failed = true; + } return rgba_to_color ((g_random_int()%256)/255.0, (g_random_int()%256)/255.0, @@ -953,110 +673,72 @@ UIConfiguration::color (const std::string& name) const 0xff); } -ArdourCanvas::HSV -UIConfiguration::RelativeHSV::get() const +Color +UIConfiguration::quantized (Color c) const { - HSV base (UIConfiguration::instance()->base_color_by_name (base_color)); - - /* this operation is a little wierd. because of the way we originally - * computed the alpha specification for the modifiers used here - * we need to reset base's alpha to zero before adding the modifier. - */ - - base.a = 0.0; - - HSV self (base + modifier); - - if (quantized_hue >= 0.0) { - self.h = quantized_hue; - } - - return self; + HSV hsv (c); + hsv.h = hue_width * (round (hsv.h/hue_width)); + return hsv.color (); } void -UIConfiguration::color_compute () +UIConfiguration::set_color (string const& name, ArdourCanvas::Color color) { - using namespace ArdourCanvas; - - map* >::iterator f; - map::iterator v; - - /* now compute distances */ - - cerr << "Attempt to reduce " << relative_colors.size() << endl; - - map::iterator current_color; - - color_aliases.clear (); - - /* First quantize the hues. - - This ought to use a perceptual model such as CIE94 or CIEDE2000 that - takes into account non-uniformity in human wavelength - discrimination. - - For now (November 2014) simply divide the hue space (360 degrees) - into small pieces. - */ - - /* quantize all current relative color definitions */ - - for (current_color = relative_colors.begin(); current_color != relative_colors.end(); ++current_color) { - - HSV hsv (current_color->second.get()); - - if (hsv.is_gray ()) { - continue; - } - - current_color->second.quantized_hue = hue_cnt * (round (hsv.h/hue_cnt)); + Colors::iterator i = colors.find (name); + if (i == colors.end()) { + return; } + i->second = color; + colors_modified = true; - actual_colors.clear (); + ColorsChanged (); /* EMIT SIGNAL */ +} - for (current_color = relative_colors.begin(); current_color != relative_colors.end(); ++current_color) { +void +UIConfiguration::set_alias (string const & name, string const & alias) +{ + ColorAliases::iterator i = color_aliases.find (name); + if (i == color_aliases.end()) { + return; + } - map::iterator possible_match; - std::string equivalent_name; - bool matched; + i->second = alias; + aliases_modified = true; - matched = false; + ColorsChanged (); /* EMIT SIGNAL */ +} - for (possible_match = actual_colors.begin(); possible_match != actual_colors.end(); ++possible_match) { +void +UIConfiguration::set_modifier (string const & name, SVAModifier svam) +{ + Modifiers::iterator m = modifiers.find (name); - HSV a (current_color->second.get()); - HSV b (possible_match->second); - - /* This uses perceptual distance to find visually - * similar colors. - */ + if (m == modifiers.end()) { + return; + } - if (a.distance (b) < 6.0) { - matched = true; - break; - } - } + m->second = svam; + modifiers_modified = true; - if (!matched) { + ColorsChanged (); /* EMIT SIGNAL */ +} - /* color does not match any other, generate a generic - * name and store two aliases. - */ +void +UIConfiguration::load_rc_file (bool themechange, bool allow_own) +{ + string basename = ui_rc_file.get(); + std::string rc_file_path; + + if (!find_file (ardour_config_search_path(), basename, rc_file_path)) { + warning << string_compose (_("Unable to find UI style file %1 in search path %2. %3 will look strange"), + basename, ardour_config_search_path().to_string(), PROGRAM_NAME) + << endmsg; + return; + } - string alias = string_compose ("color %1", actual_colors.size() + 1); - actual_colors.insert (make_pair (alias, current_color->second.get())); - color_aliases.insert (make_pair (current_color->first, alias)); + info << "Loading ui configuration file " << rc_file_path << endmsg; - } else { + Gtkmm2ext::UI::instance()->load_rcfile (rc_file_path, themechange); +} - /* this color was within the JND CIE76 distance of - * another, so throw it away. - */ - - color_aliases.insert (make_pair (current_color->first, possible_match->first)); - } - } - cerr << "Ended with " << actual_colors.size() << " colors" << endl; -}