+int
+PortManager::reconnect_ports ()
+{
+ boost::shared_ptr<Ports> p = ports.reader ();
+
+ /* re-establish connections */
+
+ DEBUG_TRACE (DEBUG::Ports, string_compose ("reconnect %1 ports\n", p->size()));
+
+ for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
+ i->second->reconnect ();
+ }
+
+ return 0;
+}
+
+void
+PortManager::connect_callback (const string& a, const string& b, bool conn)
+{
+ boost::shared_ptr<Port> port_a;
+ boost::shared_ptr<Port> port_b;
+ Ports::iterator x;
+ boost::shared_ptr<Ports> pr = ports.reader ();
+
+ x = pr->find (make_port_name_relative (a));
+ if (x != pr->end()) {
+ port_a = x->second;
+ }
+
+ x = pr->find (make_port_name_relative (b));
+ if (x != pr->end()) {
+ port_b = x->second;
+ }
+
+ PortConnectedOrDisconnected (
+ port_a, a,
+ port_b, b,
+ conn
+ ); /* EMIT SIGNAL */
+}
+
+void
+PortManager::registration_callback ()
+{
+ if (!_port_remove_in_progress) {
+ PortRegisteredOrUnregistered (); /* EMIT SIGNAL */
+ }
+}
+
+bool
+PortManager::can_request_input_monitoring () const
+{
+ if (!_backend) {
+ return false;
+ }
+
+ return _backend->can_monitor_input ();
+}
+
+void
+PortManager::request_input_monitoring (const string& name, bool yn) const
+{
+ if (!_backend) {
+ return;
+ }
+
+ PortEngine::PortHandle ph = _backend->get_port_by_name (name);
+
+ if (ph) {
+ _backend->request_input_monitoring (ph, yn);
+ }
+}
+
+void
+PortManager::ensure_input_monitoring (const string& name, bool yn) const
+{
+ if (!_backend) {
+ return;
+ }
+
+ PortEngine::PortHandle ph = _backend->get_port_by_name (name);
+
+ if (ph) {
+ _backend->ensure_input_monitoring (ph, yn);
+ }
+}
+
+uint32_t
+PortManager::port_name_size() const
+{
+ if (!_backend) {
+ return 0;
+ }
+
+ return _backend->port_name_size ();
+}
+
+string
+PortManager::my_name() const
+{
+ if (!_backend) {
+ return string();
+ }
+
+ return _backend->my_name();
+}
+
+int
+PortManager::graph_order_callback ()
+{
+ if (!_port_remove_in_progress) {
+ GraphReordered(); /* EMIT SIGNAL */
+ }
+
+ return 0;
+}
+
+void
+PortManager::cycle_start (pframes_t nframes)
+{
+ Port::set_global_port_buffer_offset (0);
+ Port::set_cycle_framecnt (nframes);
+
+ _cycle_ports = ports.reader ();
+
+ for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) {
+ p->second->cycle_start (nframes);
+ }
+}
+
+void
+PortManager::cycle_end (pframes_t nframes)
+{
+ for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) {
+ p->second->cycle_end (nframes);
+ }
+
+ for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) {
+ p->second->flush_buffers (nframes);
+ }
+
+ _cycle_ports.reset ();
+
+ /* we are done */
+}
+
+void
+PortManager::silence (pframes_t nframes)
+{
+ for (Ports::iterator i = _cycle_ports->begin(); i != _cycle_ports->end(); ++i) {
+ if (i->second->sends_output()) {
+ i->second->get_buffer(nframes).silence(nframes);
+ }
+ }
+}
+
+void
+PortManager::check_monitoring ()
+{
+ for (Ports::iterator i = _cycle_ports->begin(); i != _cycle_ports->end(); ++i) {
+
+ bool x;
+
+ if (i->second->last_monitor() != (x = i->second->monitoring_input ())) {
+ i->second->set_last_monitor (x);
+ /* XXX I think this is dangerous, due to
+ a likely mutex in the signal handlers ...
+ */
+ i->second->MonitorInputChanged (x); /* EMIT SIGNAL */
+ }
+ }
+}
+
+void
+PortManager::fade_out (gain_t base_gain, gain_t gain_step, pframes_t nframes)
+{
+ for (Ports::iterator i = _cycle_ports->begin(); i != _cycle_ports->end(); ++i) {
+
+ if (i->second->sends_output()) {
+
+ boost::shared_ptr<AudioPort> ap = boost::dynamic_pointer_cast<AudioPort> (i->second);
+ if (ap) {
+ Sample* s = ap->engine_get_whole_audio_buffer ();
+ gain_t g = base_gain;
+
+ for (pframes_t n = 0; n < nframes; ++n) {
+ *s++ *= g;
+ g -= gain_step;
+ }
+ }
+ }
+ }
+}
+
+PortEngine&
+PortManager::port_engine()
+{
+ assert (_backend);
+ return *_backend;
+}