#include <glibmm/thread.h>
#include <pbd/xml++.h>
+#include <pbd/replace_all.h>
#include <ardour/audioengine.h>
#include <ardour/io.h>
extern "C" int isinf (double);
#endif
+#define BLOCK_PROCESS_CALLBACK() Glib::Mutex::Lock em (_session.engine().process_lock())
using namespace std;
using namespace ARDOUR;
using namespace PBD;
+nframes_t IO::_automation_interval = 0;
-static float current_automation_version_number = 1.0;
-
-jack_nframes_t IO::_automation_interval = 0;
const string IO::state_node_name = "IO";
bool IO::connecting_legal = false;
bool IO::ports_legal = false;
_output_buffers(new BufferSet()),
_name (name),
_default_type(default_type),
- _gain_control (*this),
+ _gain_control (X_("gaincontrol"), *this),
_gain_automation_curve (0.0, 2.0, 1.0),
_input_minimum (ChanCount::ZERO),
_input_maximum (ChanCount::INFINITE),
deferred_state = 0;
apply_gain_automation = false;
-
+
last_automation_snapshot = 0;
_gain_automation_state = Off;
// Connect to our own MoreChannels signal to connect output buffers
IO::MoreChannels.connect (mem_fun (*this, &IO::attach_buffers));
+
+ _session.add_controllable (&_gain_control);
+}
+
+IO::IO (Session& s, const XMLNode& node, DataType dt)
+ : _session (s),
+ _output_buffers(new BufferSet()),
+ _default_type (dt),
+ _gain_control (X_("gaincontrol"), *this),
+ _gain_automation_curve (0, 0, 0) // all reset in set_state()
+{
+ // FIXME: hack
+ _meter = new PeakMeter (_session);
+
+ _panner = 0;
+ deferred_state = 0;
+ no_panner_reset = false;
+ _desired_gain = 1.0;
+ _gain = 1.0;
+ _input_connection = 0;
+ _output_connection = 0;
+
+ apply_gain_automation = false;
+
+ set_state (node);
+
+ {
+ // 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));
+
+ _session.add_controllable (&_gain_control);
}
IO::~IO ()
}
void
-IO::silence (jack_nframes_t nframes, jack_nframes_t offset)
+IO::silence (nframes_t nframes, nframes_t offset)
{
/* io_lock, not taken: function must be called from Session::process() calltree */
* to the outputs, eg applying gain or pan or whatever else needs to be done.
*/
void
-IO::deliver_output (BufferSet& bufs, jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t nframes, jack_nframes_t offset)
+IO::deliver_output (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset)
{
// FIXME: type specific code doesn't actually need to be here, it will go away in time
-
/* ********** AUDIO ********** */
if (dm.locked()) {
dg = _desired_gain;
}
+
}
Amp::run(bufs, nframes, _gain, dg, _phase_invert);
}
void
-IO::collect_input (BufferSet& outs, jack_nframes_t nframes, jack_nframes_t offset)
+IO::collect_input (BufferSet& outs, nframes_t nframes, nframes_t offset)
{
assert(outs.available() >= n_inputs());
}
void
-IO::just_meter_input (jack_nframes_t start_frame, jack_nframes_t end_frame,
- jack_nframes_t nframes, jack_nframes_t offset)
+IO::just_meter_input (nframes_t start_frame, nframes_t end_frame,
+ nframes_t nframes, nframes_t offset)
{
BufferSet& bufs = _session.get_scratch_buffers (n_inputs());
}
{
- Glib::Mutex::Lock em (_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
{
Glib::Mutex::Lock lm (io_lock);
}
{
- Glib::Mutex::Lock em(_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
{
Glib::Mutex::Lock lm (io_lock);
}
{
- Glib::Mutex::Lock em(_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
{
Glib::Mutex::Lock lm (io_lock);
}
{
- Glib::Mutex::Lock em(_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
+
{
Glib::Mutex::Lock lm (io_lock);
IOChange change (NoChange);
{
- Glib::Mutex::Lock em(_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
+
{
Glib::Mutex::Lock lm (io_lock);
type = _default_type;
{
- Glib::Mutex::Lock em(_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
+
{
Glib::Mutex::Lock lm (io_lock);
IOChange change (NoChange);
{
- Glib::Mutex::Lock em(_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
+
{
Glib::Mutex::Lock lm (io_lock);
type = _default_type;
{
- Glib::Mutex::Lock em (_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
{
Glib::Mutex::Lock lm (io_lock);
IO::disconnect_inputs (void* src)
{
{
- Glib::Mutex::Lock em (_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
{
Glib::Mutex::Lock lm (io_lock);
IO::disconnect_outputs (void* src)
{
{
- Glib::Mutex::Lock em (_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
{
Glib::Mutex::Lock lm (io_lock);
setup_peak_meters ();
reset_panner ();
/* pass it on */
- throw err;
+ throw AudioEngine::PortRegistrationFailure();
}
_inputs.add (input_port);
}
{
- Glib::Mutex::Lock em (_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
Glib::Mutex::Lock lm (io_lock);
Port* port;
return -1;
}
}
-
+
catch (AudioEngine::PortRegistrationFailure& err) {
setup_peak_meters ();
reset_panner ();
/* pass it on */
- throw err;
+ throw AudioEngine::PortRegistrationFailure();
}
_inputs.add (port);
setup_peak_meters ();
reset_panner ();
/* pass it on */
- throw err;
+ throw AudioEngine::PortRegistrationFailure ();
}
_outputs.add (port);
}
if (lockit) {
- Glib::Mutex::Lock em (_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
Glib::Mutex::Lock im (io_lock);
changed = ensure_inputs_locked (count, clear, src);
} else {
/* XXX caller should hold io_lock, but generally doesn't */
if (lockit) {
- Glib::Mutex::Lock em (_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
Glib::Mutex::Lock im (io_lock);
changed = ensure_outputs_locked (count, clear, src);
} else {
Glib::Mutex::Lock lm (io_lock);
node->add_property("name", _name);
- id().print (buf);
+ id().print (buf, sizeof (buf));
node->add_property("id", buf);
str = "";
}
node->add_child_nocopy (_panner->state (full_state));
+ node->add_child_nocopy (_gain_control.get_state ());
snprintf (buf, sizeof(buf), "%2.12f", gain());
node->add_property ("gain", buf);
/* automation */
if (full_state) {
+
+ XMLNode* autonode = new XMLNode (X_("Automation"));
+ autonode->add_child_nocopy (get_automation_state());
+ node->add_child_nocopy (*autonode);
+
snprintf (buf, sizeof (buf), "0x%x", (int) _gain_automation_curve.automation_state());
} else {
/* never store anything except Off for automation state in a template */
snprintf (buf, sizeof (buf), "0x%x", ARDOUR::Off);
}
- node->add_property ("automation-state", buf);
- snprintf (buf, sizeof (buf), "0x%x", (int) _gain_automation_curve.automation_style());
- node->add_property ("automation-style", buf);
-
- /* XXX same for pan etc. */
return *node;
}
-int
-IO::connecting_became_legal ()
-{
- int ret;
-
- if (pending_state_node == 0) {
- fatal << _("IO::connecting_became_legal() called without a pending state node") << endmsg;
- /*NOTREACHED*/
- return -1;
- }
-
- connection_legal_c.disconnect ();
-
- ret = make_connections (*pending_state_node);
-
- if (ports_legal) {
- delete pending_state_node;
- pending_state_node = 0;
- }
-
- return ret;
-}
-
-int
-IO::ports_became_legal ()
-{
- int ret;
-
- if (pending_state_node == 0) {
- fatal << _("IO::ports_became_legal() called without a pending state node") << endmsg;
- /*NOTREACHED*/
- return -1;
- }
-
- port_legal_c.disconnect ();
-
- ret = create_ports (*pending_state_node);
-
- if (connecting_legal) {
- delete pending_state_node;
- pending_state_node = 0;
- }
-
- return ret;
-}
-
int
IO::set_state (const XMLNode& node)
{
if ((prop = node.property ("name")) != 0) {
_name = prop->value();
- _panner->set_name (_name);
+ /* used to set panner name with this, but no more */
}
if ((prop = node.property ("id")) != 0) {
_gain = _desired_gain;
}
+ if ((prop = node.property ("automation-state")) != 0 || (prop = node.property ("automation-style")) != 0) {
+ /* old school automation handling */
+ }
+
for (iter = node.children().begin(); iter != node.children().end(); ++iter) {
+
if ((*iter)->name() == "Panner") {
+ if (_panner == 0) {
+ _panner = new Panner (_name, _session);
+ }
_panner->set_state (**iter);
}
- }
- if ((prop = node.property ("automation-state")) != 0) {
+ if ((*iter)->name() == X_("Automation")) {
- long int x;
- x = strtol (prop->value().c_str(), 0, 16);
- set_gain_automation_state (AutoState (x));
- }
-
- if ((prop = node.property ("automation-style")) != 0) {
+ set_automation_state (*(*iter)->children().front());
+ }
- long int x;
- x = strtol (prop->value().c_str(), 0, 16);
- set_gain_automation_style (AutoStyle (x));
+ if ((*iter)->name() == X_("controllable")) {
+ if ((prop = (*iter)->property("name")) != 0 && prop->value() == "gaincontrol") {
+ _gain_control.set_state (**iter);
+ }
+ }
}
-
+
if (ports_legal) {
if (create_ports (node)) {
pending_state_node = new XMLNode (node);
}
+ last_automation_snapshot = 0;
+
return 0;
}
+int
+IO::set_automation_state (const XMLNode& node)
+{
+ return _gain_automation_curve.set_state (node);
+}
+
+XMLNode&
+IO::get_automation_state ()
+{
+ return (_gain_automation_curve.get_state ());
+}
+
+int
+IO::load_automation (string path)
+{
+ string fullpath;
+ ifstream in;
+ char line[128];
+ uint32_t linecnt = 0;
+ float version;
+ LocaleGuard lg (X_("POSIX"));
+
+ fullpath = _session.automation_dir();
+ fullpath += path;
+
+ in.open (fullpath.c_str());
+
+ if (!in) {
+ fullpath = _session.automation_dir();
+ fullpath += _session.snap_name();
+ fullpath += '-';
+ fullpath += path;
+
+ in.open (fullpath.c_str());
+
+ if (!in) {
+ error << string_compose(_("%1: cannot open automation event file \"%2\""), _name, fullpath) << endmsg;
+ return -1;
+ }
+ }
+
+ clear_automation ();
+
+ while (in.getline (line, sizeof(line), '\n')) {
+ char type;
+ nframes_t when;
+ double value;
+
+ if (++linecnt == 1) {
+ if (memcmp (line, "version", 7) == 0) {
+ if (sscanf (line, "version %f", &version) != 1) {
+ error << string_compose(_("badly formed version number in automation event file \"%1\""), path) << endmsg;
+ return -1;
+ }
+ } else {
+ error << string_compose(_("no version information in automation event file \"%1\""), path) << endmsg;
+ return -1;
+ }
+
+ continue;
+ }
+
+ if (sscanf (line, "%c %" PRIu32 " %lf", &type, &when, &value) != 3) {
+ warning << string_compose(_("badly formatted automation event record at line %1 of %2 (ignored)"), linecnt, path) << endmsg;
+ continue;
+ }
+
+ switch (type) {
+ case 'g':
+ _gain_automation_curve.fast_simple_add (when, value);
+ break;
+
+ case 's':
+ break;
+
+ case 'm':
+ break;
+
+ case 'p':
+ /* older (pre-1.0) versions of ardour used this */
+ break;
+
+ default:
+ warning << _("dubious automation event found (and ignored)") << endmsg;
+ }
+ }
+
+ return 0;
+}
+
+int
+IO::connecting_became_legal ()
+{
+ int ret;
+
+ if (pending_state_node == 0) {
+ fatal << _("IO::connecting_became_legal() called without a pending state node") << endmsg;
+ /*NOTREACHED*/
+ return -1;
+ }
+
+ connection_legal_c.disconnect ();
+
+ ret = make_connections (*pending_state_node);
+
+ if (ports_legal) {
+ delete pending_state_node;
+ pending_state_node = 0;
+ }
+
+ return ret;
+}
+int
+IO::ports_became_legal ()
+{
+ int ret;
+
+ if (pending_state_node == 0) {
+ fatal << _("IO::ports_became_legal() called without a pending state node") << endmsg;
+ /*NOTREACHED*/
+ return -1;
+ }
+
+ port_legal_c.disconnect ();
+
+ ret = create_ports (*pending_state_node);
+
+ if (connecting_legal) {
+ delete pending_state_node;
+ pending_state_node = 0;
+ }
+
+ return ret;
+}
+
int
IO::create_ports (const XMLNode& node)
{
return 0;
}
+ /* replace all colons in the name. i wish we didn't have to do this */
+
+ if (replace_all (name, ":", "-")) {
+ warning << _("you cannot use colons to name objects with I/O connections") << endmsg;
+ }
+
for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
string current_name = i->short_name();
current_name.replace (current_name.find (_name), _name.length(), name);
return 0;
}
-void
-IO::set_input_minimum (int n)
-{
- if (n < 0)
- _input_minimum = ChanCount::ZERO;
- else
- _input_minimum = ChanCount(_default_type, n);
-}
-
-void
-IO::set_input_maximum (int n)
-{
- if (n < 0)
- _input_maximum = ChanCount::INFINITE;
- else
- _input_maximum = ChanCount(_default_type, n);
-}
-
-void
-IO::set_output_minimum (int n)
-{
- if (n < 0)
- _output_minimum = ChanCount::ZERO;
- else
- _output_minimum = ChanCount(_default_type, n);
-}
-
-void
-IO::set_output_maximum (int n)
-{
- if (n < 0)
- _output_maximum = ChanCount::INFINITE;
- else
- _output_maximum = ChanCount(_default_type, n);
-}
-
void
IO::set_input_minimum (ChanCount n)
{
}
void
-IO::set_port_latency (jack_nframes_t nframes)
+IO::set_port_latency (nframes_t nframes)
{
Glib::Mutex::Lock lm (io_lock);
}
}
-jack_nframes_t
+nframes_t
IO::output_latency () const
{
- jack_nframes_t max_latency;
- jack_nframes_t latency;
+ nframes_t max_latency;
+ nframes_t latency;
max_latency = 0;
return max_latency;
}
-jack_nframes_t
+nframes_t
IO::input_latency () const
{
- jack_nframes_t max_latency;
- jack_nframes_t latency;
+ nframes_t max_latency;
+ nframes_t latency;
max_latency = 0;
uint32_t limit;
{
- Glib::Mutex::Lock lm (_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
Glib::Mutex::Lock lm2 (io_lock);
limit = c.nports();
uint32_t limit;
{
- Glib::Mutex::Lock lm (_session.engine().process_lock());
+ BLOCK_PROCESS_CALLBACK ();
Glib::Mutex::Lock lm2 (io_lock);
limit = c.nports();
return direct_gain_to_control (io.effective_gain());
}
-UndoAction
-IO::get_memento() const
-{
- return sigc::bind (mem_fun (*(const_cast<IO *>(this)), &StateManager::use_state), _current_state_id);
-}
-
-Change
-IO::restore_state (StateManager::State& state)
-{
- return Change (0);
-}
-
-StateManager::State*
-IO::state_factory (std::string why) const
-{
- StateManager::State* state = new StateManager::State (why);
- return state;
-}
-
void
IO::setup_peak_meters()
{
void
IO::meter ()
{
- // FIXME: Remove this function and just connect signal directly to PeakMeter::meter
+ // FIXME: Ugly. Meter should manage the lock, if it's necessary
Glib::Mutex::Lock lm (io_lock); // READER: meter thread.
_meter->meter();
}
-int
-IO::save_automation (const string& path)
-{
- string fullpath;
- ofstream out;
-
- fullpath = _session.automation_dir();
- fullpath += path;
-
- out.open (fullpath.c_str());
-
- if (!out) {
- error << string_compose(_("%1: could not open automation event file \"%2\""), _name, fullpath) << endmsg;
- return -1;
- }
-
- out << X_("version ") << current_automation_version_number << endl;
-
- /* XXX use apply_to_points to get thread safety */
-
- for (AutomationList::iterator i = _gain_automation_curve.begin(); i != _gain_automation_curve.end(); ++i) {
- out << "g " << (jack_nframes_t) floor ((*i)->when) << ' ' << (*i)->value << endl;
- }
-
- _panner->save ();
-
- return 0;
-}
-
-int
-IO::load_automation (const string& path)
-{
- string fullpath;
- ifstream in;
- char line[128];
- uint32_t linecnt = 0;
- float version;
- LocaleGuard lg (X_("POSIX"));
-
- fullpath = _session.automation_dir();
- fullpath += path;
-
- in.open (fullpath.c_str());
-
- if (!in) {
- fullpath = _session.automation_dir();
- fullpath += _session.snap_name();
- fullpath += '-';
- fullpath += path;
- in.open (fullpath.c_str());
- if (!in) {
- error << string_compose(_("%1: cannot open automation event file \"%2\" (%2)"), _name, fullpath, strerror (errno)) << endmsg;
- return -1;
- }
- }
-
- clear_automation ();
-
- while (in.getline (line, sizeof(line), '\n')) {
- char type;
- jack_nframes_t when;
- double value;
-
- if (++linecnt == 1) {
- if (memcmp (line, "version", 7) == 0) {
- if (sscanf (line, "version %f", &version) != 1) {
- error << string_compose(_("badly formed version number in automation event file \"%1\""), path) << endmsg;
- return -1;
- }
- } else {
- error << string_compose(_("no version information in automation event file \"%1\""), path) << endmsg;
- return -1;
- }
-
- if (version != current_automation_version_number) {
- error << string_compose(_("mismatched automation event file version (%1)"), version) << endmsg;
- return -1;
- }
-
- continue;
- }
-
- if (sscanf (line, "%c %" PRIu32 " %lf", &type, &when, &value) != 3) {
- warning << string_compose(_("badly formatted automation event record at line %1 of %2 (ignored)"), linecnt, path) << endmsg;
- continue;
- }
-
- switch (type) {
- case 'g':
- _gain_automation_curve.add (when, value, true);
- break;
-
- case 's':
- break;
-
- case 'm':
- break;
-
- case 'p':
- /* older (pre-1.0) versions of ardour used this */
- break;
-
- default:
- warning << _("dubious automation event found (and ignored)") << endmsg;
- }
- }
-
- _gain_automation_curve.save_state (_("loaded from disk"));
-
- return 0;
-}
-
void
IO::clear_automation ()
{
}
void
-IO::automation_snapshot (jack_nframes_t now)
+IO::automation_snapshot (nframes_t now)
{
if (last_automation_snapshot > now || (now - last_automation_snapshot) > _automation_interval) {
}
void
-IO::transport_stopped (jack_nframes_t frame)
+IO::transport_stopped (nframes_t frame)
{
_gain_automation_curve.reposition_for_rt_add (frame);
if (_gain_automation_curve.automation_state() != Off) {
- if (gain_automation_recording()) {
- _gain_automation_curve.save_state (_("automation write/touch"));
- }
-
/* the src=0 condition is a special signal to not propagate
automation gain changes into the mix group when locating.
*/