enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / libs / surfaces / mackie / device_info.cc
index f12a4671014b5bcd503b9d812687117b615b2603..dfac991cca8d9e63f61e20b061677b51a0518bc9 100644 (file)
 
 #include "pbd/xml++.h"
 #include "pbd/error.h"
-#include "pbd/pathscanner.h"
+#include "pbd/file_utils.h"
+#include "pbd/convert.h"
+#include "pbd/stl_delete.h"
 
 #include "ardour/filesystem_paths.h"
 
 #include "device_info.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
-using namespace Mackie;
 using namespace PBD;
 using namespace ARDOUR;
+using namespace ArdourSurface;
+using namespace Mackie;
+
 using std::string;
 using std::vector;
 
@@ -42,6 +46,7 @@ std::map<std::string,DeviceInfo> DeviceInfo::device_info;
 DeviceInfo::DeviceInfo()
        : _strip_cnt (8)
        , _extenders (0)
+       , _master_position (0)
        , _has_two_character_display (true)
        , _has_master_fader (true)
        , _has_timecode_display (true)
@@ -52,6 +57,8 @@ DeviceInfo::DeviceInfo()
        , _uses_ipmidi (false)
        , _no_handshake (false)
        , _has_meters (true)
+       , _has_separate_meters (false)
+       , _device_type (MCU)
        , _name (X_("Mackie Control Universal Pro"))
 {
        mackie_control_buttons ();
@@ -61,11 +68,21 @@ DeviceInfo::~DeviceInfo()
 {
 }
 
+GlobalButtonInfo&
+DeviceInfo::get_global_button(Button::ID id)
+{
+       GlobalButtonsInfo::iterator it;
+
+       it = _global_buttons.find (id);
+
+       return it->second;
+}
+
 std::string&
 DeviceInfo::get_global_button_name(Button::ID id)
 {
-       std::map<Button::ID,GlobalButtonInfo>::iterator it;
-       
+       GlobalButtonsInfo::iterator it;
+
        it = _global_buttons.find (id);
        if (it == _global_buttons.end ()) {
                _global_button_name = "";
@@ -80,16 +97,15 @@ DeviceInfo::mackie_control_buttons ()
 {
        _global_buttons.clear ();
        shared_buttons ();
-       
+
        _global_buttons[Button::UserA] = GlobalButtonInfo ("Rear Panel User Switch 1", "user", 0x66);
        _global_buttons[Button::UserB] = GlobalButtonInfo ("Rear Panel User Switch 2", "user", 0x67);
-       
-       //TODO Implement "rear panel external control": a connection for a resistive 
-       //TODO element expression pedal . Message: 0xb0 0x2e 0xVV where 0xVV = external 
+
+       //TODO Implement "rear panel external control": a connection for a resistive
+       //TODO element expression pedal . Message: 0xb0 0x2e 0xVV where 0xVV = external
        //TODO controller position value (0x00 to 0x7f)
-       
+
        _strip_buttons[Button::RecEnable] = StripButtonInfo (0x0, "Rec");
-       _strip_buttons[Button::FaderTouch] = StripButtonInfo (0xe0, "Fader Touch");
 }
 
 void
@@ -97,12 +113,11 @@ DeviceInfo::logic_control_buttons ()
 {
        _global_buttons.clear ();
        shared_buttons ();
-       
+
        _global_buttons[Button::UserA] = GlobalButtonInfo ("User Switch A", "user", 0x66);
        _global_buttons[Button::UserB] = GlobalButtonInfo ("User Switch B", "user", 0x67);
 
        _strip_buttons[Button::RecEnable] = StripButtonInfo (0x0, "Rec/Rdy");
-       _strip_buttons[Button::FaderTouch] = StripButtonInfo (0x68, "Fader Touch");
 }
 
 void
@@ -114,7 +129,7 @@ DeviceInfo::shared_buttons ()
        _global_buttons[Button::Plugin] = GlobalButtonInfo ("Plugin", "assignment", 0x2b);
        _global_buttons[Button::Eq] = GlobalButtonInfo ("Eq", "assignment", 0x2c);
        _global_buttons[Button::Dyn] = GlobalButtonInfo ("Instrument", "assignment", 0x2d);
-       
+
        _global_buttons[Button::Left] = GlobalButtonInfo ("Bank Left", "bank", 0x2e);
        _global_buttons[Button::Right] = GlobalButtonInfo ("Bank Right", "bank", 0x2f);
        _global_buttons[Button::ChannelLeft] = GlobalButtonInfo ("Channel Left", "bank", 0x30);
@@ -124,7 +139,7 @@ DeviceInfo::shared_buttons ()
 
        _global_buttons[Button::NameValue] = GlobalButtonInfo ("Name/Value", "display", 0x34);
        _global_buttons[Button::TimecodeBeats] = GlobalButtonInfo ("Timecode/Beats", "display", 0x35);
-       
+
        _global_buttons[Button::F1] = GlobalButtonInfo ("F1", "function select", 0x36);
        _global_buttons[Button::F2] = GlobalButtonInfo ("F2", "function select", 0x37);
        _global_buttons[Button::F3] = GlobalButtonInfo ("F3", "function select", 0x38);
@@ -133,7 +148,7 @@ DeviceInfo::shared_buttons ()
        _global_buttons[Button::F6] = GlobalButtonInfo ("F6", "function select", 0x3b);
        _global_buttons[Button::F7] = GlobalButtonInfo ("F7", "function select", 0x3c);
        _global_buttons[Button::F8] = GlobalButtonInfo ("F8", "function select", 0x3d);
-       
+
        _global_buttons[Button::MidiTracks] = GlobalButtonInfo ("MIDI Tracks", "global view", 0x3e);
        _global_buttons[Button::Inputs] = GlobalButtonInfo ("Inputs", "global view", 0x3f);
        _global_buttons[Button::AudioTracks] = GlobalButtonInfo ("Audio Tracks", "global view", 0x40);
@@ -142,19 +157,19 @@ DeviceInfo::shared_buttons ()
        _global_buttons[Button::Busses] = GlobalButtonInfo ("Busses", "global view", 0x43);
        _global_buttons[Button::Outputs] = GlobalButtonInfo ("Outputs", "global view", 0x44);
        _global_buttons[Button::User] = GlobalButtonInfo ("User", "global view", 0x45);
-       
+
        _global_buttons[Button::Shift] = GlobalButtonInfo ("Shift", "modifiers", 0x46);
        _global_buttons[Button::Option] = GlobalButtonInfo ("Option", "modifiers", 0x47);
        _global_buttons[Button::Ctrl] = GlobalButtonInfo ("Ctrl", "modifiers", 0x48);
        _global_buttons[Button::CmdAlt] = GlobalButtonInfo ("Cmd/Alt", "modifiers", 0x49);
-       
+
        _global_buttons[Button::Read] = GlobalButtonInfo ("Read/Off", "automation", 0x4a);
        _global_buttons[Button::Write] = GlobalButtonInfo ("Write", "automation", 0x4b);
        _global_buttons[Button::Trim] = GlobalButtonInfo ("Trim", "automation", 0x4c);
        _global_buttons[Button::Touch] = GlobalButtonInfo ("Touch", "automation", 0x4d);
        _global_buttons[Button::Latch] = GlobalButtonInfo ("Latch", "automation", 0x4e);
        _global_buttons[Button::Grp] = GlobalButtonInfo ("Group", "automation", 0x4f);
-       
+
        _global_buttons[Button::Save] = GlobalButtonInfo ("Save", "utilities", 0x50);
        _global_buttons[Button::Undo] = GlobalButtonInfo ("Undo", "utilities", 0x51);
        _global_buttons[Button::Cancel] = GlobalButtonInfo ("Cancel", "utilities", 0x52);
@@ -166,14 +181,14 @@ DeviceInfo::shared_buttons ()
        _global_buttons[Button::Drop] = GlobalButtonInfo ("Drop", "transport", 0x57);
        _global_buttons[Button::Replace] = GlobalButtonInfo ("Replace", "transport", 0x58);
        _global_buttons[Button::Click] = GlobalButtonInfo ("Click", "transport", 0x59);
-       _global_buttons[Button::Solo] = GlobalButtonInfo ("Solo", "transport", 0x5a);
-       
+       _global_buttons[Button::ClearSolo] = GlobalButtonInfo ("Solo", "transport", 0x5a);
+
        _global_buttons[Button::Rewind] = GlobalButtonInfo ("Rewind", "transport", 0x5b);
        _global_buttons[Button::Ffwd] = GlobalButtonInfo ("Fast Fwd", "transport", 0x5c);
        _global_buttons[Button::Stop] = GlobalButtonInfo ("Stop", "transport", 0x5d);
        _global_buttons[Button::Play] = GlobalButtonInfo ("Play", "transport", 0x5e);
        _global_buttons[Button::Record] = GlobalButtonInfo ("Record", "transport", 0x5f);
-       
+
        _global_buttons[Button::CursorUp] = GlobalButtonInfo ("Cursor Up", "cursor", 0x60);
        _global_buttons[Button::CursorDown] = GlobalButtonInfo ("Cursor Down", "cursor", 0x61);
        _global_buttons[Button::CursorLeft] = GlobalButtonInfo ("Cursor Left", "cursor", 0x62);
@@ -185,6 +200,10 @@ DeviceInfo::shared_buttons ()
        _strip_buttons[Button::Mute] = StripButtonInfo (0x10, "Mute");
        _strip_buttons[Button::Select] = StripButtonInfo (0x18, "Select");
        _strip_buttons[Button::VSelect] = StripButtonInfo (0x20, "V-Select");
+
+       _strip_buttons[Button::FaderTouch] = StripButtonInfo (0x68, "Fader Touch");
+
+       _global_buttons[Button::MasterFaderTouch] = GlobalButtonInfo ("Master Fader Touch", "master", 0x70);
 }
 
 int
@@ -197,8 +216,29 @@ DeviceInfo::set_state (const XMLNode& node, int /* version */)
                return -1;
        }
 
+       /* Device type ought to be mandatory but early versions missed it */
+       if ((child = node.child ("DeviceType")) != 0) {
+               if ((prop = child->property ("value")) != 0) {
+                       if (prop->value() == X_("MCU")) {
+                               _device_type = MCU;
+                       } else if (prop->value() == X_("MCXT")) {
+                               _device_type = MCXT;
+                       } else if (prop->value() == X_("LC")) {
+                               _device_type = LC;
+                       } else if (prop->value() == X_("LCXT")) {
+                               _device_type = LCXT;
+                       } else if (prop->value() == X_("HUI")) {
+                               _device_type = HUI;
+                       } else {
+                               error << string_compose (_("Unknown Mackie device type \"%1\" used in device info file, using MCU instead"), prop->value()) << endmsg;
+                               _device_type = MCU;
+                       }
+               } else {
+                       _device_type = MCU;
+               }
+       }
+
        /* name is mandatory */
        if ((child = node.child ("Name")) != 0) {
                if ((prop = child->property ("value")) != 0) {
                        _name = prop->value();
@@ -208,10 +248,9 @@ DeviceInfo::set_state (const XMLNode& node, int /* version */)
        }
 
        /* strip count is mandatory */
-
        if ((child = node.child ("Strips")) != 0) {
                if ((prop = child->property ("value")) != 0) {
-                       if ((_strip_cnt = atoi (prop->value())) == 0) {
+                       if ((_strip_cnt = atoi (prop->value().c_str())) == 0) {
                                _strip_cnt = 8;
                        }
                }
@@ -221,12 +260,22 @@ DeviceInfo::set_state (const XMLNode& node, int /* version */)
 
        if ((child = node.child ("Extenders")) != 0) {
                if ((prop = child->property ("value")) != 0) {
-                       if ((_extenders = atoi (prop->value())) == 0) {
+                       if ((_extenders = atoi (prop->value().c_str())) == 0) {
                                _extenders = 0;
                        }
                }
        }
 
+       if ((child = node.child ("MasterPosition")) != 0) {
+               if ((prop = child->property ("value")) != 0) {
+                       if ((_master_position = atoi (prop->value().c_str())) == 0) {
+                               _master_position = 0;
+                       } else if (_master_position > 0) {
+                               _master_position --;
+                       }
+               }
+       }
+
        if ((child = node.child ("TwoCharacterDisplay")) != 0) {
                if ((prop = child->property ("value")) != 0) {
                        _has_two_character_display = string_is_affirmative (prop->value());
@@ -295,6 +344,14 @@ DeviceInfo::set_state (const XMLNode& node, int /* version */)
                _has_meters = true;
        }
 
+       if ((child = node.child ("HasSeparateMeters")) != 0) {
+               if ((prop = child->property ("value")) != 0) {
+                       _has_separate_meters = string_is_affirmative (prop->value());
+               }
+       } else {
+               _has_separate_meters = false;
+       }
+
        if ((child = node.child ("LogicControlButtons")) != 0) {
                if ((prop = child->property ("value")) != 0) {
                        _uses_logic_control_buttons = string_is_affirmative (prop->value());
@@ -322,16 +379,16 @@ DeviceInfo::set_state (const XMLNode& node, int /* version */)
                                                        std::map<Button::ID,GlobalButtonInfo>::iterator b = _global_buttons.find (bid);
                                                        if (b != _global_buttons.end()) {
                                                                b->second.id = val;
-                                                               
+
                                                                if ((prop = (*i)->property ("label")) != 0) {
                                                                        b->second.label = prop->value();
                                                                }
                                                        }
                                                }
                                        }
-                                       
+
                                }
-                               
+
                        } else if ((*i)->name() == "StripButton") {
                                if ((prop = (*i)->property ("name")) != 0) {
                                        int id = Button::name_to_id (prop->value());
@@ -345,9 +402,9 @@ DeviceInfo::set_state (const XMLNode& node, int /* version */)
                                                        }
                                                }
                                        }
-                                       
+
                                }
-                               
+
                        }
                }
        }
