#include "pbd/replace_all.h"
#include "pbd/unknown_type.h"
#include "pbd/enumwriter.h"
+#include "pbd/locale_guard.h"
+#include "pbd/types_convert.h"
#include "ardour/audioengine.h"
#include "ardour/buffer.h"
#include "ardour/profile.h"
#include "ardour/route.h"
#include "ardour/session.h"
+#include "ardour/types_convert.h"
#include "ardour/user_bundle.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
#define BLOCK_PROCESS_CALLBACK() Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock())
{
Glib::Threads::Mutex::Lock lm (io_lock);
+ DEBUG_TRACE (DEBUG::Ports, string_compose ("IO %1 unregisters %2 ports\n", name(), _ports.num_ports()));
+
BLOCK_PROCESS_CALLBACK ();
for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
_session.engine().unregister_port (*i);
}
+ delete pending_state_node; pending_state_node = 0;
}
void
IO::disconnect_check (boost::shared_ptr<Port> a, boost::shared_ptr<Port> b)
{
+ if (_session.state_of_the_state () & Session::Deletion) {
+ return;
+ }
/* this could be called from within our own ::disconnect() method(s)
or from somewhere that operates directly on a port. so, we don't
know for sure if we can take this lock or not. if we fail,
#endif
boost::shared_ptr<Port> port;
+ vector<boost::shared_ptr<Port> > deleted_ports;
changed = false;
assert(port);
_ports.remove(port);
+
+ /* hold a reference to the port so that we can ensure
+ * that this thread, and not a JACK notification thread,
+ * holds the final reference.
+ */
+
+ deleted_ports.push_back (port);
_session.engine().unregister_port (port);
changed = true;
}
+ /* this will drop the final reference to the deleted ports,
+ * which will in turn call their destructors, which will in
+ * turn call the backend to unregister them.
+ *
+ * There will no connect/disconnect or register/unregister
+ * callbacks from the backend until we get here, because
+ * they are driven by the Port destructor. The destructor
+ * will not execute until we drop the final reference,
+ * which all happens right .... here.
+ */
+ deleted_ports.clear ();
+
/* create any necessary new ports */
while (n_ports().get(*t) < n) {
IO::state (bool /*full_state*/)
{
XMLNode* node = new XMLNode (state_node_name);
- char buf[64];
- string str;
int n;
- LocaleGuard lg (X_("C"));
Glib::Threads::Mutex::Lock lm (io_lock);
- node->add_property("name", _name);
- id().print (buf, sizeof (buf));
- node->add_property("id", buf);
- node->add_property ("direction", enum_2_string (_direction));
- node->add_property ("default-type", _default_type.to_string());
+ node->set_property ("name", name());
+ node->set_property ("id", id ());
+ node->set_property ("direction", _direction);
+ node->set_property ("default-type", _default_type);
if (!_pretty_name_prefix.empty ()) {
- node->add_property("pretty-name", _pretty_name_prefix);
+ node->set_property("pretty-name", _pretty_name_prefix);
}
for (std::vector<UserBundleInfo*>::iterator i = _bundles_connected.begin(); i != _bundles_connected.end(); ++i) {
XMLNode* n = new XMLNode ("Bundle");
- n->add_property ("name", (*i)->bundle->name ());
+ n->set_property ("name", (*i)->bundle->name ());
node->add_child_nocopy (*n);
}
vector<string> connections;
XMLNode* pnode = new XMLNode (X_("Port"));
- pnode->add_property (X_("type"), i->type().to_string());
- pnode->add_property (X_("name"), i->name());
+ pnode->set_property (X_("type"), i->type());
+ pnode->set_property (X_("name"), i->name());
if (i->get_connections (connections)) {
vector<string>::const_iterator ci;
XMLNode* cnode = new XMLNode (X_("Connection"));
- cnode->add_property (X_("other"), _session.engine().make_port_name_relative (*ci));
+ cnode->set_property (X_("other"), _session.engine().make_port_name_relative (*ci));
pnode->add_child_nocopy (*cnode);
}
}
node->add_child_nocopy (*pnode);
}
- snprintf (buf, sizeof (buf), "%" PRId64, _user_latency);
- node->add_property (X_("user-latency"), buf);
+ node->set_property (X_("user-latency"), _user_latency);
return *node;
}
*/
assert (version >= 3000);
- const XMLProperty* prop;
- XMLNodeConstIterator iter;
- LocaleGuard lg (X_("C"));
-
/* force use of non-localized representation of decimal point,
since we use it a lot in XML files and so forth.
*/
return -1;
}
- if ((prop = node.property ("name")) != 0) {
- set_name (prop->value());
+ bool ignore_name = node.property ("ignore-name");
+ std::string name;
+ if (node.get_property ("name", name) && !ignore_name) {
+ set_name (name);
}
- if ((prop = node.property (X_("default-type"))) != 0) {
- _default_type = DataType(prop->value());
+ if (node.get_property (X_("default-type"), _default_type)) {
assert(_default_type != DataType::NIL);
}
set_id (node);
- if ((prop = node.property ("direction")) != 0) {
- _direction = (Direction) string_2_enum (prop->value(), _direction);
- }
+ node.get_property ("direction", _direction);
if (create_ports (node, version)) {
return -1;
}
// after create_ports, updates names
- if ((prop = node.property ("pretty-name")) != 0) {
- set_pretty_name (prop->value());
+ if (node.get_property ("pretty-name", name)) {
+ set_pretty_name (name);
}
if (connecting_legal) {
} else {
+ delete pending_state_node;
pending_state_node = new XMLNode (node);
pending_state_node_version = version;
pending_state_node_in = false;
ConnectingLegal.connect_same_thread (connection_legal_c, boost::bind (&IO::connecting_became_legal, this));
}
- if ((prop = node.property ("user-latency")) != 0) {
- _user_latency = atoi (prop->value ());
- }
+ node.get_property ("user-latency", _user_latency);
return 0;
}
int
IO::set_state_2X (const XMLNode& node, int version, bool in)
{
- const XMLProperty* prop;
+ XMLProperty const * prop;
XMLNodeConstIterator iter;
- LocaleGuard lg (X_("C"));
+ LocaleGuard lg;
/* force use of non-localized representation of decimal point,
since we use it a lot in XML files and so forth.
} else {
+ delete pending_state_node;
pending_state_node = new XMLNode (node);
pending_state_node_version = version;
pending_state_node_in = in;
string possible_name;
bool stereo = false;
string::size_type last_non_digit_pos;
+ std::string bundle_number_str;
error << string_compose(_("Unknown bundle \"%1\" listed for %2 of %3"), desired_name, bundle_type_name, _name)
<< endmsg;
last_non_digit_pos = desired_name.find_last_not_of(digits);
if (last_non_digit_pos != string::npos) {
- stringstream s;
- s << desired_name.substr(last_non_digit_pos);
- s >> bundle_number;
+ bundle_number_str = desired_name.substr(last_non_digit_pos);
+ bundle_number = string_to<int32_t>(bundle_number_str);
}
// see if it's a stereo connection e.g. "in 3+4"
if (left_last_non_digit_pos != string::npos) {
int left_bundle_number = 0;
- stringstream s;
- s << desired_name.substr(left_last_non_digit_pos, last_non_digit_pos-1);
- s >> left_bundle_number;
+ bundle_number_str = desired_name.substr(left_last_non_digit_pos, last_non_digit_pos-1);
+ left_bundle_number = string_to<int32_t>(bundle_number_str);
if (left_bundle_number > 0 && left_bundle_number + 1 == bundle_number) {
bundle_number--;
if (bundle_number & mask) {
bundle_number &= ~mask;
- stringstream s;
- s << default_name << " " << bundle_number + 1;
+ std::string possible_name = default_name + " " + to_string(bundle_number + 1);
if (stereo) {
- s << "+" << bundle_number + 2;
+ possible_name += "+" + to_string(bundle_number + 2);
}
- possible_name = s.str();
-
if ((c = _session.bundle_by_name (possible_name)) != 0) {
break;
}
return make_connections_2X (node, version, in);
}
- const XMLProperty* prop;
+ XMLProperty const * prop;
for (XMLNodeConstIterator i = node.children().begin(); i != node.children().end(); ++i) {
IO::prepare_for_reset (XMLNode& node, const std::string& name)
{
/* reset name */
- node.add_property ("name", name);
+ node.set_property ("name", name);
/* now find connections and reset the name of the port
in one so that when we re-use it it will match
the name of the thing we're applying it to.
*/
- XMLProperty* prop;
+ XMLProperty * prop;
XMLNodeList children = node.children();
for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
int
IO::make_connections_2X (const XMLNode& node, int /*version*/, bool in)
{
- const XMLProperty* prop;
+ XMLProperty const * prop;
/* XXX: bundles ("connections" as was) */
case 2:
return c == 0 ? _("L") : _("R");
default:
- snprintf (buf, sizeof(buf), _("%d"), (c + 1));
+ snprintf (buf, sizeof(buf), "%d", (c + 1));
return buf;
}
} else {
- snprintf (buf, sizeof(buf), _("%d"), (c + 1));
+ snprintf (buf, sizeof(buf), "%d", (c + 1));
return buf;
}
string
IO::name_from_state (const XMLNode& node)
{
- const XMLProperty* prop;
+ XMLProperty const * prop;
if ((prop = node.property ("name")) != 0) {
return prop->value();
void
IO::set_name_in_state (XMLNode& node, const string& new_name)
{
- node.add_property (X_("name"), new_name);
+ node.set_property (X_("name"), new_name);
XMLNodeList children = node.children ();
for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
if ((*i)->name() == X_("Port")) {
string const old_name = (*i)->property(X_("name"))->value();
string const old_name_second_part = old_name.substr (old_name.find_first_of ("/") + 1);
- (*i)->add_property (X_("name"), string_compose ("%1/%2", new_name, old_name_second_part));
+ (*i)->set_property (X_("name"), string_compose ("%1/%2", new_name, old_name_second_part));
}
}
}
* Caller must hold process lock.
*/
void
-IO::process_input (boost::shared_ptr<Processor> proc, framepos_t start_frame, framepos_t end_frame, pframes_t nframes)
+IO::process_input (boost::shared_ptr<Processor> proc, framepos_t start_frame, framepos_t end_frame, double speed, pframes_t nframes)
{
/* don't read the data into new buffers - just use the port buffers directly */
_buffers.get_backend_port_addresses (_ports, nframes);
if (proc) {
- proc->run (_buffers, start_frame, end_frame, nframes, true);
+ proc->run (_buffers, start_frame, end_frame, speed, nframes, true);
}
}
void
IO::copy_to_outputs (BufferSet& bufs, DataType type, pframes_t nframes, framecnt_t offset)
{
- // Copy any buffers 1:1 to outputs
-
PortSet::iterator o = _ports.begin(type);
BufferSet::iterator i = bufs.begin(type);
BufferSet::iterator prev = i;
+ assert(i != bufs.end(type)); // or second loop will crash
+
+ // Copy any buffers 1:1 to outputs
+
while (i != bufs.end(type) && o != _ports.end (type)) {
Buffer& port_buffer (o->get_buffer (nframes));
port_buffer.read_from (*i, nframes, offset);