From d46acb86eaa3a94fb2dc673964271ecfe0f004dd Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 13 Mar 2012 20:14:55 +0000 Subject: redesign how XML state, bitslots and names get propagated during copying a send/port insert/return git-svn-id: svn://localhost/ardour2/branches/3.0@11669 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/port_insert.h | 9 +++- libs/ardour/ardour/return.h | 4 +- libs/ardour/ardour/send.h | 5 ++- libs/ardour/io_processor.cc | 16 +++---- libs/ardour/port.cc | 2 +- libs/ardour/port_insert.cc | 50 +++++++++++++++++---- libs/ardour/processor.cc | 27 +++++++----- libs/ardour/return.cc | 57 ++++++++++++++---------- libs/ardour/send.cc | 95 ++++++++++++++++++++++------------------ 9 files changed, 164 insertions(+), 101 deletions(-) (limited to 'libs') diff --git a/libs/ardour/ardour/port_insert.h b/libs/ardour/ardour/port_insert.h index 2ff9031afa..f42294b2b4 100644 --- a/libs/ardour/ardour/port_insert.h +++ b/libs/ardour/ardour/port_insert.h @@ -45,6 +45,8 @@ class PortInsert : public IOProcessor { public: PortInsert (Session&, boost::shared_ptr, boost::shared_ptr mm); + PortInsert (Session&, const std::string&, uint32_t bitslot, + boost::shared_ptr, boost::shared_ptr mm); ~PortInsert (); XMLNode& state(bool full); @@ -63,7 +65,7 @@ class PortInsert : public IOProcessor void activate (); void deactivate (); - uint32_t bit_slot() const { return bitslot; } + uint32_t bit_slot() const { return _bitslot; } void start_latency_detection (); void stop_latency_detection (); @@ -72,13 +74,16 @@ class PortInsert : public IOProcessor void set_measured_latency (framecnt_t); framecnt_t latency () const; + static void make_unique (XMLNode &); + static std::string name_and_id_new_insert (Session&, uint32_t&); + private: /* disallow copy construction */ PortInsert (const PortInsert&); boost::shared_ptr _out; - uint32_t bitslot; + uint32_t _bitslot; MTDM* _mtdm; bool _latency_detect; framecnt_t _latency_flush_frames; diff --git a/libs/ardour/ardour/return.h b/libs/ardour/ardour/return.h index 153e50f482..f41360b73b 100644 --- a/libs/ardour/ardour/return.h +++ b/libs/ardour/ardour/return.h @@ -37,6 +37,7 @@ class Return : public IOProcessor { public: Return (Session&, bool internal = false); + Return (Session&, const std::string& name, uint32_t bslot, bool internal = false); virtual ~Return (); uint32_t bit_slot() const { return _bitslot; } @@ -59,7 +60,8 @@ public: bool configure_io (ChanCount in, ChanCount out); static uint32_t how_many_returns(); - static void make_unique (XMLNode &, Session &); + static void make_unique (XMLNode &); + static std::string name_and_id_new_return (Session&, uint32_t&); protected: bool _metering; diff --git a/libs/ardour/ardour/send.h b/libs/ardour/ardour/send.h index c83eff65ab..dce8fd31d5 100644 --- a/libs/ardour/ardour/send.h +++ b/libs/ardour/ardour/send.h @@ -36,6 +36,7 @@ class Send : public Delivery { public: Send (Session&, boost::shared_ptr pannable, boost::shared_ptr, Delivery::Role r = Delivery::Send); + Send (Session&, const std::string& name, uint32_t bitslot, boost::shared_ptr pannable, boost::shared_ptr, Delivery::Role r = Delivery::Send); virtual ~Send (); uint32_t bit_slot() const { return _bitslot; } @@ -67,7 +68,8 @@ class Send : public Delivery std::string value_as_string (boost::shared_ptr) const; static uint32_t how_many_sends(); - static void make_unique (XMLNode &, Session &); + static void make_unique (XMLNode &); + static std::string name_and_id_new_send (Session&, Delivery::Role r, uint32_t&); protected: bool _metering; @@ -81,7 +83,6 @@ class Send : public Delivery int set_state_2X (XMLNode const &, int); uint32_t _bitslot; - static std::string name_and_id_new_send (Session&, Delivery::Role r, uint32_t&); }; } // namespace ARDOUR diff --git a/libs/ardour/io_processor.cc b/libs/ardour/io_processor.cc index 8e7cba0ab1..12ab63483c 100644 --- a/libs/ardour/io_processor.cc +++ b/libs/ardour/io_processor.cc @@ -169,7 +169,7 @@ IOProcessor::set_state (const XMLNode& node, int version) XMLNodeIterator niter; const string instr = enum_2_string (IO::Input); const string outstr = enum_2_string (IO::Output); - + if (_own_input) { for (niter = nlist.begin(); niter != nlist.end(); ++niter) { const XMLProperty* prop; @@ -184,21 +184,21 @@ IOProcessor::set_state (const XMLNode& node, int version) } } } - + if (io_node) { _input->set_state(*io_node, version); - + // legacy sessions: use IO name if ((prop = node.property ("name")) == 0) { set_name (_input->name()); } - + } else { /* no input, which is OK */ } - + } - + if (_own_output) { for (niter = nlist.begin(); niter != nlist.end(); ++niter) { if ((*niter)->name() == "IO") { @@ -215,10 +215,10 @@ IOProcessor::set_state (const XMLNode& node, int version) } } } - + if (io_node) { _output->set_state(*io_node, version); - + // legacy sessions: use IO name if ((prop = node.property ("name")) == 0) { set_name (_output->name()); diff --git a/libs/ardour/port.cc b/libs/ardour/port.cc index 157b7e9a21..e9a3c09a10 100644 --- a/libs/ardour/port.cc +++ b/libs/ardour/port.cc @@ -70,7 +70,7 @@ Port::Port (std::string const & n, DataType t, Flags f) } if ((_jack_port = jack_port_register (_engine->jack (), _name.c_str (), t.to_jack_type (), _flags, 0)) == 0) { - cerr << "Failed to register JACK port, reason is unknown from here\n"; + cerr << "Failed to register JACK port \"" << _name << "\", reason is unknown from here\n"; throw failed_constructor (); } } diff --git a/libs/ardour/port_insert.cc b/libs/ardour/port_insert.cc index c5d941428f..70f88e904f 100644 --- a/libs/ardour/port_insert.cc +++ b/libs/ardour/port_insert.cc @@ -41,9 +41,27 @@ using namespace std; using namespace ARDOUR; using namespace PBD; +string +PortInsert::name_and_id_new_insert (Session& s, uint32_t& bitslot) +{ + bitslot = s.next_insert_id (); + return string_compose (_("insert %1"), bitslot+ 1); +} + PortInsert::PortInsert (Session& s, boost::shared_ptr pannable, boost::shared_ptr mm) - : IOProcessor (s, true, true, string_compose (_("insert %1"), (bitslot = s.next_insert_id()) + 1), "") + : IOProcessor (s, true, true, name_and_id_new_insert (s, _bitslot), "") + , _out (new Delivery (s, _output, pannable, mm, _name, Delivery::Insert)) +{ + _mtdm = 0; + _latency_detect = false; + _latency_flush_frames = false; + _measured_latency = 0; +} + +PortInsert::PortInsert (Session& s, const std::string& name, uint32_t bslot, boost::shared_ptr pannable, boost::shared_ptr mm) + : IOProcessor (s, true, true, name, "") , _out (new Delivery (s, _output, pannable, mm, _name, Delivery::Insert)) + , _bitslot (bslot) { _mtdm = 0; _latency_detect = false; @@ -53,7 +71,7 @@ PortInsert::PortInsert (Session& s, boost::shared_ptr pannable, boost: PortInsert::~PortInsert () { - _session.unmark_insert_id (bitslot); + _session.unmark_insert_id (_bitslot); delete _mtdm; } @@ -164,7 +182,7 @@ PortInsert::state (bool full) XMLNode& node = IOProcessor::state(full); char buf[32]; node.add_property ("type", "port"); - snprintf (buf, sizeof (buf), "%" PRIu32, bitslot); + snprintf (buf, sizeof (buf), "%" PRIu32, _bitslot); node.add_property ("bitslot", buf); snprintf (buf, sizeof (buf), "%" PRId64, _measured_latency); node.add_property("latency", buf); @@ -216,12 +234,14 @@ PortInsert::set_state (const XMLNode& node, int version) _measured_latency = latency; } - if ((prop = node.property ("bitslot")) == 0) { - bitslot = _session.next_insert_id(); - } else { - _session.unmark_insert_id (bitslot); - sscanf (prop->value().c_str(), "%" PRIu32, &bitslot); - _session.mark_insert_id (bitslot); + if (!node.property ("ignore-bitslot")) { + if ((prop = node.property ("bitslot")) == 0) { + _bitslot = _session.next_insert_id(); + } else { + _session.unmark_insert_id (_bitslot); + sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot); + _session.mark_insert_id (_bitslot); + } } return 0; @@ -295,3 +315,15 @@ PortInsert::deactivate () _out->deactivate (); } + +/** Set up the XML description of a send so that we will not + * reset its name or bitslot during ::set_state() + * @param state XML insert state. + */ + +void +PortInsert::make_unique (XMLNode &state) +{ + state.add_property ("ignore-bitslot", "1"); + state.add_property ("ignore-name", "1"); +} diff --git a/libs/ardour/processor.cc b/libs/ardour/processor.cc index 4be545126b..79384c701e 100644 --- a/libs/ardour/processor.cc +++ b/libs/ardour/processor.cc @@ -141,15 +141,15 @@ Processor::set_state_2X (const XMLNode & node, int /*version*/) XMLProperty const * prop; XMLNodeList children = node.children (); - + for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) { if ((*i)->name() == X_("IO")) { - + if ((prop = (*i)->property ("name")) != 0) { set_name (prop->value ()); } - + set_id (**i); if ((prop = (*i)->property ("active")) != 0) { @@ -177,17 +177,20 @@ Processor::set_state (const XMLNode& node, int version) const XMLProperty *prop; const XMLProperty *legacy_active = 0; - - // may not exist for legacy 3.0 sessions - if ((prop = node.property ("name")) != 0) { - /* don't let derived classes have a crack at set_name, - as some (like Send) will screw with the one we suggest. - */ - Processor::set_name (prop->value()); + bool leave_name_alone = (node.property ("ignore-name") != 0); + + if (!leave_name_alone) { + // may not exist for legacy 3.0 sessions + if ((prop = node.property ("name")) != 0) { + /* don't let derived classes have a crack at set_name, + as some (like Send) will screw with the one we suggest. + */ + Processor::set_name (prop->value()); + } + + set_id (node); } - set_id (node); - XMLNodeList nlist = node.children(); XMLNodeIterator niter; diff --git a/libs/ardour/return.cc b/libs/ardour/return.cc index ca02b11dc0..8433f7de08 100644 --- a/libs/ardour/return.cc +++ b/libs/ardour/return.cc @@ -38,10 +38,29 @@ using namespace ARDOUR; using namespace PBD; +std::string +Return::name_and_id_new_return (Session& s, uint32_t& bitslot) +{ + bitslot = s.next_return_id(); + return string_compose (_("return %1"), bitslot + 1); +} + + Return::Return (Session& s, bool internal) : IOProcessor (s, (internal ? false : true), false, - string_compose (_("return %1"), (_bitslot = s.next_return_id()) + 1)) + name_and_id_new_return (s, _bitslot)) + , _metering (false) +{ + /* never muted */ + + _amp.reset (new Amp (_session)); + _meter.reset (new PeakMeter (_session)); +} + +Return::Return (Session& s, const std::string& name, uint32_t bslot, bool internal) + : IOProcessor (s, (internal ? false : true), false, name) , _metering (false) + , _bitslot (bslot) { /* never muted */ @@ -92,12 +111,14 @@ Return::set_state (const XMLNode& node, int version) IOProcessor::set_state (*insert_node, version); - if ((prop = node.property ("bitslot")) == 0) { - _bitslot = _session.next_return_id(); - } else { - _session.unmark_return_id (_bitslot); - sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot); - _session.mark_return_id (_bitslot); + if (!node.property ("ignore-bitslot")) { + if ((prop = node.property ("bitslot")) == 0) { + _bitslot = _session.next_return_id(); + } else { + _session.unmark_return_id (_bitslot); + sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot); + _session.mark_return_id (_bitslot); + } } return 0; @@ -154,27 +175,15 @@ Return::configure_io (ChanCount in, ChanCount out) return true; } -/** Set up the XML description of a return so that its name is unique. +/** Set up the XML description of a return so that we will not + * reset its name or bitslot during ::set_state() * @param state XML return state. - * @param session Session. */ void -Return::make_unique (XMLNode &state, Session &session) +Return::make_unique (XMLNode &state) { - uint32_t const bitslot = session.next_return_id() + 1; - - char buf[32]; - snprintf (buf, sizeof (buf), "%" PRIu32, bitslot); - state.property("bitslot")->set_value (buf); - - std::string const name = string_compose (_("return %1"), bitslot); - - state.property("name")->set_value (name); - - XMLNode* io = state.child ("IO"); - if (io) { - io->property("name")->set_value (name); - } + state.add_property ("ignore-bitslot", "1"); + state.add_property ("ignore-name", "1"); } diff --git a/libs/ardour/send.cc b/libs/ardour/send.cc index b6f042cbb2..ce48b2712b 100644 --- a/libs/ardour/send.cc +++ b/libs/ardour/send.cc @@ -85,6 +85,26 @@ Send::Send (Session& s, boost::shared_ptr p, boost::shared_ptrgain_control ()); } +Send::Send (Session& s, const std::string& name, uint32_t bslot, boost::shared_ptr p, boost::shared_ptr mm, Role r) + : Delivery (s, p, mm, name, r) + , _metering (false) + , _bitslot (bslot) +{ + if (_role == Listen) { + /* we don't need to do this but it keeps things looking clean + in a debugger. _bitslot is not used by listen sends. + */ + _bitslot = 0; + } + + boost_debug_shared_ptr_mark_interesting (this, "send"); + + _amp.reset (new Amp (_session)); + _meter.reset (new PeakMeter (_session)); + + add_control (_amp->gain_control ()); +} + Send::~Send () { _session.unmark_send_id (_bitslot); @@ -191,34 +211,37 @@ Send::set_state (const XMLNode& node, int version) Delivery::set_state (node, version); - /* don't try to reset bitslot if there is a node for it already: this can cause - issues with the session's accounting of send ID's - */ + if (node.property ("ignore-bitslot") == 0) { - if ((prop = node.property ("bitslot")) == 0) { - if (_role == Delivery::Aux) { - _bitslot = _session.next_aux_send_id (); - } else if (_role == Delivery::Send) { - _bitslot = _session.next_send_id (); - } else { - // bitslot doesn't matter but make it zero anyway - _bitslot = 0; - } - } else { - if (_role == Delivery::Aux) { - _session.unmark_aux_send_id (_bitslot); - sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot); - _session.mark_aux_send_id (_bitslot); - } else if (_role == Delivery::Send) { - _session.unmark_send_id (_bitslot); - sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot); - _session.mark_send_id (_bitslot); + /* don't try to reset bitslot if there is a node for it already: this can cause + issues with the session's accounting of send ID's + */ + + if ((prop = node.property ("bitslot")) == 0) { + if (_role == Delivery::Aux) { + _bitslot = _session.next_aux_send_id (); + } else if (_role == Delivery::Send) { + _bitslot = _session.next_send_id (); + } else { + // bitslot doesn't matter but make it zero anyway + _bitslot = 0; + } } else { - // bitslot doesn't matter but make it zero anyway - _bitslot = 0; + if (_role == Delivery::Aux) { + _session.unmark_aux_send_id (_bitslot); + sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot); + _session.mark_aux_send_id (_bitslot); + } else if (_role == Delivery::Send) { + _session.unmark_send_id (_bitslot); + sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot); + _session.mark_send_id (_bitslot); + } else { + // bitslot doesn't matter but make it zero anyway + _bitslot = 0; + } } - } - + } + XMLNodeList nlist = node.children(); for (XMLNodeIterator i = nlist.begin(); i != nlist.end(); ++i) { if ((*i)->name() == X_("Processor")) { @@ -292,28 +315,16 @@ Send::configure_io (ChanCount in, ChanCount out) return true; } -/** Set up the XML description of a send so that its name is unique. +/** Set up the XML description of a send so that we will not + * reset its name or bitslot during ::set_state() * @param state XML send state. * @param session Session. */ void -Send::make_unique (XMLNode &state, Session &session) +Send::make_unique (XMLNode &state) { - uint32_t const bitslot = session.next_send_id() + 1; - - char buf[32]; - snprintf (buf, sizeof (buf), "%" PRIu32, bitslot); - state.property("bitslot")->set_value (buf); - - string const name = string_compose (_("send %1"), bitslot); - - state.property("name")->set_value (name); - - XMLNode* io = state.child ("IO"); - - if (io) { - io->property("name")->set_value (name); - } + state.add_property ("ignore-bitslot", "1"); + state.add_property ("ignore-name", "1"); } bool -- cgit v1.2.3