@@ -373,6 +430,12 @@ DeviceInfo::extenders() const
        return _extenders;
 }
 
+uint32_t
+DeviceInfo::master_position() const
+{
+       return _master_position;
+}
+
 bool
 DeviceInfo::has_master_fader() const
 {
@@ -385,6 +448,12 @@ DeviceInfo::has_meters() const
        return _has_meters;
 }
 
+bool
+DeviceInfo::has_separate_meters() const
+{
+       return _has_separate_meters;
+}
+
 bool
 DeviceInfo::has_two_character_display() const
 {
@@ -431,24 +500,24 @@ static const char * const devinfo_env_variable_name = "ARDOUR_MCP_PATH";
 static const char* const devinfo_dir_name = "mcp";
 static const char* const devinfo_suffix = ".device";
 
-static SearchPath
+static Searchpath
 devinfo_search_path ()
 {
        bool devinfo_path_defined = false;
-        sys::path spath_env (Glib::getenv (devinfo_env_variable_name, devinfo_path_defined));
+        std::string spath_env (Glib::getenv (devinfo_env_variable_name, devinfo_path_defined));
 
        if (devinfo_path_defined) {
                return spath_env;
        }
 
-       SearchPath spath (ardour_data_search_path());
+       Searchpath spath (ardour_data_search_path());
        spath.add_subdirectory_to_paths(devinfo_dir_name);
 
        return spath;
 }
 
 static bool
-devinfo_filter (const string &str, void */*arg*/)
+devinfo_filter (const string &str, void/*arg*/)
 {
        return (str.length() > strlen(devinfo_suffix) &&
                str.find (devinfo_suffix) == (str.length() - strlen (devinfo_suffix)));
@@ -457,33 +526,25 @@ devinfo_filter (const string &str, void */*arg*/)
 void
 DeviceInfo::reload_device_info ()
 {
-       DeviceInfo di;
        vector<string> s;
-       vector<string *> *devinfos;
-       PathScanner scanner;
-       SearchPath spath (devinfo_search_path());
+       vector<string> devinfos;
+       Searchpath spath (devinfo_search_path());
 
-       devinfos = scanner (spath.to_string(), devinfo_filter, 0, false, true);
+       find_files_matching_filter (devinfos, spath, devinfo_filter, 0, false, true);
        device_info.clear ();
 
-       if (!devinfos) {
-               error << "No MCP device info files found using " << spath.to_string() << endmsg;
-               std::cerr << "No MCP device info files found using " << spath.to_string() << std::endl;
-               return;
-       }
-
-       if (devinfos->empty()) {
+       if (devinfos.empty()) {
                error << "No MCP device info files found using " << spath.to_string() << endmsg;
                std::cerr << "No MCP device info files found using " << spath.to_string() << std::endl;
                return;
        }
 
-       for (vector<string*>::iterator i = devinfos->begin(); i != devinfos->end(); ++i) {
-               string fullpath = *(*i);
+       for (vector<string>::iterator i = devinfos.begin(); i != devinfos.end(); ++i) {
+               string fullpath = *i;
+               DeviceInfo di; // has to be initial every loop or info from last added.
 
                XMLTree tree;
 
-
                if (!tree.read (fullpath.c_str())) {
                        continue;
                }
@@ -497,15 +558,14 @@ DeviceInfo::reload_device_info ()
                        device_info[di.name()] = di;
                }
        }
-
-       delete devinfos;
 }
 
 std::ostream& operator<< (std::ostream& os, const Mackie::DeviceInfo& di)
 {
-       os << di.name() << ' ' 
+       os << di.name() << ' '
           << di.strip_cnt() << ' '
           << di.extenders() << ' '
+          << di.master_position() << ' '
                ;
        return os;
 }