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 , _has_touch_sense_faders (true)
51 , _name (X_("Mackie Control Universal Pro"))
56 DeviceInfo::~DeviceInfo()
61 DeviceInfo::set_state (const XMLNode& node, int /* version */)
63 const XMLProperty* prop;
66 if (node.name() != "MackieProtocolDevice") {
70 /* name is mandatory */
72 if ((child = node.child ("Name")) != 0) {
73 if ((prop = child->property ("value")) != 0) {
74 _name = prop->value();
80 if ((child = node.child ("Strips")) != 0) {
81 if ((prop = child->property ("value")) != 0) {
82 if ((_strip_cnt = atoi (prop->value())) == 0) {
88 if ((child = node.child ("Extenders")) != 0) {
89 if ((prop = child->property ("value")) != 0) {
90 if ((_extenders = atoi (prop->value())) == 0) {
96 if ((child = node.child ("TwoCharacterDisplay")) != 0) {
97 if ((prop = child->property ("value")) != 0) {
98 _has_two_character_display = string_is_affirmative (prop->value());
102 if ((child = node.child ("MasterFader")) != 0) {
103 if ((prop = child->property ("value")) != 0) {
104 _has_master_fader = string_is_affirmative (prop->value());
108 if ((child = node.child ("DisplaySegments")) != 0) {
109 if ((prop = child->property ("value")) != 0) {
110 _has_segmented_display = string_is_affirmative (prop->value());
114 if ((child = node.child ("TimecodeDisplay")) != 0) {
115 if ((prop = child->property ("value")) != 0) {
116 _has_timecode_display = string_is_affirmative (prop->value());
120 if ((child = node.child ("GlobalControls")) != 0) {
121 if ((prop = child->property ("value")) != 0) {
122 _has_global_controls = string_is_affirmative (prop->value());
126 if ((child = node.child ("JogWheel")) != 0) {
127 if ((prop = child->property ("value")) != 0) {
128 _has_jog_wheel = string_is_affirmative (prop->value());
132 if ((child = node.child ("TouchSenseFaders")) != 0) {
133 if ((prop = child->property ("value")) != 0) {
134 _has_touch_sense_faders = string_is_affirmative (prop->value());
142 DeviceInfo::name() const
148 DeviceInfo::strip_cnt() const
154 DeviceInfo::extenders() const
160 DeviceInfo::has_master_fader() const
162 return _has_master_fader;
166 DeviceInfo::has_two_character_display() const
168 return _has_two_character_display;
172 DeviceInfo::has_segmented_display() const
174 return _has_segmented_display;
178 DeviceInfo::has_timecode_display () const
180 return _has_timecode_display;
184 DeviceInfo::has_global_controls () const
186 return _has_global_controls;
190 DeviceInfo::has_jog_wheel () const
192 return _has_jog_wheel;
196 DeviceInfo::has_touch_sense_faders () const
198 return _has_touch_sense_faders;
201 static const char * const devinfo_env_variable_name = "ARDOUR_MCP_DEVINFO_PATH";
202 static const char* const devinfo_dir_name = "mcp_devices";
203 static const char* const devinfo_suffix = ".xml";
206 system_devinfo_search_path ()
208 bool devinfo_path_defined = false;
209 sys::path spath_env (Glib::getenv (devinfo_env_variable_name, devinfo_path_defined));
211 if (devinfo_path_defined) {
215 SearchPath spath (system_data_search_path());
216 spath.add_subdirectory_to_paths(devinfo_dir_name);
218 // just return the first directory in the search path that exists
219 SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
221 if (i == spath.end()) return sys::path();
227 user_devinfo_directory ()
229 sys::path p(user_config_directory());
230 p /= devinfo_dir_name;
236 devinfo_filter (const string &str, void */*arg*/)
238 return (str.length() > strlen(devinfo_suffix) &&
239 str.find (devinfo_suffix) == (str.length() - strlen (devinfo_suffix)));
243 DeviceInfo::reload_device_info ()
247 vector<string *> *devinfos;
249 SearchPath spath (system_devinfo_search_path());
250 spath += user_devinfo_directory ();
252 devinfos = scanner (spath.to_string(), devinfo_filter, 0, false, true);
253 device_info.clear ();
256 error << "No MCP device info files found using " << spath.to_string() << endmsg;
257 std::cerr << "No MCP device info files found using " << spath.to_string() << std::endl;
261 if (devinfos->empty()) {
262 error << "No MCP device info files found using " << spath.to_string() << endmsg;
263 std::cerr << "No MCP device info files found using " << spath.to_string() << std::endl;
267 for (vector<string*>::iterator i = devinfos->begin(); i != devinfos->end(); ++i) {
268 string fullpath = *(*i);
273 if (!tree.read (fullpath.c_str())) {
277 XMLNode* root = tree.root ();
282 if (di.set_state (*root, 3000) == 0) { /* version is ignored for now */
283 device_info[di.name()] = di;
284 std::cerr << di << '\n';
291 std::ostream& operator<< (std::ostream& os, const Mackie::DeviceInfo& di)
293 os << di.name() << ' '
294 << di.strip_cnt() << ' '
295 << di.extenders() << ' '