X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Froute_group.cc;h=629216da39e5763b4fa2ed122c4fe1386169a16d;hb=75ede0dd6bda0136aef612b0e427ae25b208d0d0;hp=792bcfc3e50da996062b4f7b0e0605641942e41f;hpb=bc56eb8bd73c7b456b646ba0cc627d449baa37f2;p=ardour.git diff --git a/libs/ardour/route_group.cc b/libs/ardour/route_group.cc index 792bcfc3e5..629216da39 100644 --- a/libs/ardour/route_group.cc +++ b/libs/ardour/route_group.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2002 Paul Davis + Copyright (C) 2000-2009 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,17 +17,17 @@ */ -#define __STDC_FORMAT_MACROS #include #include -#include #include "pbd/error.h" #include "pbd/enumwriter.h" +#include "pbd/strsplit.h" #include "ardour/amp.h" +#include "ardour/debug.h" #include "ardour/route_group.h" #include "ardour/audio_track.h" #include "ardour/audio_diskstream.h" @@ -37,49 +37,130 @@ #include "i18n.h" using namespace ARDOUR; -using namespace sigc; +using namespace PBD; using namespace std; -RouteGroup::RouteGroup (Session& s, const string &n, Flag f, Property p) - : _session (s), _name (n), _flags (f), _properties (Property (p)) -{ +namespace ARDOUR { + namespace Properties { + PropertyDescriptor relative; + PropertyDescriptor active; + PropertyDescriptor gain; + PropertyDescriptor mute; + PropertyDescriptor solo; + PropertyDescriptor recenable; + PropertyDescriptor select; + PropertyDescriptor edit; + } } void -RouteGroup::set_name (string str) +RouteGroup::make_property_quarks () { - _name = str; - _session.set_dirty (); - FlagsChanged (0); /* EMIT SIGNAL */ + Properties::relative.property_id = g_quark_from_static_string (X_("relative")); + DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for relative = %1\n", Properties::relative.property_id)); + Properties::active.property_id = g_quark_from_static_string (X_("active")); + DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for active = %1\n", Properties::active.property_id)); + Properties::hidden.property_id = g_quark_from_static_string (X_("hidden")); + DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for hidden = %1\n", Properties::hidden.property_id)); + Properties::gain.property_id = g_quark_from_static_string (X_("gain")); + DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for gain = %1\n", Properties::gain.property_id)); + Properties::mute.property_id = g_quark_from_static_string (X_("mute")); + DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for mute = %1\n", Properties::mute.property_id)); + Properties::solo.property_id = g_quark_from_static_string (X_("solo")); + DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for solo = %1\n", Properties::solo.property_id)); + Properties::recenable.property_id = g_quark_from_static_string (X_("recenable")); + DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for recenable = %1\n", Properties::recenable.property_id)); + Properties::select.property_id = g_quark_from_static_string (X_("select")); + DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for select = %1\n", Properties::select.property_id)); + Properties::edit.property_id = g_quark_from_static_string (X_("edit")); + DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for edit = %1\n", Properties::edit.property_id)); +} + +#define ROUTE_GROUP_DEFAULT_PROPERTIES _relative (Properties::relative, false) \ + , _active (Properties::active, false) \ + , _hidden (Properties::hidden, false) \ + , _gain (Properties::gain, false) \ + , _mute (Properties::mute, false) \ + , _solo (Properties::solo, false) \ + , _recenable (Properties::recenable, false) \ + , _select (Properties::select, false) \ + , _edit (Properties::edit, false) + +RouteGroup::RouteGroup (Session& s, const string &n) + : SessionObject (s, n) + , routes (new RouteList) + , ROUTE_GROUP_DEFAULT_PROPERTIES +{ + _xml_node_name = X_("RouteGroup"); + + add_property (_relative); + add_property (_active); + add_property (_hidden); + add_property (_gain); + add_property (_mute); + add_property (_solo); + add_property (_recenable); + add_property (_select); + add_property (_edit); +} + +RouteGroup::~RouteGroup () +{ + for (RouteList::iterator i = routes->begin(); i != routes->end();) { + RouteList::iterator tmp = i; + ++tmp; + + (*i)->leave_route_group (); + + i = tmp; + } } +/** Add a route to a group. Adding a route which is already in the group is allowed; nothing will happen. + * @param r Route to add. + */ int -RouteGroup::add (Route *r) +RouteGroup::add (boost::shared_ptr r) { - routes.push_back (r); - r->GoingAway.connect (sigc::bind (mem_fun (*this, &RouteGroup::remove_when_going_away), r)); + if (find (routes->begin(), routes->end(), r) != routes->end()) { + return 0; + } + + r->leave_route_group (); + + routes->push_back (r); + + r->join_route_group (this); + r->DropReferences.connect_same_thread (*this, boost::bind (&RouteGroup::remove_when_going_away, this, boost::weak_ptr (r))); + _session.set_dirty (); - changed (); /* EMIT SIGNAL */ + MembershipChanged (); /* EMIT SIGNAL */ return 0; } void -RouteGroup::remove_when_going_away (Route *r) +RouteGroup::remove_when_going_away (boost::weak_ptr wr) { - remove (r); + boost::shared_ptr r (wr.lock()); + + if (r) { + remove (r); + } } int -RouteGroup::remove (Route *r) +RouteGroup::remove (boost::shared_ptr r) { - list::iterator i; + RouteList::iterator i; - if ((i = find (routes.begin(), routes.end(), r)) != routes.end()) { - routes.erase (i); + if ((i = find (routes->begin(), routes->end(), r)) != routes->end()) { + r->leave_route_group (); + routes->erase (i); _session.set_dirty (); - changed (); /* EMIT SIGNAL */ + MembershipChanged (); /* EMIT SIGNAL */ return 0; } + return -1; } @@ -89,7 +170,7 @@ RouteGroup::get_min_factor(gain_t factor) { gain_t g; - for (list::iterator i = routes.begin(); i != routes.end(); i++) { + for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) { g = (*i)->amp()->gain(); if ( (g+g*factor) >= 0.0f) @@ -108,7 +189,7 @@ RouteGroup::get_max_factor(gain_t factor) { gain_t g; - for (list::iterator i = routes.begin(); i != routes.end(); i++) { + for (RouteList::iterator i = routes->begin(); i != routes->end(); i++) { g = (*i)->amp()->gain(); // if the current factor woulnd't raise this route above maximum @@ -130,9 +211,19 @@ XMLNode& RouteGroup::get_state (void) { XMLNode *node = new XMLNode ("RouteGroup"); - node->add_property ("name", _name); - node->add_property ("flags", enum_2_string (_flags)); - node->add_property ("properties", enum_2_string (_properties)); + + add_properties (*node); + + if (!routes->empty()) { + stringstream str; + + for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) { + str << (*i)->id () << ' '; + } + + node->add_property ("routes", str.str()); + } + return *node; } @@ -143,103 +234,152 @@ RouteGroup::set_state (const XMLNode& node, int version) return set_state_2X (node, version); } + set_values (node); + const XMLProperty *prop; - if ((prop = node.property ("name")) != 0) { - _name = prop->value(); + if ((prop = node.property ("routes")) != 0) { + stringstream str (prop->value()); + vector ids; + split (str.str(), ids, ' '); + + for (vector::iterator i = ids.begin(); i != ids.end(); ++i) { + PBD::ID id (*i); + boost::shared_ptr r = _session.route_by_id (id); + + if (r) { + add (r); + } + } } - if ((prop = node.property ("flags")) != 0) { - _flags = Flag (string_2_enum (prop->value(), _flags)); - } + return 0; +} + +int +RouteGroup::set_state_2X (const XMLNode& node, int /*version*/) +{ + set_values (node); - if ((prop = node.property ("properties")) != 0) { - _properties = Property (string_2_enum (prop->value(), _properties)); + if (node.name() == "MixGroup") { + _gain = true; + _mute = true; + _solo = true; + _recenable = true; + _edit = false; + } else if (node.name() == "EditGroup") { + _gain = false; + _mute = false; + _solo = false; + _recenable = false; + _edit = true; } return 0; } -int -RouteGroup::set_state_2X (const XMLNode& node, int /*version*/) +void +RouteGroup::set_gain (bool yn) +{ + if (is_gain() == yn) { + return; + } + _gain = yn; +} + +void +RouteGroup::set_mute (bool yn) { - XMLProperty const * prop; + if (is_mute() == yn) { + return; + } + _mute = yn; +} - if ((prop = node.property ("name")) != 0) { - _name = prop->value(); +void +RouteGroup::set_solo (bool yn) +{ + if (is_solo() == yn) { + return; } + _solo = yn; +} - if ((prop = node.property ("flags")) != 0) { - _flags = Flag (string_2_enum (prop->value(), _flags)); +void +RouteGroup::set_recenable (bool yn) +{ + if (is_recenable() == yn) { + return; } + _recenable = yn; +} - if (node.name() == "MixGroup") { - _properties = Property (Gain | Mute | Solo | RecEnable); - } else if (node.name() == "EditGroup") { - _properties = Property (Select | Edit); +void +RouteGroup::set_select (bool yn) +{ + if (is_select() == yn) { + return; } + _select = yn; +} - return 0; +void +RouteGroup::set_edit (bool yn) +{ + if (is_edit() == yn) { + return; + } + _edit = yn; } void -RouteGroup::set_active (bool yn, void *src) +RouteGroup::set_active (bool yn, void* /*src*/) { if (is_active() == yn) { return; } - if (yn) { - _flags = Flag (_flags | Active); - } else { - _flags = Flag (_flags & ~Active); - } + + _active = yn; + send_change (PropertyChange (Properties::active)); + _session.set_dirty (); - FlagsChanged (src); /* EMIT SIGNAL */ } void -RouteGroup::set_relative (bool yn, void *src) - +RouteGroup::set_relative (bool yn, void* /*src*/) { if (is_relative() == yn) { return; } - if (yn) { - _flags = Flag (_flags | Relative); - } else { - _flags = Flag (_flags & ~Relative); - } + _relative = yn; _session.set_dirty (); - FlagsChanged (src); /* EMIT SIGNAL */ } void -RouteGroup::set_hidden (bool yn, void *src) - +RouteGroup::set_hidden (bool yn, void* /*src*/) { if (is_hidden() == yn) { return; } if (yn) { - _flags = Flag (_flags | Hidden); + _hidden = true; if (Config->get_hiding_groups_deactivates_groups()) { - _flags = Flag (_flags & ~Active); + _active = false; } } else { - _flags = Flag (_flags & ~Hidden); + _hidden = false; if (Config->get_hiding_groups_deactivates_groups()) { - _flags = Flag (_flags | Active); + _active = true; } } _session.set_dirty (); - FlagsChanged (src); /* EMIT SIGNAL */ } void -RouteGroup::audio_track_group (set& ats) +RouteGroup::audio_track_group (set >& ats) { - for (list::iterator i = routes.begin(); i != routes.end(); ++i) { - AudioTrack* at = dynamic_cast(*i); + for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) { + boost::shared_ptr at = boost::dynamic_pointer_cast(*i); if (at) { ats.insert (at); } @@ -254,20 +394,20 @@ RouteGroup::make_subgroup () /* since we don't do MIDI Busses yet, check quickly ... */ - for (list::iterator i = routes.begin(); i != routes.end(); ++i) { + for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) { if ((*i)->output()->n_ports().n_midi() != 0) { PBD::info << _("You cannot subgroup MIDI tracks at this time") << endmsg; return; } } - for (list::iterator i = routes.begin(); i != routes.end(); ++i) { + for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) { nin = max (nin, (*i)->output()->n_ports().n_audio()); } try { /* use master bus etc. to determine default nouts */ - rl = _session.new_audio_route (nin, 2, 0, 1); + rl = _session.new_audio_route (false, nin, 2, 0, 1); } catch (...) { return; } @@ -277,7 +417,7 @@ RouteGroup::make_subgroup () boost::shared_ptr bundle = subgroup_bus->input()->bundle (); - for (list::iterator i = routes.begin(); i != routes.end(); ++i) { + for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) { (*i)->output()->disconnect (this); (*i)->output()->connect_ports_to_bundle (bundle, this); } @@ -289,8 +429,8 @@ RouteGroup::destroy_subgroup () if (!subgroup_bus) { return; } - - for (list::iterator i = routes.begin(); i != routes.end(); ++i) { + + for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) { (*i)->output()->disconnect (this); /* XXX find a new bundle to connect to */ } @@ -298,3 +438,14 @@ RouteGroup::destroy_subgroup () _session.remove_route (subgroup_bus); subgroup_bus.reset (); } + +bool +RouteGroup::enabled_property (PBD::PropertyID prop) +{ + OwnedPropertyList::iterator i = _properties->find (prop); + if (i == _properties->end()) { + return false; + } + + return dynamic_cast* > (i->second)->val (); +}