#include <dlfcn.h>
+#include <glibmm/fileutils.h>
+
#include "pbd/compose.h"
#include "pbd/file_utils.h"
#include "pbd/error.h"
#include "control_protocol/control_protocol.h"
-#include "ardour/session.h"
+#include "ardour/debug.h"
#include "ardour/control_protocol_manager.h"
#include "ardour/control_protocol_search_path.h"
ControlProtocolManager::ControlProtocolManager ()
{
-
}
ControlProtocolManager::~ControlProtocolManager()
if ((*i)->requested || (*i)->mandatory) {
instantiate (**i);
(*i)->requested = false;
-
- if ((*i)->protocol && (*i)->state) {
- (*i)->protocol->set_state (*(*i)->state, Stateful::loading_state_version);
+
+ if ((*i)->protocol) {
+ if ((*i)->state) {
+ (*i)->protocol->set_state (*(*i)->state, Stateful::loading_state_version);
+ } else {
+ /* guarantee a call to
+ set_state() whether we have
+ existing state or not
+ */
+ (*i)->protocol->set_state (XMLNode(""), Stateful::loading_state_version);
+ }
}
}
}
}
cpi.protocol = 0;
+ delete cpi.state;
+ cpi.state = 0;
dlclose (cpi.descriptor->module);
return 0;
}
for (list<ControlProtocolInfo*>::iterator i = control_protocol_info.begin(); i != control_protocol_info.end(); ++i) {
if ((*i)->mandatory && ((*i)->protocol == 0)) {
- info << string_compose (_("Instantiating mandatory control protocol %1"), (*i)->name) << endmsg;
+ DEBUG_TRACE (DEBUG::ControlProtocols,
+ string_compose (_("Instantiating mandatory control protocol %1"), (*i)->name));
instantiate (**i);
}
}
Glib::PatternSpec dylib_extension_pattern("*.dylib");
find_matching_files_in_search_path (control_protocol_search_path (),
- so_extension_pattern, cp_modules);
+ so_extension_pattern, cp_modules);
find_matching_files_in_search_path (control_protocol_search_path (),
- dylib_extension_pattern, cp_modules);
-
- info << string_compose (_("looking for control protocols in %1"), control_protocol_search_path().to_string()) << endmsg;
+ dylib_extension_pattern, cp_modules);
+ DEBUG_TRACE (DEBUG::ControlProtocols,
+ string_compose (_("looking for control protocols in %1\n"), control_protocol_search_path().to_string()));
+
for (vector<sys::path>::iterator i = cp_modules.begin(); i != cp_modules.end(); ++i) {
control_protocol_discover ((*i).to_string());
}
{
ControlProtocolDescriptor* descriptor;
+#ifdef __APPLE__
+ /* don't load OS X shared objects that are just symlinks to the real thing.
+ */
+
+ if (path.find (".dylib") && Glib::file_test (path, Glib::FILE_TEST_IS_SYMLINK)) {
+ return 0;
+ }
+#endif
+
if ((descriptor = get_descriptor (path)) != 0) {
if (!descriptor->probe (descriptor)) {
- info << string_compose (_("Control protocol %1 not usable"), descriptor->name) << endmsg;
+ DEBUG_TRACE (DEBUG::ControlProtocols,
+ string_compose (_("Control protocol %1 not usable"), descriptor->name));
} else {
ControlProtocolInfo* cpi = new ControlProtocolInfo ();
control_protocol_info.push_back (cpi);
- info << string_compose(_("Control surface protocol discovered: \"%1\""), cpi->name) << endmsg;
+ DEBUG_TRACE (DEBUG::ControlProtocols,
+ string_compose(_("Control surface protocol discovered: \"%1\""), cpi->name));
}
dlclose (descriptor->module);
if (prop && string_is_affirmative (prop->value())) {
if ((prop = (*citer)->property (X_("name"))) != 0) {
ControlProtocolInfo* cpi = cpi_by_name (prop->value());
+
if (cpi) {
- if (!(*citer)->children().empty()) {
- cpi->state = (*citer)->children().front ();
- } else {
- cpi->state = 0;
+
+ if (cpi->state) {
+ delete cpi->state;
}
+ cpi->state = new XMLNode (**citer);
+
if (_session) {
instantiate (*cpi);
} else {
return *_instance;
}
+
+void
+ControlProtocolManager::midi_connectivity_established ()
+{
+ Glib::Mutex::Lock lm (protocols_lock);
+
+ for (list<ControlProtocol*>::iterator p = control_protocols.begin(); p != control_protocols.end(); ++p) {
+ (*p)->midi_connectivity_established ();
+ }
+}