- if (ok == false) {
- break;
- }
- }
-
- if (ok) {
- new_list.push_back (*i);
- } else {
- i->configuration_will_change.disconnect ();
- i->configuration_has_changed.disconnect ();
- i->ports_will_change.disconnect ();
- i->ports_have_changed.disconnect ();
- }
- }
-
- list = new_list;
-}
-
-
-int
-IO::disconnect_input (Port* our_port, string other_port, void* src)
-{
- if (other_port.length() == 0 || our_port == 0) {
- return 0;
- }
-
- {
- BLOCK_PROCESS_CALLBACK ();
-
- {
- Glib::Mutex::Lock lm (io_lock);
-
- /* check that our_port is really one of ours */
-
- if ( ! _inputs.contains(our_port)) {
- return -1;
- }
-
- /* disconnect it from the source */
-
- if (_session.engine().disconnect (other_port, our_port->name())) {
- error << string_compose(_("IO: cannot disconnect input port %1 from %2"), our_port->name(), other_port) << endmsg;
- return -1;
- }
-
- check_bundles_connected_to_inputs ();
- }
- }
-
- input_changed (ConnectionsChanged, src); /* EMIT SIGNAL */
- _session.set_dirty ();
-
- return 0;
-}
-
-int
-IO::connect_input (Port* our_port, string other_port, void* src)
-{
- if (other_port.length() == 0 || our_port == 0) {
- return 0;
- }
-
- {
- BLOCK_PROCESS_CALLBACK ();
-
- {
- Glib::Mutex::Lock lm (io_lock);
-
- /* check that our_port is really one of ours */
-
- if ( ! _inputs.contains(our_port) ) {
- return -1;
- }
-
- /* connect it to the source */
-
- if (_session.engine().connect (other_port, our_port->name())) {
- return -1;
- }
- }
- }
-
- input_changed (ConnectionsChanged, src); /* EMIT SIGNAL */
- _session.set_dirty ();
- return 0;
-}
-
-int
-IO::disconnect_output (Port* our_port, string other_port, void* src)
-{
- if (other_port.length() == 0 || our_port == 0) {
- return 0;
- }
-
- {
- BLOCK_PROCESS_CALLBACK ();
-
- {
- Glib::Mutex::Lock lm (io_lock);
-
- /* check that our_port is really one of ours */
-
- if ( ! _outputs.contains(our_port) ) {
- return -1;
- }
-
- /* disconnect it from the destination */
-
- if (_session.engine().disconnect (our_port->name(), other_port)) {
- error << string_compose(_("IO: cannot disconnect output port %1 from %2"), our_port->name(), other_port) << endmsg;
- return -1;
- }
-
- check_bundles_connected_to_outputs ();
- }
- }
-
- output_changed (ConnectionsChanged, src); /* EMIT SIGNAL */
- _session.set_dirty ();
- return 0;
-}
-
-int
-IO::connect_output (Port* our_port, string other_port, void* src)
-{
- if (other_port.length() == 0 || our_port == 0) {
- return 0;
- }
-
- {
- BLOCK_PROCESS_CALLBACK ();
-
-
- {
- Glib::Mutex::Lock lm (io_lock);
-
- /* check that our_port is really one of ours */
-
- if ( ! _outputs.contains(our_port) ) {
- return -1;
- }
-
- /* connect it to the destination */
-
- if (_session.engine().connect (our_port->name(), other_port)) {
- return -1;
- }
- }
- }
-
- output_changed (ConnectionsChanged, src); /* EMIT SIGNAL */
- _session.set_dirty ();
- return 0;
-}
-
-int
-IO::set_input (Port* other_port, void* src)
-{
- /* this removes all but one ports, and connects that one port
- to the specified source.
- */
-
- if (_input_minimum.n_total() > 1) {
- /* sorry, you can't do this */
- return -1;
- }
-
- if (other_port == 0) {
- if (_input_minimum == ChanCount::ZERO) {
- return ensure_inputs (ChanCount::ZERO, false, true, src);
- } else {
- return -1;
- }
- }
-
- if (ensure_inputs (ChanCount(other_port->type(), 1), true, true, src)) {
- return -1;
- }
-
- return connect_input (_inputs.port(0), other_port->name(), src);
-}
-
-int
-IO::remove_output_port (Port* port, void* src)
-{
- IOChange change (NoChange);
-
- {
- BLOCK_PROCESS_CALLBACK ();
-
-
- {
- Glib::Mutex::Lock lm (io_lock);
-
- if (n_outputs() <= _output_minimum) {
- /* sorry, you can't do this */
- return -1;
- }
-
- if (_outputs.remove(port)) {
- change = IOChange (change|ConfigurationChanged);
-
- if (port->connected()) {
- change = IOChange (change|ConnectionsChanged);
- }
-
- _session.engine().unregister_port (*port);
- check_bundles_connected_to_outputs ();
-
- setup_peak_meters ();
- reset_panner ();
- }
- }
-
- PortCountChanged (n_outputs()); /* EMIT SIGNAL */
- }
-
- if (change == ConnectionsChanged) {
- setup_bundles_for_inputs_and_outputs ();
- }
-
- if (change != NoChange) {
- output_changed (change, src);
- _session.set_dirty ();
- return 0;
- }
-
- return -1;
-}
-
-/** Add an output port.
- *
- * @param destination Name of input port to connect new port to.
- * @param src Source for emitted ConfigurationChanged signal.
- * @param type Data type of port. Default value (NIL) will use this IO's default type.
- */
-int
-IO::add_output_port (string destination, void* src, DataType type)
-{
- Port* our_port;
- char name[64];
-
- if (type == DataType::NIL)
- type = _default_type;
-
- {
- BLOCK_PROCESS_CALLBACK ();
-
-
- {
- Glib::Mutex::Lock lm (io_lock);
-
- if (n_outputs() >= _output_maximum) {
- return -1;
- }
-
- /* Create a new output port */
-
- // FIXME: naming scheme for differently typed ports?
- if (_output_maximum.get(type) == 1) {
- snprintf (name, sizeof (name), _("%s/out"), _name.c_str());
- } else {
- snprintf (name, sizeof (name), _("%s/out %u"), _name.c_str(), find_output_port_hole());
- }
-
- if ((our_port = _session.engine().register_output_port (type, name, _public_ports)) == 0) {
- error << string_compose(_("IO: cannot register output port %1"), name) << endmsg;
- return -1;
- }
-
- _outputs.add (our_port);
- setup_peak_meters ();
- reset_panner ();
- }
-
- PortCountChanged (n_outputs()); /* EMIT SIGNAL */
- }
-
- if (destination.length()) {
- if (_session.engine().connect (our_port->name(), destination)) {
- return -1;
- }
- }
-
- // pan_changed (src); /* EMIT SIGNAL */
- output_changed (ConfigurationChanged, src); /* EMIT SIGNAL */
- setup_bundles_for_inputs_and_outputs ();
- _session.set_dirty ();
-
- return 0;
-}
-
-int
-IO::remove_input_port (Port* port, void* src)
-{
- IOChange change (NoChange);
-
- {
- BLOCK_PROCESS_CALLBACK ();
-
-
- {
- Glib::Mutex::Lock lm (io_lock);
-
- if (n_inputs() <= _input_minimum) {
- /* sorry, you can't do this */
- return -1;
- }
-
- if (_inputs.remove(port)) {
- change = IOChange (change|ConfigurationChanged);
-
- if (port->connected()) {
- change = IOChange (change|ConnectionsChanged);
- }
-
- _session.engine().unregister_port (*port);
- check_bundles_connected_to_inputs ();
-
- setup_peak_meters ();
- reset_panner ();
- }
- }
-
- PortCountChanged (n_inputs ()); /* EMIT SIGNAL */
- }
-
- if (change == ConfigurationChanged) {
- setup_bundles_for_inputs_and_outputs ();
- }
-
- if (change != NoChange) {
- input_changed (change, src);
- _session.set_dirty ();
- return 0;
- }
-
- return -1;
-}
-
-
-/** Add an input port.
- *
- * @param type Data type of port. The appropriate port type, and @ref Port will be created.
- * @param destination Name of input port to connect new port to.
- * @param src Source for emitted ConfigurationChanged signal.
- */
-int
-IO::add_input_port (string source, void* src, DataType type)
-{
- Port* our_port;
- char name[64];
-
- if (type == DataType::NIL)
- type = _default_type;
-
- {
- BLOCK_PROCESS_CALLBACK ();
-
- {
- Glib::Mutex::Lock lm (io_lock);
-
- if (n_inputs() >= _input_maximum) {
- return -1;
- }
-
- /* Create a new input port */
-
- // FIXME: naming scheme for differently typed ports?
- if (_input_maximum.get(type) == 1) {
- snprintf (name, sizeof (name), _("%s/in"), _name.c_str());
- } else {
- snprintf (name, sizeof (name), _("%s/in %u"), _name.c_str(), find_input_port_hole());
- }
-
- if ((our_port = _session.engine().register_input_port (type, name, _public_ports)) == 0) {
- error << string_compose(_("IO: cannot register input port %1"), name) << endmsg;
- return -1;
- }
-
- _inputs.add (our_port);
- setup_peak_meters ();
- reset_panner ();
- }
-
- PortCountChanged (n_inputs()); /* EMIT SIGNAL */
- }
-
- if (source.length()) {
-
- if (_session.engine().connect (source, our_port->name())) {
- return -1;
- }
- }
-
- // pan_changed (src); /* EMIT SIGNAL */
- input_changed (ConfigurationChanged, src); /* EMIT SIGNAL */
- setup_bundles_for_inputs_and_outputs ();
- _session.set_dirty ();
-
- return 0;
-}
-
-int
-IO::disconnect_inputs (void* src)
-{
- {
- BLOCK_PROCESS_CALLBACK ();
-
- {
- Glib::Mutex::Lock lm (io_lock);
-
- for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
- _session.engine().disconnect (*i);
- }
-
- check_bundles_connected_to_inputs ();
- }
- }
-
- input_changed (ConnectionsChanged, src); /* EMIT SIGNAL */
-
- return 0;
-}
-
-int
-IO::disconnect_outputs (void* src)
-{
- {
- BLOCK_PROCESS_CALLBACK ();
-
- {
- Glib::Mutex::Lock lm (io_lock);
-
- for (PortSet::iterator i = _outputs.begin(); i != _outputs.end(); ++i) {
- _session.engine().disconnect (*i);
- }
-
- check_bundles_connected_to_outputs ();
- }
- }
-
- output_changed (ConnectionsChanged, src); /* EMIT SIGNAL */
- _session.set_dirty ();
-
- return 0;
-}
-
-bool
-IO::ensure_inputs_locked (ChanCount count, bool clear, void* src)
-{
- Port* input_port = 0;
- bool changed = false;
-
-
- for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
-
- const size_t n = count.get(*t);
-
- /* remove unused ports */
- for (size_t i = n_inputs().get(*t); i > n; --i) {
- input_port = _inputs.port(*t, i-1);
-
- assert(input_port);
- _inputs.remove(input_port);
- _session.engine().unregister_port (*input_port);
-
- changed = true;
- }
-
- /* create any necessary new ports */
- while (n_inputs().get(*t) < n) {
-
- char buf[64];
-
- if (_input_maximum.get(*t) == 1) {
- snprintf (buf, sizeof (buf), _("%s/in"), _name.c_str());
- } else {
- snprintf (buf, sizeof (buf), _("%s/in %u"), _name.c_str(), find_input_port_hole());
- }
-
- try {
-
- if ((input_port = _session.engine().register_input_port (*t, buf, _public_ports)) == 0) {
- error << string_compose(_("IO: cannot register input port %1"), buf) << endmsg;
- return -1;
- }
- }
-
- catch (AudioEngine::PortRegistrationFailure& err) {
- setup_peak_meters ();
- reset_panner ();
- /* pass it on */
- throw AudioEngine::PortRegistrationFailure();
- }
-
- _inputs.add (input_port);
- changed = true;
- }
- }
-
- if (changed) {
- check_bundles_connected_to_inputs ();
- setup_peak_meters ();
- reset_panner ();
- PortCountChanged (n_inputs()); /* EMIT SIGNAL */
- _session.set_dirty ();
- }
-
- if (clear) {
- /* disconnect all existing ports so that we get a fresh start */
- for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
- _session.engine().disconnect (*i);