+
+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::silence_outputs (pframes_t nframes)
+{
+ std::vector<std::string> port_names;
+ if (get_ports("", DataType::AUDIO, IsOutput, port_names)) {
+ for (std::vector<std::string>::iterator p = port_names.begin(); p != port_names.end(); ++p) {
+ if (!port_is_mine(*p)) {
+ continue;
+ }
+ PortEngine::PortHandle ph = _backend->get_port_by_name (*p);
+ if (!ph) {
+ continue;
+ }
+ void *buf = _backend->get_buffer(ph, nframes);
+ if (!buf) {
+ continue;
+ }
+ memset (buf, 0, sizeof(float) * nframes);
+ }
+ }
+
+ if (get_ports("", DataType::MIDI, IsOutput, port_names)) {
+ for (std::vector<std::string>::iterator p = port_names.begin(); p != port_names.end(); ++p) {
+ if (!port_is_mine(*p)) {
+ continue;
+ }
+ PortEngine::PortHandle ph = _backend->get_port_by_name (*p);
+ if (!ph) {
+ continue;
+ }
+ void *buf = _backend->get_buffer(ph, nframes);
+ if (!buf) {
+ continue;
+ }
+ _backend->midi_clear (buf);
+ }
+ }
+}
+
+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;
+}