#include <ardour/session.h>
#include <ardour/cycle_timer.h>
#include <ardour/panner.h>
-#include <ardour/dB.h>
+#include <ardour/buffer_set.h>
+#include <ardour/meter.h>
+#include <ardour/amp.h>
#include "i18n.h"
sigc::signal<int> IO::ConnectingLegal;
sigc::signal<int> IO::PortsLegal;
sigc::signal<int> IO::PannersLegal;
-sigc::signal<void,ChanCount> IO::MoreOutputs;
+sigc::signal<void,ChanCount> IO::MoreChannels;
sigc::signal<int> IO::PortsCreated;
Glib::StaticMutex IO::m_meter_signal_lock = GLIBMM_STATIC_MUTEX_INIT;
return pow((6.0*log(gain)/log(2.0)+192.0)/198.0, 8.0);
}
-/*
-static bool sort_ports_by_name (Port* a, Port* b)
-{
- return a->name() < b->name();
-}
-*/
-
/** @param default_type The type of port that will be created by ensure_io
* and friends if no type is explicitly requested (to avoid breakage).
int input_min, int input_max, int output_min, int output_max,
DataType default_type)
: _session (s),
+ _output_buffers(new BufferSet()),
_name (name),
_default_type(default_type),
_gain_control (*this),
_gain_automation_curve (0.0, 2.0, 1.0),
- _input_minimum (_default_type, input_min),
- _input_maximum (_default_type, input_max),
- _output_minimum (_default_type, output_min),
- _output_maximum (_default_type, output_max)
+ _input_minimum (ChanCount::ZERO),
+ _input_maximum (ChanCount::INFINITE),
+ _output_minimum (ChanCount::ZERO),
+ _output_maximum (ChanCount::INFINITE)
{
_panner = new Panner (name, _session);
+ _meter = new PeakMeter (_session);
+
+ if (input_min > 0) {
+ _input_minimum = ChanCount(_default_type, input_min);
+ }
+ if (input_max >= 0) {
+ _input_maximum = ChanCount(_default_type, input_max);
+ }
+ if (output_min > 0) {
+ _output_minimum = ChanCount(_default_type, output_min);
+ }
+ if (output_max >= 0) {
+ _output_maximum = ChanCount(_default_type, output_max);
+ }
+
_gain = 1.0;
_desired_gain = 1.0;
_input_connection = 0;
_output_connection = 0;
pending_state_node = 0;
no_panner_reset = false;
+ _phase_invert = false;
deferred_state = 0;
apply_gain_automation = false;
_gain_automation_state = Off;
_gain_automation_style = Absolute;
-
- {
- // IO::Meter is emitted from another thread so the
- // Meter signal must be protected.
- Glib::Mutex::Lock guard (m_meter_signal_lock);
- m_meter_connection = Meter.connect (mem_fun (*this, &IO::meter));
- }
+
+ {
+ // IO::Meter is emitted from another thread so the
+ // Meter signal must be protected.
+ Glib::Mutex::Lock guard (m_meter_signal_lock);
+ m_meter_connection = Meter.connect (mem_fun (*this, &IO::meter));
+ }
+
+ // Connect to our own MoreChannels signal to connect output buffers
+ IO::MoreChannels.connect (mem_fun (*this, &IO::attach_buffers));
}
IO::~IO ()
{
-
- Glib::Mutex::Lock guard (m_meter_signal_lock);
+ Glib::Mutex::Lock guard (m_meter_signal_lock);
+
Glib::Mutex::Lock lm (io_lock);
for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
_session.engine().unregister_port (*i);
}
- m_meter_connection.disconnect();
+ m_meter_connection.disconnect();
+
+ delete _meter;
+ delete _panner;
+ delete _output_buffers;
}
void
/* io_lock, not taken: function must be called from Session::process() calltree */
for (PortSet::iterator i = _outputs.begin(); i != _outputs.end(); ++i) {
- (*i)->silence (nframes, offset);
+ i->get_buffer().silence (nframes, offset);
}
}
+/** Deliver bufs to the IO's Jack outputs.
+ *
+ * This function should automatically do whatever it necessary to correctly deliver bufs
+ * to the outputs, eg applying gain or pan or whatever else needs to be done.
+ */
void
-IO::apply_declick (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframes, gain_t initial, gain_t target, bool invert_polarity)
+IO::deliver_output (BufferSet& bufs, jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t nframes, jack_nframes_t offset)
{
- jack_nframes_t declick = min ((jack_nframes_t)128, nframes);
- gain_t delta;
- Sample *buffer;
- double fractional_shift;
- double fractional_pos;
- gain_t polscale = invert_polarity ? -1.0f : 1.0f;
-
- if (nframes == 0) return;
+ // FIXME: type specific code doesn't actually need to be here, it will go away in time
- fractional_shift = -1.0/declick;
-
- if (target < initial) {
- /* fade out: remove more and more of delta from initial */
- delta = -(initial - target);
- } else {
- /* fade in: add more and more of delta from initial */
- delta = target - initial;
- }
- for (uint32_t n = 0; n < nbufs; ++n) {
+ /* ********** AUDIO ********** */
- buffer = bufs[n];
- fractional_pos = 1.0;
-
- for (jack_nframes_t nx = 0; nx < declick; ++nx) {
- buffer[nx] *= polscale * (initial + (delta * (0.5 + 0.5 * cos (M_PI * fractional_pos))));
- fractional_pos += fractional_shift;
- }
-
- /* now ensure the rest of the buffer has the target value
- applied, if necessary.
- */
+ // Apply gain if gain automation isn't playing
+ if ( ! apply_gain_automation) {
- if (declick != nframes) {
+ gain_t dg = _gain; // desired gain
- if (invert_polarity) {
- target = -target;
- }
+ {
+ Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
- if (target == 0.0) {
- memset (&buffer[declick], 0, sizeof (Sample) * (nframes - declick));
- } else if (target != 1.0) {
- for (jack_nframes_t nx = declick; nx < nframes; ++nx) {
- buffer[nx] *= target;
- }
+ if (dm.locked()) {
+ dg = _desired_gain;
}
}
- }
-}
-
-void
-IO::pan_automated (vector<Sample*>& bufs, uint32_t nbufs, jack_nframes_t start, jack_nframes_t end, jack_nframes_t nframes, jack_nframes_t offset)
-{
- Sample* dst;
- /* io_lock, not taken: function must be called from Session::process() calltree */
-
- if (n_outputs().get(DataType::AUDIO) == 0) {
- return;
+ Amp::run(bufs, nframes, _gain, dg, _phase_invert);
}
+
+ // Use the panner to distribute audio to output port buffers
+ if (_panner && !_panner->empty() && !_panner->bypassed()) {
+ _panner->distribute(bufs, output_buffers(), start_frame, end_frame, nframes, offset);
+ } else {
+ const DataType type = DataType::AUDIO;
- if (n_outputs().get(DataType::AUDIO) == 1) {
-
- dst = audio_output(0)->get_audio_buffer().data (nframes, offset);
-
- for (uint32_t n = 0; n < nbufs; ++n) {
- if (bufs[n] != dst) {
- memcpy (dst, bufs[n], sizeof (Sample) * nframes);
- }
+ // Copy any audio 1:1 to outputs
+ assert(bufs.count().get(DataType::AUDIO) == output_buffers().count().get(DataType::AUDIO));
+ BufferSet::iterator o = output_buffers().begin(type);
+ for (BufferSet::iterator i = bufs.begin(type); i != bufs.end(type); ++i, ++o) {
+ o->read_from(*i, nframes, offset);
}
-
- output(0)->mark_silence (false);
-
- return;
- }
-
- uint32_t o = 0;
- vector<Sample *>::iterator in;
- Panner::iterator pan;
- Sample* obufs[n_outputs().get(DataType::AUDIO)];
-
- /* the terrible silence ... */
- for (PortSet::audio_iterator out = _outputs.audio_begin(); out != _outputs.audio_end(); ++out, ++o) {
- (*out)->silence(nframes, offset);
- obufs[o] = (*out)->get_audio_buffer().data(nframes, offset);
}
- uint32_t n;
- for (pan = _panner->begin(), n = 0; n < nbufs; ++n, ++pan) {
- (*pan)->distribute_automated (bufs[n], obufs, start, end, nframes, _session.pan_automation_buffer());
- }
-}
+ /* ********** MIDI ********** */
-void
-IO::pan (vector<Sample*>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset, gain_t gain_coeff)
-{
- Sample* dst;
- Sample* src;
-
- /* io_lock, not taken: function must be called from Session::process() calltree */
-
- if (n_outputs().get(DataType::AUDIO) == 0) {
+ // No MIDI, we're done here
+ if (bufs.count().get(DataType::MIDI) == 0) {
return;
}
- /* the panner can be empty if there are no inputs to the
- route, but still outputs
- */
+ const DataType type = DataType::MIDI;
- if (_panner->bypassed() || _panner->empty()) {
- deliver_output_no_pan (bufs, nbufs, nframes, offset);
- return;
- }
-
- if (n_outputs().get(DataType::AUDIO) == 1) {
-
- dst = audio_output(0)->get_audio_buffer().data(nframes, offset);
-
- if (gain_coeff == 0.0f) {
-
- /* only one output, and gain was zero, so make it silent */
-
- memset (dst, 0, sizeof (Sample) * nframes);
-
- } else if (gain_coeff == 1.0f){
-
- /* mix all buffers into the output */
-
- uint32_t n;
-
- memcpy (dst, bufs[0], sizeof (Sample) * nframes);
-
- for (n = 1; n < nbufs; ++n) {
- src = bufs[n];
-
- for (jack_nframes_t n = 0; n < nframes; ++n) {
- dst[n] += src[n];
- }
- }
-
- audio_output(0)->mark_silence (false);
-
- } else {
-
- /* mix all buffers into the output, scaling them all by the gain */
-
- uint32_t n;
-
- src = bufs[0];
-
- for (jack_nframes_t n = 0; n < nframes; ++n) {
- dst[n] = src[n] * gain_coeff;
- }
-
- for (n = 1; n < nbufs; ++n) {
- src = bufs[n];
-
- for (jack_nframes_t n = 0; n < nframes; ++n) {
- dst[n] += src[n] * gain_coeff;
- }
- }
-
- audio_output(0)->mark_silence (false);
- }
-
- return;
- }
-
- uint32_t o = 0;
- vector<Sample *>::iterator in;
- Panner::iterator pan;
- Sample* obufs[n_outputs().get(DataType::AUDIO)];
-
- /* the terrible silence ... */
-
- /* XXX this is wasteful but i see no way to avoid it */
-
- for (PortSet::audio_iterator out = _outputs.audio_begin(); out != _outputs.audio_end(); ++out, ++o) {
- obufs[o] = (*out)->get_audio_buffer().data (nframes, offset);
- memset (obufs[o], 0, sizeof (Sample) * nframes);
- (*out)->mark_silence (false);
- }
-
- uint32_t n;
-
- for (pan = _panner->begin(), n = 0; n < nbufs; ++n) {
- Panner::iterator tmp;
-
- tmp = pan;
- ++tmp;
-
- (*pan)->distribute (bufs[n], obufs, gain_coeff, nframes);
-
- if (tmp != _panner->end()) {
- pan = tmp;
- }
+ // Copy any MIDI 1:1 to outputs
+ assert(bufs.count().get(DataType::MIDI) == output_buffers().count().get(DataType::MIDI));
+ BufferSet::iterator o = output_buffers().begin(type);
+ for (BufferSet::iterator i = bufs.begin(type); i != bufs.end(type); ++i, ++o) {
+ o->read_from(*i, nframes, offset);
}
}
void
-IO::deliver_output (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset)
+IO::collect_input (BufferSet& outs, jack_nframes_t nframes, jack_nframes_t offset)
{
- /* io_lock, not taken: function must be called from Session::process() calltree */
+ assert(outs.available() >= n_inputs());
- if (n_outputs().get(DataType::AUDIO) == 0) {
- return;
- }
+ outs.set_count(n_inputs());
- if (_panner->bypassed() || _panner->empty()) {
- deliver_output_no_pan (bufs, nbufs, nframes, offset);
+ if (outs.count() == ChanCount::ZERO)
return;
- }
-
- gain_t dg;
- gain_t pangain = _gain;
-
- {
- Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
+ for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
- if (dm.locked()) {
- dg = _desired_gain;
- } else {
- dg = _gain;
+ BufferSet::iterator o = outs.begin(*t);
+ for (PortSet::iterator i = _inputs.begin(*t); i != _inputs.end(*t); ++i, ++o) {
+ o->read_from(i->get_buffer(), nframes, offset);
}
- }
-
- if (dg != _gain) {
- apply_declick (bufs, nbufs, nframes, _gain, dg, false);
- _gain = dg;
- pangain = 1.0f;
- }
-
- /* simple, non-automation panning to outputs */
- if (_session.transport_speed() > 1.5f || _session.transport_speed() < -1.5f) {
- pan (bufs, nbufs, nframes, offset, pangain * speed_quietning);
- } else {
- pan (bufs, nbufs, nframes, offset, pangain);
- }
-}
-
-void
-IO::deliver_output_no_pan (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset)
-{
- /* io_lock, not taken: function must be called from Session::process() calltree */
-
- if (n_outputs().get(DataType::AUDIO) == 0) {
- return;
- }
-
- gain_t dg;
- gain_t old_gain = _gain;
-
- if (apply_gain_automation) {
-
- /* gain has already been applied by automation code. do nothing here except
- speed quietning.
- */
-
- _gain = 1.0f;
- dg = _gain;
-
- } else {
-
- Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
-
- if (dm.locked()) {
- dg = _desired_gain;
- } else {
- dg = _gain;
- }
- }
-
- Sample* src;
- Sample* dst;
- uint32_t i;
- vector<Sample*> outs;
- gain_t actual_gain;
-
- if (dg != _gain) {
- /* unlikely condition */
- i = 0;
- for (PortSet::audio_iterator o = _outputs.audio_begin(); o != _outputs.audio_end(); ++o, ++i) {
- outs.push_back ((*o)->get_audio_buffer().data (nframes, offset));
- }
- }
-
- /* reduce nbufs to the index of the last input buffer */
-
- nbufs--;
-
- if (_session.transport_speed() > 1.5f || _session.transport_speed() < -1.5f) {
- actual_gain = _gain * speed_quietning;
- } else {
- actual_gain = _gain;
- }
-
- i = 0;
- for (PortSet::audio_iterator o = _outputs.audio_begin(); o != _outputs.audio_end(); ++o, ++i) {
-
- dst = (*o)->get_audio_buffer().data(nframes, offset);
- src = bufs[min(nbufs,i)];
-
- if (dg != _gain || actual_gain == 1.0f) {
- memcpy (dst, src, sizeof (Sample) * nframes);
- } else if (actual_gain == 0.0f) {
- memset (dst, 0, sizeof (Sample) * nframes);
- } else {
- for (jack_nframes_t x = 0; x < nframes; ++x) {
- dst[x] = src[x] * actual_gain;
- }
- }
-
- (*o)->mark_silence (false);
- }
-
- if (dg != _gain) {
- apply_declick (outs, outs.size(), nframes, _gain, dg, false);
- _gain = dg;
- }
-
- if (apply_gain_automation) {
- _gain = old_gain;
- }
-}
-
-void
-IO::collect_input (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset)
-{
- /* io_lock, not taken: function must be called from Session::process() calltree */
-
- uint32_t n = 0;
- Sample *last = 0;
-
- /* we require that bufs.size() >= 1 */
-
- for (PortSet::audio_iterator i = _inputs.audio_begin(); n < nbufs; ++i, ++n) {
- if (i == _inputs.audio_end()) {
- break;
- }
-
- /* XXX always read the full extent of the port buffer that
- we need. One day, we may use jack_port_get_buffer_at_offset()
- or something similar. For now, this simple hack will
- have to do.
-
- Hack? Why yes .. we only need to read nframes-worth of
- data, but the data we want is at 'offset' within the
- buffer.
- */
-
- last = (*i)->get_audio_buffer().data(nframes, offset);
- // the dest buffer's offset has already been applied
- memcpy (bufs[n], last, sizeof (Sample) * nframes);
- }
-
- /* fill any excess outputs with the last input */
-
- while (n < nbufs && last) {
- // the dest buffer's offset has already been applied
- memcpy (bufs[n], last, sizeof (Sample) * nframes);
- ++n;
}
}
IO::just_meter_input (jack_nframes_t start_frame, jack_nframes_t end_frame,
jack_nframes_t nframes, jack_nframes_t offset)
{
- vector<Sample*>& bufs = _session.get_passthru_buffers ();
- uint32_t nbufs = n_process_buffers ();
+ BufferSet& bufs = _session.get_scratch_buffers (n_inputs());
- collect_input (bufs, nbufs, nframes, offset);
+ collect_input (bufs, nframes, offset);
- for (uint32_t n = 0; n < nbufs; ++n) {
- _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
- }
+ _meter->run(bufs, nframes);
}
void
if (other_port == 0) {
if (_input_minimum == ChanCount::ZERO) {
- return ensure_inputs (0, false, true, src);
+ return ensure_inputs (ChanCount::ZERO, false, true, src);
} else {
return -1;
}
}
- if (ensure_inputs (1, true, true, src)) {
+ if (ensure_inputs (ChanCount(other_port->type(), 1), true, true, src)) {
return -1;
}
int
IO::remove_output_port (Port* port, void* src)
{
- throw; // FIXME
-#if 0
IOChange change (NoChange);
{
{
Glib::Mutex::Lock lm (io_lock);
-
- if (_noutputs - 1 == (uint32_t) _output_minimum) {
+
+ if (n_outputs() <= _output_minimum) {
/* sorry, you can't do this */
return -1;
}
-
- for (PortSet::iterator i = _outputs.begin(); i != _outputs.end(); ++i) {
- if (*i == port) {
- change = IOChange (change|ConfigurationChanged);
- if (port->connected()) {
- change = IOChange (change|ConnectionsChanged);
- }
-
- _session.engine().unregister_port (*i);
- _outputs.erase (i);
- _noutputs--;
- drop_output_connection ();
-
- break;
- }
- }
- if (change != NoChange) {
+ if (_outputs.remove(port)) {
+ change = IOChange (change|ConfigurationChanged);
+
+ if (port->connected()) {
+ change = IOChange (change|ConnectionsChanged);
+ }
+
+ _session.engine().unregister_port (*port);
+ drop_output_connection ();
+
setup_peak_meters ();
reset_panner ();
}
}
}
-
+
if (change != NoChange) {
- output_changed (change, src); /* EMIT SIGNAL */
+ output_changed (change, src);
_session.set_dirty ();
return 0;
- }
-#endif
+ }
+
return -1;
}
/* Create a new output port */
// FIXME: naming scheme for differently typed ports?
- if (_output_maximum.get_total() == 1) {
+ 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());
return -1;
}
- _outputs.add_port (our_port);
+ _outputs.add (our_port);
drop_output_connection ();
setup_peak_meters ();
reset_panner ();
}
- MoreOutputs (n_outputs()); /* EMIT SIGNAL */
+ MoreChannels (n_outputs()); /* EMIT SIGNAL */
}
if (destination.length()) {
int
IO::remove_input_port (Port* port, void* src)
{
- throw; // FIXME
-#if 0
IOChange change (NoChange);
{
{
Glib::Mutex::Lock lm (io_lock);
- if (((int)_ninputs - 1) < _input_minimum) {
+ if (n_inputs() <= _input_minimum) {
/* sorry, you can't do this */
return -1;
}
- for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
-
- if (*i == port) {
- change = IOChange (change|ConfigurationChanged);
- if (port->connected()) {
- change = IOChange (change|ConnectionsChanged);
- }
+ if (_inputs.remove(port)) {
+ change = IOChange (change|ConfigurationChanged);
- _session.engine().unregister_port (*i);
- _inputs.erase (i);
- _ninputs--;
- drop_input_connection ();
+ if (port->connected()) {
+ change = IOChange (change|ConnectionsChanged);
+ }
- break;
- }
- }
-
- if (change != NoChange) {
+ _session.engine().unregister_port (*port);
+ drop_input_connection ();
+
setup_peak_meters ();
reset_panner ();
}
_session.set_dirty ();
return 0;
}
-#endif
+
return -1;
}
/* Create a new input port */
// FIXME: naming scheme for differently typed ports?
- if (_input_maximum.get_total() == 1) {
+ 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());
error << string_compose(_("IO: cannot register input port %1"), name) << endmsg;
return -1;
}
-
- _inputs.add_port(our_port);
+
+ _inputs.add (our_port);
drop_input_connection ();
setup_peak_meters ();
reset_panner ();
}
- MoreOutputs (n_inputs()); /* EMIT SIGNAL */
+ MoreChannels (n_inputs()); /* EMIT SIGNAL */
}
if (source.length()) {
}
bool
-IO::ensure_inputs_locked (uint32_t n, bool clear, void* src)
+IO::ensure_inputs_locked (ChanCount count, bool clear, void* src)
{
- Port* input_port;
- bool changed = false;
-
- /* remove unused ports */
-
- while (n_inputs().get(_default_type) > n) {
- throw; // FIXME
- /*
- _session.engine().unregister_port (_inputs.back());
- _inputs.pop_back();
- _ninputs--;
- changed = true;
- */
- }
-
- /* create any necessary new ports */
-
- while (n_inputs().get(_default_type) < n) {
-
- char buf[64];
-
- /* Create a new input port (of the default type) */
+ Port* input_port = 0;
+ bool changed = false;
+
+
+ for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
- if (_input_maximum.get_total() == 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());
+ 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;
}
-
- try {
-
- if ((input_port = _session.engine().register_input_port (_default_type, buf)) == 0) {
- error << string_compose(_("IO: cannot register input port %1"), buf) << endmsg;
- return -1;
+
+ /* 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());
}
- }
- catch (AudioEngine::PortRegistrationFailure& err) {
- setup_peak_meters ();
- reset_panner ();
- /* pass it on */
- throw err;
+ try {
+
+ if ((input_port = _session.engine().register_input_port (*t, buf)) == 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 err;
+ }
+
+ _inputs.add (input_port);
+ changed = true;
}
-
- _inputs.add_port (input_port);
- changed = true;
}
if (changed) {
drop_input_connection ();
setup_peak_meters ();
reset_panner ();
- MoreOutputs (n_inputs()); /* EMIT SIGNAL */
+ MoreChannels (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);
}
return changed;
}
+/** Attach output_buffers to port buffers.
+ *
+ * Connected to IO's own MoreChannels signal.
+ */
+void
+IO::attach_buffers(ChanCount ignored)
+{
+ _output_buffers->attach_buffers(_outputs);
+}
+
int
-IO::ensure_io (uint32_t nin, uint32_t nout, bool clear, void* src)
+IO::ensure_io (ChanCount in, ChanCount out, bool clear, void* src)
{
- bool in_changed = false;
- bool out_changed = false;
- bool need_pan_reset;
+ bool in_changed = false;
+ bool out_changed = false;
+ bool need_pan_reset = false;
- nin = min (_input_maximum.get(_default_type), static_cast<size_t>(nin));
+ in = min (_input_maximum, in);
- nout = min (_output_maximum.get(_default_type), static_cast<size_t>(nout));
+ out = min (_output_maximum, out);
- if (nin == n_inputs().get(_default_type) && nout == n_outputs().get(_default_type) && !clear) {
+ if (in == n_inputs() && out == n_outputs() && !clear) {
return 0;
}
Port* port;
- if (n_outputs().get(_default_type) == nout) {
- need_pan_reset = false;
- } else {
+ if (n_outputs() != out) {
need_pan_reset = true;
}
- /* remove unused ports */
-
- while (n_inputs().get(_default_type) > nin) {
- throw; // FIXME
- /*
- _session.engine().unregister_port (_inputs.back());
- _inputs.pop_back();
- _ninputs--;
- in_changed = true;*/
- }
-
- while (n_outputs().get(_default_type) > nout) {
- throw; // FIXME
- /*
- _session.engine().unregister_port (_outputs.back());
- _outputs.pop_back();
- _noutputs--;
- out_changed = true;*/
- }
-
- /* create any necessary new ports (of the default type) */
-
- while (n_inputs().get(_default_type) < nin) {
-
- char buf[64];
+ for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
- /* Create a new input port */
-
- if (_input_maximum.get_total() == 1) {
- snprintf (buf, sizeof (buf), _("%s/in"), _name.c_str());
+ const size_t nin = in.get(*t);
+ const size_t nout = out.get(*t);
+
+ Port* output_port = 0;
+ Port* input_port = 0;
+
+ /* remove unused output ports */
+ for (size_t i = n_outputs().get(*t); i > nout; --i) {
+ output_port = _outputs.port(*t, i-1);
+
+ assert(output_port);
+ _outputs.remove(output_port);
+ _session.engine().unregister_port (*output_port);
+
+ out_changed = true;
}
- else {
- snprintf (buf, sizeof (buf), _("%s/in %u"), _name.c_str(), find_input_port_hole());
+
+ /* remove unused input ports */
+ for (size_t i = n_inputs().get(*t); i > nin; --i) {
+ input_port = _inputs.port(*t, i-1);
+
+ assert(input_port);
+ _inputs.remove(input_port);
+ _session.engine().unregister_port (*input_port);
+
+ in_changed = true;
}
-
- try {
- if ((port = _session.engine().register_input_port (_default_type, buf)) == 0) {
- error << string_compose(_("IO: cannot register input port %1"), buf) << endmsg;
- return -1;
+
+ /* create any necessary new input ports */
+
+ while (n_inputs().get(*t) < nin) {
+
+ char buf[64];
+
+ /* Create a new input port */
+
+ 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());
}
- }
- catch (AudioEngine::PortRegistrationFailure& err) {
- setup_peak_meters ();
- reset_panner ();
- /* pass it on */
- throw err;
- }
-
- _inputs.add_port (port);
- in_changed = true;
- }
+ try {
+ if ((port = _session.engine().register_input_port (*t, buf)) == 0) {
+ error << string_compose(_("IO: cannot register input port %1"), buf) << endmsg;
+ return -1;
+ }
+ }
- /* create any necessary new ports */
-
- while (n_outputs().get(_default_type) < nout) {
-
- char buf[64];
-
- /* Create a new output port */
-
- if (_output_maximum.get_total() == 1) {
- snprintf (buf, sizeof (buf), _("%s/out"), _name.c_str());
- } else {
- snprintf (buf, sizeof (buf), _("%s/out %u"), _name.c_str(), find_output_port_hole());
- }
-
- try {
- if ((port = _session.engine().register_output_port (_default_type, buf)) == 0) {
- error << string_compose(_("IO: cannot register output port %1"), buf) << endmsg;
- return -1;
+ catch (AudioEngine::PortRegistrationFailure& err) {
+ setup_peak_meters ();
+ reset_panner ();
+ /* pass it on */
+ throw err;
}
+
+ _inputs.add (port);
+ in_changed = true;
}
-
- catch (AudioEngine::PortRegistrationFailure& err) {
- setup_peak_meters ();
- reset_panner ();
- /* pass it on */
- throw err;
+
+ /* create any necessary new output ports */
+
+ while (n_outputs().get(*t) < nout) {
+
+ char buf[64];
+
+ /* Create a new output port */
+
+ if (_output_maximum.get(*t) == 1) {
+ snprintf (buf, sizeof (buf), _("%s/out"), _name.c_str());
+ } else {
+ snprintf (buf, sizeof (buf), _("%s/out %u"), _name.c_str(), find_output_port_hole());
+ }
+
+ try {
+ if ((port = _session.engine().register_output_port (*t, buf)) == 0) {
+ error << string_compose(_("IO: cannot register output port %1"), buf) << endmsg;
+ return -1;
+ }
+ }
+
+ catch (AudioEngine::PortRegistrationFailure& err) {
+ setup_peak_meters ();
+ reset_panner ();
+ /* pass it on */
+ throw err;
+ }
+
+ _outputs.add (port);
+ out_changed = true;
}
-
- _outputs.add_port (port);
- out_changed = true;
}
if (clear) {
}
if (in_changed || out_changed) {
- MoreOutputs (max (n_outputs(), n_inputs())); /* EMIT SIGNAL */
+ MoreChannels (max (n_outputs(), n_inputs())); /* EMIT SIGNAL */
_session.set_dirty ();
}
}
int
-IO::ensure_inputs (uint32_t n, bool clear, bool lockit, void* src)
+IO::ensure_inputs (ChanCount count, bool clear, bool lockit, void* src)
{
bool changed = false;
- n = min (_input_maximum.get(_default_type), static_cast<size_t>(n));
+ count = min (_input_maximum, count);
- if (n == n_inputs().get(_default_type) && !clear) {
+ if (count == n_inputs() && !clear) {
return 0;
}
if (lockit) {
Glib::Mutex::Lock em (_session.engine().process_lock());
Glib::Mutex::Lock im (io_lock);
- changed = ensure_inputs_locked (n, clear, src);
+ changed = ensure_inputs_locked (count, clear, src);
} else {
- changed = ensure_inputs_locked (n, clear, src);
+ changed = ensure_inputs_locked (count, clear, src);
}
if (changed) {
}
bool
-IO::ensure_outputs_locked (uint32_t n, bool clear, void* src)
+IO::ensure_outputs_locked (ChanCount count, bool clear, void* src)
{
- Port* output_port;
- bool changed = false;
- bool need_pan_reset;
+ Port* output_port = 0;
+ bool changed = false;
+ bool need_pan_reset = false;
- if (n_outputs().get(_default_type) == n) {
- need_pan_reset = false;
- } else {
+ if (n_outputs() != count) {
need_pan_reset = true;
}
- /* remove unused ports */
-
- while (n_outputs().get(_default_type) > n) {
- throw; // FIXME
- /*
- _session.engine().unregister_port (_outputs.back());
- _outputs.pop_back();
- _noutputs--;
- changed = true;
- */
- }
-
- /* create any necessary new ports */
-
- while (n_outputs().get(_default_type) < n) {
-
- char buf[64];
-
- /* Create a new output port */
-
- if (_output_maximum.get(_default_type) == 1) {
- snprintf (buf, sizeof (buf), _("%s/out"), _name.c_str());
- } else {
- snprintf (buf, sizeof (buf), _("%s/out %u"), _name.c_str(), find_output_port_hole());
- }
-
- if ((output_port = _session.engine().register_output_port (_default_type, buf)) == 0) {
- error << string_compose(_("IO: cannot register output port %1"), buf) << endmsg;
- return -1;
+ 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_outputs().get(*t); i > n; --i) {
+ output_port = _outputs.port(*t, i-1);
+
+ assert(output_port);
+ _outputs.remove(output_port);
+ _session.engine().unregister_port (*output_port);
+
+ changed = true;
}
-
- _outputs.add_port (output_port);
- changed = true;
- setup_peak_meters ();
- if (need_pan_reset) {
- reset_panner ();
+ /* create any necessary new ports */
+ while (n_outputs().get(*t) < n) {
+
+ char buf[64];
+
+ if (_output_maximum.get(*t) == 1) {
+ snprintf (buf, sizeof (buf), _("%s/out"), _name.c_str());
+ } else {
+ snprintf (buf, sizeof (buf), _("%s/out %u"), _name.c_str(), find_output_port_hole());
+ }
+
+ if ((output_port = _session.engine().register_output_port (*t, buf)) == 0) {
+ error << string_compose(_("IO: cannot register output port %1"), buf) << endmsg;
+ return -1;
+ }
+
+ _outputs.add (output_port);
+ changed = true;
+ setup_peak_meters ();
+
+ if (need_pan_reset) {
+ reset_panner ();
+ }
}
}
if (changed) {
drop_output_connection ();
- MoreOutputs (n_outputs()); /* EMIT SIGNAL */
+ MoreChannels (n_outputs()); /* EMIT SIGNAL */
_session.set_dirty ();
}
if (clear) {
/* disconnect all existing ports so that we get a fresh start */
-
for (PortSet::iterator i = _outputs.begin(); i != _outputs.end(); ++i) {
_session.engine().disconnect (*i);
}
}
int
-IO::ensure_outputs (uint32_t n, bool clear, bool lockit, void* src)
+IO::ensure_outputs (ChanCount count, bool clear, bool lockit, void* src)
{
bool changed = false;
if (_output_maximum < ChanCount::INFINITE) {
- n = min (_output_maximum.get(_default_type), static_cast<size_t>(n));
- if (n == n_outputs().get(_default_type) && !clear) {
+ count = min (_output_maximum, count);
+ if (count == n_outputs() && !clear) {
return 0;
}
}
if (lockit) {
Glib::Mutex::Lock em (_session.engine().process_lock());
Glib::Mutex::Lock im (io_lock);
- changed = ensure_outputs_locked (n, clear, src);
+ changed = ensure_outputs_locked (count, clear, src);
} else {
- changed = ensure_outputs_locked (n, clear, src);
+ changed = ensure_outputs_locked (count, clear, src);
}
if (changed) {
output_changed (ConfigurationChanged, src); /* EMIT SIGNAL */
}
+
return 0;
}
{
if (panners_legal) {
if (!no_panner_reset) {
- _panner->reset (n_outputs().get(_default_type), pans_required());
+ _panner->reset (n_outputs().get(DataType::AUDIO), pans_required());
}
} else {
panner_legal_c.disconnect ();
int
IO::panners_became_legal ()
{
- _panner->reset (n_outputs().get(_default_type), pans_required());
+ _panner->reset (n_outputs().get(DataType::AUDIO), pans_required());
_panner->load (); // automation
panner_legal_c.disconnect ();
return 0;
if (need_ins) {
for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
- const char **connections = (*i)->get_connections();
+ const char **connections = i->get_connections();
if (connections && connections[0]) {
str += '{';
for (PortSet::iterator i = _outputs.begin(); i != _outputs.end(); ++i) {
- const char **connections = (*i)->get_connections();
+ const char **connections = i->get_connections();
if (connections && connections[0]) {
snprintf (buf, sizeof(buf), "%2.12f", gain());
node->add_property ("gain", buf);
+ // FIXME: this is NOT sufficient!
const int in_min = (_input_minimum == ChanCount::ZERO) ? -1 : _input_minimum.get(_default_type);
const int in_max = (_input_maximum == ChanCount::INFINITE) ? -1 : _input_maximum.get(_default_type);
const int out_min = (_output_minimum == ChanCount::ZERO) ? -1 : _output_minimum.get(_default_type);
no_panner_reset = true;
- if (ensure_io (num_inputs, num_outputs, true, this)) {
+ // FIXME: audio-only
+ if (ensure_io (ChanCount(DataType::AUDIO, num_inputs), ChanCount(DataType::AUDIO, num_outputs), true, this)) {
error << string_compose(_("%1: cannot create I/O ports"), _name) << endmsg;
return -1;
}
return 0;
}
- if (ensure_inputs (nports, true, true, this)) {
+ // FIXME: audio-only
+ if (ensure_inputs (ChanCount(DataType::AUDIO, nports), true, true, this)) {
return -1;
}
return 0;
}
- if (ensure_outputs (nports, true, true, this)) {
+ // FIXME: audio-only
+ if (ensure_outputs (ChanCount(DataType::AUDIO, nports), true, true, this)) {
return -1;
}
}
for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
- string current_name = (*i)->short_name();
+ string current_name = i->short_name();
current_name.replace (current_name.find (_name), _name.length(), name);
- (*i)->set_name (current_name);
+ i->set_name (current_name);
}
for (PortSet::iterator i = _outputs.begin(); i != _outputs.end(); ++i) {
- string current_name = (*i)->short_name();
+ string current_name = i->short_name();
current_name.replace (current_name.find (_name), _name.length(), name);
- (*i)->set_name (current_name);
+ i->set_name (current_name);
}
_name = name;
Glib::Mutex::Lock lm (io_lock);
for (PortSet::iterator i = _outputs.begin(); i != _outputs.end(); ++i) {
- (*i)->set_latency (nframes);
+ i->set_latency (nframes);
}
}
/* io lock not taken - must be protected by other means */
for (PortSet::const_iterator i = _outputs.begin(); i != _outputs.end(); ++i) {
- if ((latency = _session.engine().get_port_total_latency (*(*i))) > max_latency) {
+ if ((latency = _session.engine().get_port_total_latency (*i)) > max_latency) {
max_latency = latency;
}
}
/* io lock not taken - must be protected by other means */
for (PortSet::const_iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
- if ((latency = _session.engine().get_port_total_latency (*(*i))) > max_latency) {
+ if ((latency = _session.engine().get_port_total_latency (*i)) > max_latency) {
max_latency = latency;
}
}
drop_input_connection ();
- if (ensure_inputs (limit, false, false, src)) {
+ // FIXME connections only work for audio-only
+ if (ensure_inputs (ChanCount(DataType::AUDIO, limit), false, false, src)) {
return -1;
}
/* clear any existing connections */
- _session.engine().disconnect (_inputs.port(n));
+ _session.engine().disconnect (*_inputs.port(n));
} else if (_inputs.port(n)->connected() > 1) {
the one we want.
*/
- _session.engine().disconnect (_inputs.port(n));
+ _session.engine().disconnect (*_inputs.port(n));
}
}
drop_output_connection ();
- if (ensure_outputs (limit, false, false, src)) {
+ // FIXME: audio-only
+ if (ensure_outputs (ChanCount(DataType::AUDIO, limit), false, false, src)) {
return -1;
}
/* clear any existing connections */
- _session.engine().disconnect (_outputs.port(n));
+ _session.engine().disconnect (*_outputs.port(n));
} else if (_outputs.port(n)->connected() > 1) {
the one we want.
*/
- _session.engine().disconnect (_outputs.port(n));
+ _session.engine().disconnect (*_outputs.port(n));
}
}
}
return direct_gain_to_control (io.effective_gain());
}
-void
-IO::reset_peak_meters ()
-{
- uint32_t limit = max (n_inputs().get(DataType::AUDIO), n_outputs().get(DataType::AUDIO));
-
- for (uint32_t i = 0; i < limit; ++i) {
- _peak_power[i] = 0;
- }
-}
-
-void
-IO::setup_peak_meters ()
-{
- uint32_t limit = max (n_inputs().get(DataType::AUDIO), n_outputs().get(DataType::AUDIO));
-
- while (_peak_power.size() < limit) {
- _peak_power.push_back (0);
- _visible_peak_power.push_back (0);
- }
-}
-
UndoAction
IO::get_memento() const
{
return state;
}
+void
+IO::setup_peak_meters()
+{
+ _meter->setup(std::max(_inputs.count(), _outputs.count()));
+}
+
/**
Update the peak meters.
{
Glib::Mutex::Lock guard (m_meter_signal_lock);
- Meter();
+ Meter(); /* EMIT SIGNAL */
}
void
IO::meter ()
{
- Glib::Mutex::Lock lm (io_lock); // READER: meter thread.
- uint32_t limit = max (n_inputs().get(DataType::AUDIO), n_outputs().get(DataType::AUDIO));
+ // FIXME: Remove this function and just connect signal directly to PeakMeter::meter
- for (uint32_t n = 0; n < limit; ++n) {
-
- /* XXX we should use atomic exchange here */
-
- /* grab peak since last read */
-
- float new_peak = _peak_power[n];
- _peak_power[n] = 0;
-
- /* compute new visible value using falloff */
-
- if (new_peak > 0.0) {
- new_peak = coefficient_to_dB (new_peak);
- } else {
- new_peak = minus_infinity();
- }
-
- if (_session.meter_falloff() == 0.0f || new_peak > _visible_peak_power[n]) {
- _visible_peak_power[n] = new_peak;
- } else {
- // do falloff
- new_peak = _visible_peak_power[n] - _session.meter_falloff();
- _visible_peak_power[n] = max (new_peak, -INFINITY);
- }
- }
+ Glib::Mutex::Lock lm (io_lock); // READER: meter thread.
+ _meter->meter();
}
int
snprintf (buf, jack_port_name_size(), _("%s/in %u"), _name.c_str(), n);
for ( ; i != _inputs.end(); ++i) {
- if ((*i)->short_name() == buf) {
+ if (i->short_name() == buf) {
break;
}
}
snprintf (buf, jack_port_name_size(), _("%s/out %u"), _name.c_str(), n);
for ( ; i != _outputs.end(); ++i) {
- if ((*i)->short_name() == buf) {
+ if (i->short_name() == buf) {
break;
}
}
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 */
+}
+