From 777c7c6c037d604f1456889d7435fa90aa5e8109 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 6 Mar 2023 00:08:38 +0100 Subject: [PATCH] added trackcolors to X-Touch, added _is_xtouch to device info as condition for trackcolors --- libs/surfaces/mackie/device_info.cc | 12 +++++ libs/surfaces/mackie/device_info.h | 2 + libs/surfaces/mackie/surface.cc | 78 ++++++++++++++++++++++++++++- libs/surfaces/mackie/surface.h | 13 +++++ share/mcp/x-touch.device | 1 + 5 files changed, 105 insertions(+), 1 deletion(-) diff --git a/libs/surfaces/mackie/device_info.cc b/libs/surfaces/mackie/device_info.cc index f8ced52c89..df00b11f89 100644 --- a/libs/surfaces/mackie/device_info.cc +++ b/libs/surfaces/mackie/device_info.cc @@ -62,6 +62,7 @@ DeviceInfo::DeviceInfo() , _is_qcon(false) , _is_platformMp(false) , _is_proG2(false) + , _is_xtouch(false) , _has_qcon_second_lcd(false) , _has_qcon_master_meters(false) , _has_meters (true) @@ -340,6 +341,12 @@ DeviceInfo::set_state (const XMLNode& node, int /* version */) } else { _is_qcon = false; } + + if ((child = node.child ("IsXTouch")) != 0) { + child->get_property ("value", _is_xtouch); + } else { + _is_xtouch = false; + } if ((child = node.child ("IsPlatformMp")) != 0) { child->get_property ("value", _is_platformMp); @@ -523,6 +530,11 @@ bool DeviceInfo::is_proG2 () const return _is_proG2; } +bool DeviceInfo::is_xtouch () const +{ + return _is_xtouch; +} + bool DeviceInfo::has_qcon_second_lcd () const { diff --git a/libs/surfaces/mackie/device_info.h b/libs/surfaces/mackie/device_info.h index 745344b59d..93abe73f7b 100644 --- a/libs/surfaces/mackie/device_info.h +++ b/libs/surfaces/mackie/device_info.h @@ -83,6 +83,7 @@ class DeviceInfo bool is_qcon() const; bool is_platformMp() const; bool is_proG2() const; + bool is_xtouch() const; bool has_qcon_second_lcd() const; bool has_qcon_master_meters() const; bool has_meters() const; @@ -118,6 +119,7 @@ class DeviceInfo bool _is_qcon; bool _is_platformMp; bool _is_proG2; + bool _is_xtouch; bool _has_qcon_second_lcd; bool _has_qcon_master_meters; bool _has_meters; diff --git a/libs/surfaces/mackie/surface.cc b/libs/surfaces/mackie/surface.cc index e214a1c4d2..e821db2d7d 100644 --- a/libs/surfaces/mackie/surface.cc +++ b/libs/surfaces/mackie/surface.cc @@ -1190,6 +1190,11 @@ Surface::map_stripables (const vector >& stripables DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Mapping %1 stripables to %2 strips\n", stripables.size(), strips.size())); + + bool xtouch = _mcp.device_info().is_xtouch(); + XTouchColors colors[] { Off, Off, Off, Off, Off, Off, Off, Off }; + uint8_t i = 0; + for (r = stripables.begin(); r != stripables.end() && s != strips.end(); ++s) { /* don't try to assign stripables to a locked strip. it won't @@ -1198,15 +1203,21 @@ Surface::map_stripables (const vector >& stripables */ if (!(*s)->locked()) { + if(xtouch){ + colors[i] = static_cast(convert_color_to_xtouch_value((*r)->presentation_info().color())); + ++i; + } (*s)->set_stripable (*r); ++r; } } - for (; s != strips.end(); ++s) { DEBUG_TRACE (DEBUG::MackieControl, string_compose ("strip %1 being set to null stripable\n", (*s)->index())); (*s)->set_stripable (boost::shared_ptr()); } + if(xtouch){ + _port->write(display_colors_on_xtouch(colors)); //write colors to strips for xtouch + } } static char @@ -1623,3 +1634,68 @@ Surface::display_message_for (string const& msg, uint64_t msecs) (*s)->block_screen_display_for (msecs); } } + +/** display @p color_values on the 8 scribble strips of the X-Touch + * + * @param color_values is assumed to be an array with a color value for each of the 8 scribble strips +*/ +MidiByteArray +Surface::display_colors_on_xtouch(const XTouchColors color_values[]) const +{ + MidiByteArray midi_msg; + midi_msg << sysex_hdr (); + midi_msg << 0x72; + + uint8_t displaycount = 8; + + for(uint8_t i = 0; i < displaycount; ++i){ + midi_msg << color_values[i]; + } + + midi_msg << MIDI::eox; + + return midi_msg; +} + +/** takes trackcolor in 0xRRGGBBAA (Red, Green, Blue, Alpha) and converts it to suitable xtouch colors + * return value can be casted to enum XTouchColor +*/ +uint8_t +Surface::convert_color_to_xtouch_value(uint32_t color) const +{ + uint8_t red = color >> 24; + uint8_t green = (color >> 16) & 0xff; + uint8_t blue = (color >> 8) & 0xff; + + uint8_t max = red; + if(max < green){ + max = green; + } + if(max < blue){ + max = blue; + } + + if(max != 0){ + //set the highest value to 0xFF to be brightness independent + + float norm = 255.0/max; + red = static_cast(red*norm); + green = static_cast(green*norm); + blue = static_cast(blue*norm); + + uint8_t xcolor = 0; + if(red > 0x7f){ + xcolor = xcolor | 0b001; //lowest bit is red + } + if(green > 0x7f){ + xcolor = xcolor | 0b010; //second bit is green + } + if(blue > 0x7f){ + xcolor = xcolor | 0b100; //third bit is blue + } + return xcolor; + } + else{ + return White; //if it would be black (color = 0x000000) return white, because black means off + } +} diff --git a/libs/surfaces/mackie/surface.h b/libs/surfaces/mackie/surface.h index 92247dbf4e..ce2dc81349 100644 --- a/libs/surfaces/mackie/surface.h +++ b/libs/surfaces/mackie/surface.h @@ -68,6 +68,17 @@ class Led; class Surface : public PBD::ScopedConnectionList, public sigc::trackable { public: + enum XTouchColors { + Off, + Red, + Green, + Yellow, + Blue, + Purple, + Cyan, + White, + }; + Surface (MackieControlProtocol&, const std::string& name, uint32_t number, surface_type_t stype); virtual ~Surface(); @@ -245,6 +256,8 @@ public: bool is_qcon; MidiByteArray display_line (std::string const& msg, int line_num); + MidiByteArray display_colors_on_xtouch(const XTouchColors color_values[]) const; + uint8_t convert_color_to_xtouch_value(uint32_t color) const; public: /* IP MIDI devices need to keep a handle on this and destroy it */ diff --git a/share/mcp/x-touch.device b/share/mcp/x-touch.device index 8d46abdcab..937a9a9ad8 100644 --- a/share/mcp/x-touch.device +++ b/share/mcp/x-touch.device @@ -12,4 +12,5 @@ +