push2: parameterize and centralize colors
[ardour.git] / libs / surfaces / push2 / push2.cc
index 69e2f619cbde704d787473b0853bf955a788efd9..c187dc77aa0931058c772e05c964c35599a938df 100644 (file)
@@ -16,6 +16,8 @@
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include <stdlib.h>
+
 #include "pbd/compose.h"
 #include "pbd/convert.h"
 #include "pbd/debug.h"
@@ -40,6 +42,8 @@
 
 #include "gtkmm2ext/rgb_macros.h"
 
+#include "canvas/colors.h"
+
 #include "push2.h"
 #include "gui.h"
 #include "layout.h"
@@ -141,6 +145,7 @@ Push2::Push2 (ARDOUR::Session& s)
 
        build_maps ();
        build_color_map ();
+       fill_color_table (); 
 
        /* master cannot be removed, so no need to connect to going-away signal */
        master = session->master_out ();
@@ -1615,31 +1620,17 @@ Push2::get_color_index (uint32_t rgb)
                return i->second;
        }
 
-       cerr << "new color 0x" << std::hex << rgb << std::dec << endl;
-
        int r, g, b, a;
        UINT_TO_RGBA (rgb, &r, &g, &b, &a);
-       uint8_t r7, r1;
-       uint8_t b7, b1;
-       uint8_t g7, g1;
-       uint8_t w7, w1;
-
-       r7 = r & 0x7f;
-       r1 = r & 0x1;
-       g7 = g & 0x7f;
-       g1 = g & 0x1;
-       b7 = b & 0x7f;
-       b1 = b & 0x1;
-       w7 = 204 & 0x7f;
-       w1 = 204 & 0x1;
+       int w = 204; /* not sure where/when we should get this value */
 
        /* get a free index */
 
        uint8_t index;
 
        if (color_map_free_list.empty()) {
-               /* random replacement of any entry below 122 (where the
-                * Ableton standard colors live, and not zero either (black)
+               /* random replacement of any entry above zero and below 122 (where the
+                * Ableton standard colors live)
                 */
                index = 1 + (random() % 121);
        } else {
@@ -1651,14 +1642,14 @@ Push2::get_color_index (uint32_t rgb)
        MidiByteArray update_pallette_msg (8, 0xf0, 0x00, 0x21, 0x1d, 0x01, 0x01, 0x05, 0xF7);
 
        palette_msg[7] = index;
-       palette_msg[8] = r7;
-       palette_msg[9] = r1;
-       palette_msg[10] = g7;
-       palette_msg[11] = g1;
-       palette_msg[12] = b7;
-       palette_msg[13] = b1;
-       palette_msg[14] = w7;
-       palette_msg[15] = w1;
+       palette_msg[8] = r & 0x7f;
+       palette_msg[9] = r & 0x1;
+       palette_msg[10] = g & 0x7f;
+       palette_msg[11] = g & 0x1;
+       palette_msg[12] = b & 0x7f;
+       palette_msg[13] = b & 0x1;
+       palette_msg[14] = w & 0x7f;
+       palette_msg[15] = w & 0x1;
 
        write (palette_msg);
        write (update_pallette_msg);
@@ -1672,7 +1663,8 @@ void
 Push2::build_color_map ()
 {
        /* These are "standard" colors that Ableton docs suggest will always be
-          there
+          there. Put them in our color map so that when we look up these
+          colors, we will use the Ableton indices for them.
        */
 
        color_map.insert (make_pair (RGB_TO_UINT (0,0,0), 0));
@@ -1687,3 +1679,36 @@ Push2::build_color_map ()
                color_map_free_list.push (n);
        }
 }
+
+void
+Push2::fill_color_table ()
+{
+       colors.insert (make_pair (DarkBackground, ArdourCanvas::rgba_to_color (0, 0, 0, 1)));
+       colors.insert (make_pair (LightBackground, ArdourCanvas::rgba_to_color (0.98, 0.98, 0.98, 1)));
+
+       colors.insert (make_pair (ParameterName, ArdourCanvas::rgba_to_color (0.32, 0.28, 0.47, 1)));
+
+       colors.insert (make_pair (KnobArcBackground, ArdourCanvas::rgba_to_color (0.3, 0.3, 0.3, 1.0)));
+       colors.insert (make_pair (KnobArcStart, ArdourCanvas::rgba_to_color (1.0, 0.0, 0.0, 1.0)));
+       colors.insert (make_pair (KnobArcEnd, ArdourCanvas::rgba_to_color (0.0, 1.0, 0.0, 1.0)));
+
+       colors.insert (make_pair (KnobLineShadow, ArdourCanvas::rgba_to_color  (0, 0, 0, 0.3)));
+       colors.insert (make_pair (KnobLine, ArdourCanvas::rgba_to_color (1, 1, 1, 1)));
+
+       colors.insert (make_pair (KnobForeground, ArdourCanvas::rgba_to_color (1, 1, 1, 1)));
+       colors.insert (make_pair (KnobBackground, ArdourCanvas::rgba_to_color (1, 1, 1, 1)));
+       colors.insert (make_pair (KnobShadow, ArdourCanvas::rgba_to_color (0, 0, 0, 0.1)));
+       colors.insert (make_pair (KnobBorder, ArdourCanvas::rgba_to_color (0, 0, 0, 1)));
+
+}
+
+uint32_t
+Push2::get_color (ColorName name)
+{
+       Colors::iterator c = colors.find (name);
+       if (c != colors.end()) {
+               return c->second;
+       }
+
+       return random();
+}