+
+void
+IO::set_active (bool yn)
+{
+ _active = yn;
+ active_changed(); /* EMIT SIGNAL */
+}
+
+
+AudioPort*
+IO::audio_input(uint32_t n) const
+{
+ return dynamic_cast<AudioPort*>(input(n));
+}
+
+AudioPort*
+IO::audio_output(uint32_t n) const
+{
+ return dynamic_cast<AudioPort*>(output(n));
+}
+
+MidiPort*
+IO::midi_input(uint32_t n) const
+{
+ return dynamic_cast<MidiPort*>(input(n));
+}
+
+MidiPort*
+IO::midi_output(uint32_t n) const
+{
+ return dynamic_cast<MidiPort*>(output(n));
+}
+
+void
+IO::set_phase_invert (bool yn, void *src)
+{
+ if (_phase_invert != yn) {
+ _phase_invert = yn;
+ // phase_invert_changed (src); /* EMIT SIGNAL */
+ }
+}
+
+void
+IO::set_denormal_protection (bool yn, void *src)
+{
+ if (_denormal_protection != yn) {
+ _denormal_protection = yn;
+ // denormal_protection_changed (src); /* EMIT SIGNAL */
+ }
+}
+
+void
+IO::update_port_total_latencies ()
+{
+ /* io_lock, not taken: function must be called from Session::process() calltree */
+
+ for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
+ _session.engine().update_total_latency (*i);
+ }
+
+ for (PortSet::iterator i = _outputs.begin(); i != _outputs.end(); ++i) {
+ _session.engine().update_total_latency (*i);
+ }
+}
+
+
+/**
+ * Setup bundles that describe our inputs and outputs.
+ */
+
+void
+IO::setup_bundles_for_inputs_and_outputs ()
+{
+ char buf[32];
+
+ snprintf(buf, sizeof (buf), _("%s in"), _name.c_str());
+ _bundle_for_inputs->set_name (buf);
+ uint32_t const ni = inputs().num_ports();
+ _bundle_for_inputs->set_channels (ni);
+ for (uint32_t i = 0; i < ni; ++i) {
+ _bundle_for_inputs->set_port (i, inputs().port(i)->name());
+ }
+
+ snprintf(buf, sizeof (buf), _("%s out"), _name.c_str());
+ _bundle_for_outputs->set_name (buf);
+ uint32_t const no = outputs().num_ports();
+ _bundle_for_outputs->set_channels (no);
+ for (uint32_t i = 0; i < no; ++i) {
+ _bundle_for_outputs->set_port (i, outputs().port(i)->name());
+ }
+}
+
+
+/**
+ * Create and setup bundles that describe our inputs and outputs.
+ */
+
+void
+IO::create_bundles_for_inputs_and_outputs ()
+{
+ _bundle_for_inputs = boost::shared_ptr<AutoBundle> (new AutoBundle (true));
+ _bundle_for_outputs = boost::shared_ptr<AutoBundle> (new AutoBundle (false));
+ setup_bundles_for_inputs_and_outputs ();
+}
+
+/** Add a bundle to a list if is connected to our inputs.
+ * @param b Bundle to check.
+ * @param bundles List to add to.
+ */
+void
+IO::maybe_add_input_bundle_to_list (boost::shared_ptr<Bundle> b, std::vector<boost::shared_ptr<Bundle> >* bundles)
+{
+ boost::shared_ptr<AutoBundle> ab = boost::dynamic_pointer_cast<AutoBundle, Bundle> (b);
+
+ if (ab == 0 || ab->ports_are_outputs() == false) {
+ return;
+ }
+
+ if (ab->nchannels().get (default_type()) != n_inputs().n_total ()) {
+ return;
+ }
+
+ for (uint32_t i = 0; i < n_inputs().n_total (); ++i) {
+
+ PortList const & pl = b->channel_ports (i);
+
+ if (pl.empty()) {
+ return;
+ }
+
+ if (!input(i)->connected_to (pl[0])) {
+ return;
+ }
+ }
+
+ bundles->push_back (b);
+}
+
+/** @return Bundles connected to our inputs */
+std::vector<boost::shared_ptr<Bundle> >
+IO::bundles_connected_to_inputs ()
+{
+ std::vector<boost::shared_ptr<Bundle> > bundles;
+
+ /* User bundles */
+ for (std::vector<UserBundleInfo>::iterator i = _bundles_connected_to_inputs.begin(); i != _bundles_connected_to_inputs.end(); ++i) {
+ bundles.push_back (i->bundle);
+ }
+
+ /* Auto bundles */
+ _session.foreach_bundle (
+ sigc::bind (sigc::mem_fun (*this, &IO::maybe_add_input_bundle_to_list), &bundles)
+ );
+
+ return bundles;
+}
+
+
+/** Add a bundle to a list if is connected to our outputs.
+ * @param b Bundle to check.
+ * @param bundles List to add to.
+ */
+void
+IO::maybe_add_output_bundle_to_list (boost::shared_ptr<Bundle> b, std::vector<boost::shared_ptr<Bundle> >* bundles)
+{
+ boost::shared_ptr<AutoBundle> ab = boost::dynamic_pointer_cast<AutoBundle, Bundle> (b);
+ if (ab == 0 || ab->ports_are_inputs() == false) {
+ return;
+ }
+
+ if (ab->nchannels ().get (default_type()) != n_outputs().n_total ()) {
+ return;
+ }
+
+ for (uint32_t i = 0; i < n_outputs().n_total (); ++i) {
+
+ PortList const & pl = b->channel_ports (i);
+
+ if (pl.empty()) {
+ return;
+ }
+
+ if (!output(i)->connected_to (pl[0])) {
+ return;
+ }
+ }
+
+ bundles->push_back (b);
+}
+
+
+/* @return Bundles connected to our outputs */
+std::vector<boost::shared_ptr<Bundle> >
+IO::bundles_connected_to_outputs ()
+{
+ std::vector<boost::shared_ptr<Bundle> > bundles;
+
+ /* User bundles */
+ for (std::vector<UserBundleInfo>::iterator i = _bundles_connected_to_outputs.begin(); i != _bundles_connected_to_outputs.end(); ++i) {
+ bundles.push_back (i->bundle);
+ }
+
+ /* Auto bundles */
+ _session.foreach_bundle (
+ sigc::bind (sigc::mem_fun (*this, &IO::maybe_add_output_bundle_to_list), &bundles)
+ );
+
+ return bundles;
+}
+
+
+IO::UserBundleInfo::UserBundleInfo (IO* io, boost::shared_ptr<UserBundle> b)
+{
+ bundle = b;
+ configuration_will_change = b->ConfigurationWillChange.connect (
+ sigc::mem_fun (*io, &IO::bundle_configuration_will_change)
+ );
+ configuration_has_changed = b->ConfigurationHasChanged.connect (
+ sigc::mem_fun (*io, &IO::bundle_configuration_has_changed)
+ );
+ ports_will_change = b->PortsWillChange.connect (
+ sigc::mem_fun (*io, &IO::bundle_ports_will_change)
+ );
+ ports_have_changed = b->PortsHaveChanged.connect (
+ sigc::mem_fun (*io, &IO::bundle_ports_have_changed)
+ );
+}
+
+void
+IO::prepare_inputs (nframes_t nframes, nframes_t offset)
+{
+ /* io_lock, not taken: function must be called from Session::process() calltree */
+
+ for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
+ (*i).cycle_start (nframes, offset);
+ }
+}