2 Copyright (C) 2006,2007 John Anderson
3 Copyright (C) 2012 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <glibmm/miscutils.h>
23 #include "pbd/xml++.h"
24 #include "pbd/error.h"
25 #include "pbd/pathscanner.h"
27 #include "ardour/filesystem_paths.h"
29 #include "device_info.h"
33 using namespace Mackie;
35 using namespace ARDOUR;
39 std::map<std::string,DeviceInfo> DeviceInfo::device_info;
41 DeviceInfo::DeviceInfo()
44 , _has_two_character_display (true)
45 , _has_master_fader (true)
46 , _has_segmented_display (false)
47 , _has_timecode_display (true)
48 , _has_global_controls (true)
49 , _has_jog_wheel (true)
50 , _name (X_("Mackie Control Universal Pro"))
55 DeviceInfo::~DeviceInfo()
60 DeviceInfo::set_state (const XMLNode& node, int /* version */)
62 const XMLProperty* prop;
65 if (node.name() != "MackieProtocolDevice") {
69 /* name is mandatory */
71 if ((child = node.child ("Name")) != 0) {
72 if ((prop = child->property ("value")) != 0) {
73 _name = prop->value();
79 if ((child = node.child ("Strips")) != 0) {
80 if ((prop = child->property ("value")) != 0) {
81 if ((_strip_cnt = atoi (prop->value())) == 0) {
87 if ((child = node.child ("Extenders")) != 0) {
88 if ((prop = child->property ("value")) != 0) {
89 if ((_extenders = atoi (prop->value())) == 0) {
95 if ((child = node.child ("TwoCharacterDisplay")) != 0) {
96 if ((prop = child->property ("value")) != 0) {
97 _has_two_character_display = string_is_affirmative (prop->value());
101 if ((child = node.child ("MasterFader")) != 0) {
102 if ((prop = child->property ("value")) != 0) {
103 _has_master_fader = string_is_affirmative (prop->value());
107 if ((child = node.child ("DisplaySegments")) != 0) {
108 if ((prop = child->property ("value")) != 0) {
109 _has_segmented_display = string_is_affirmative (prop->value());
113 if ((child = node.child ("TimecodeDisplay")) != 0) {
114 if ((prop = child->property ("value")) != 0) {
115 _has_timecode_display = string_is_affirmative (prop->value());
119 if ((child = node.child ("GlobalControls")) != 0) {
120 if ((prop = child->property ("value")) != 0) {
121 _has_global_controls = string_is_affirmative (prop->value());
125 if ((child = node.child ("JogWheel")) != 0) {
126 if ((prop = child->property ("value")) != 0) {
127 _has_jog_wheel = string_is_affirmative (prop->value());
135 DeviceInfo::name() const
141 DeviceInfo::strip_cnt() const
147 DeviceInfo::extenders() const
153 DeviceInfo::has_master_fader() const
155 return _has_master_fader;
159 DeviceInfo::has_two_character_display() const
161 return _has_two_character_display;
165 DeviceInfo::has_segmented_display() const
167 return _has_segmented_display;
171 DeviceInfo::has_timecode_display () const
173 return _has_timecode_display;
177 DeviceInfo::has_global_controls () const
179 return _has_global_controls;
183 DeviceInfo::has_jog_wheel () const
185 return _has_jog_wheel;
188 static const char * const devinfo_env_variable_name = "ARDOUR_MCP_DEVINFO_PATH";
189 static const char* const devinfo_dir_name = "mcp_devices";
190 static const char* const devinfo_suffix = ".xml";
193 system_devinfo_search_path ()
195 bool devinfo_path_defined = false;
196 sys::path spath_env (Glib::getenv (devinfo_env_variable_name, devinfo_path_defined));
198 if (devinfo_path_defined) {
202 SearchPath spath (system_data_search_path());
203 spath.add_subdirectory_to_paths(devinfo_dir_name);
205 // just return the first directory in the search path that exists
206 SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
208 if (i == spath.end()) return sys::path();
214 user_devinfo_directory ()
216 sys::path p(user_config_directory());
217 p /= devinfo_dir_name;
223 devinfo_filter (const string &str, void */*arg*/)
225 return (str.length() > strlen(devinfo_suffix) &&
226 str.find (devinfo_suffix) == (str.length() - strlen (devinfo_suffix)));
230 DeviceInfo::reload_device_info ()
234 vector<string *> *devinfos;
236 SearchPath spath (system_devinfo_search_path());
237 spath += user_devinfo_directory ();
239 devinfos = scanner (spath.to_string(), devinfo_filter, 0, false, true);
240 device_info.clear ();
243 error << "No MCP device info files found using " << spath.to_string() << endmsg;
244 std::cerr << "No MCP device info files found using " << spath.to_string() << std::endl;
248 if (devinfos->empty()) {
249 error << "No MCP device info files found using " << spath.to_string() << endmsg;
250 std::cerr << "No MCP device info files found using " << spath.to_string() << std::endl;
254 for (vector<string*>::iterator i = devinfos->begin(); i != devinfos->end(); ++i) {
255 string fullpath = *(*i);
260 if (!tree.read (fullpath.c_str())) {
264 XMLNode* root = tree.root ();
269 if (di.set_state (*root, 3000) == 0) { /* version is ignored for now */
270 device_info[di.name()] = di;
271 std::cerr << di << '\n';
278 std::ostream& operator<< (std::ostream& os, const Mackie::DeviceInfo& di)
280 os << di.name() << ' '
281 << di.strip_cnt() << ' '
282 << di.extenders() << ' '