diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2012-06-28 22:27:37 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2012-06-28 22:27:37 +0000 |
commit | 7db500301d1f02e9cb98eb5c744ae68456fac75b (patch) | |
tree | 93690e7d6b6a82e057cc276caba4db1dbca70904 /libs | |
parent | 81de53da1d82244ec589d6d65a5739b3022828c7 (diff) |
further efforts at cleaning up the design of the interaction/relationship between route sort order keys and remote control IDs
git-svn-id: svn://localhost/ardour2/branches/3.0@12962 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/route.h | 3 | ||||
-rw-r--r-- | libs/ardour/ardour/session.h | 1 | ||||
-rw-r--r-- | libs/ardour/route.cc | 114 | ||||
-rw-r--r-- | libs/ardour/session.cc | 60 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 27 |
5 files changed, 164 insertions, 41 deletions
diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h index 695e151dbb..f6c737d766 100644 --- a/libs/ardour/ardour/route.h +++ b/libs/ardour/ardour/route.h @@ -423,6 +423,7 @@ class Route : public SessionObject, public Automatable, public RouteGroupMember, void set_remote_control_id (uint32_t id, bool notify_class_listeners = true); uint32_t remote_control_id () const; + void set_remote_control_id_from_order_key (RouteSortOrderKey); /* for things concerned about *this* route's RID */ @@ -534,7 +535,7 @@ class Route : public SessionObject, public Automatable, public RouteGroupMember, typedef std::map<RouteSortOrderKey,uint32_t> OrderKeys; OrderKeys order_keys; - uint32_t* _remote_control_id; + uint32_t _remote_control_id; void input_change_handler (IOChange, void *src); void output_change_handler (IOChange, void *src); diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index a132a4a5e8..bc14805074 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -235,6 +235,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi }; void sync_order_keys (RouteSortOrderKey); + void sync_remote_id_from_order_keys (RouteSortOrderKey); template<class T> void foreach_route (T *obj, void (T::*func)(Route&)); template<class T> void foreach_route (T *obj, void (T::*func)(boost::shared_ptr<Route>)); diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index 2112336d8b..0c233bfc31 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -195,8 +195,6 @@ Route::~Route () } _processors.clear (); - - delete _remote_control_id; } void @@ -232,11 +230,9 @@ Route::set_remote_control_id (uint32_t id, bool notify_class_listeners) } if (id != remote_control_id()) { - if (!_remote_control_id) { - _remote_control_id = new uint32_t; - } - *_remote_control_id = id; + _remote_control_id = id; RemoteControlIDChanged (); + if (notify_class_listeners) { RemoteControlIDChange (); } @@ -246,16 +242,6 @@ Route::set_remote_control_id (uint32_t id, bool notify_class_listeners) uint32_t Route::remote_control_id() const { - switch (Config->get_remote_model()) { - case UserOrdered: - if (_remote_control_id) { - return *_remote_control_id; - } - break; - default: - break; - } - if (is_master()) { return MasterBusRemoteControlID; } @@ -264,16 +250,7 @@ Route::remote_control_id() const return MonitorBusRemoteControlID; } - /* order keys are zero-based, remote control ID's are one-based - */ - - switch (Config->get_remote_model()) { - case EditorOrdered: - return order_key (EditorSort) + 1; - case MixerOrdered: - default: - return order_key (MixerSort) + 1; - } + return _remote_control_id; } bool @@ -297,6 +274,10 @@ Route::order_key (RouteSortOrderKey key) const void Route::sync_order_keys (RouteSortOrderKey base) { + /* this is called after changes to 1 or more route order keys have been + * made, and we want to sync up. + */ + OrderKeys::iterator i = order_keys.find (base); if (i == order_keys.end()) { @@ -305,27 +286,86 @@ Route::sync_order_keys (RouteSortOrderKey base) for (OrderKeys::iterator k = order_keys.begin(); k != order_keys.end(); ++k) { - if (k->first == MixerSort && (is_master() || is_monitor())) { - /* don't sync the mixer sort keys for master/monitor, + if (is_master() || is_monitor()) { + /* don't sync the sort keys for master/monitor, * since they are not part of the normal ordering. */ - continue; } if (k->first != base) { + DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 set key for %2 to %3 from %4\n", + name(), + enum_2_string (k->first), + i->second, + base)); + k->second = i->second; } } } void +Route::set_remote_control_id_from_order_key (RouteSortOrderKey key) +{ + if (is_master() || is_monitor() || is_hidden()) { + return; + } + + uint32_t n = order_keys[key]; + + switch (Config->get_remote_model()) { + case UserOrdered: + break; + case EditorOrdered: + if (key == EditorSort) { + boost::shared_ptr<Route> master = _session.master_out(); + if (master && n > 0 && n > master->order_key (EditorSort)) { + --n; + } + _remote_control_id = n + 1; + DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: from order key %2, set edit-based RID to %3\n", + name(), n, _remote_control_id)); + RemoteControlIDChanged (); /* EMIT SIGNAL * (per-route) */ + } + break; + + case MixerOrdered: + if (key == MixerSort) { + boost::shared_ptr<Route> master = _session.master_out(); + if (master && n > 0 && n > master->order_key (MixerSort)) { + --n; + } + _remote_control_id = n + 1; + DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: from order key %2, set mix-based RID to %3\n", + name(), n, _remote_control_id)); + RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */ + } + break; + } + + /* don't emit class-level RID signals here, leave that to the entity + that changed the order key, so that we don't get lots + of emissions for no good reasons (e.g. when changing all + route order keys) + */ +} + +void Route::set_order_key (RouteSortOrderKey key, uint32_t n) { - if (order_keys.find (key) == order_keys.end() || order_keys[key] != n) { - order_keys[key] = n; - _session.set_dirty (); + OrderKeys::iterator i = order_keys.find (key); + + if (i != order_keys.end() && i->second == n) { + return; } + + order_keys[key] = n; + + DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key %2 set to %3 (chk=%4)\n", + name(), enum_2_string (key), n, order_key (key))); + + _session.set_dirty (); } string @@ -1894,12 +1934,10 @@ Route::state(bool full_state) node->add_child_nocopy (_mute_control->get_state ()); node->add_child_nocopy (_mute_master->get_state ()); - if (_remote_control_id) { - XMLNode* remote_control_node = new XMLNode (X_("RemoteControl")); - snprintf (buf, sizeof (buf), "%d", *_remote_control_id); - remote_control_node->add_property (X_("id"), buf); - node->add_child_nocopy (*remote_control_node); - } + XMLNode* remote_control_node = new XMLNode (X_("RemoteControl")); + snprintf (buf, sizeof (buf), "%d", _remote_control_id); + remote_control_node->add_property (X_("id"), buf); + node->add_child_nocopy (*remote_control_node); if (_comment.length()) { XMLNode *cmt = node->add_child ("Comment"); diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 47d76ff150..fab877cf0b 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -2205,7 +2205,22 @@ Session::add_routes (RouteList& new_routes, bool input_auto_connect, bool output } RouteAdded (new_routes); /* EMIT SIGNAL */ - Route::RemoteControlIDChange (); /* EMIT SIGNAL */ + + /* we added at least one new route, and everyone who needs to has now + * handled this event. This means that route order keys are correctly + * set and we can now ensure that remote control IDs are set. + */ + + switch (Config->get_remote_model()) { + case UserOrdered: + break; + case MixerOrdered: + sync_remote_id_from_order_keys (MixerSort); + break; + case EditorOrdered: + sync_remote_id_from_order_keys (EditorSort); + break; + } } void @@ -4714,11 +4729,54 @@ Session::sync_order_keys (RouteSortOrderKey sort_key_changed) /* tell everyone that something has happened to the sort keys and let them sync up with the change(s) + this will give objects that manage the sort order keys the + opportunity to keep them in sync if they wish to. */ DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("Sync Order Keys, based on %1\n", enum_2_string (sort_key_changed))); Route::SyncOrderKeys (sort_key_changed); /* EMIT SIGNAL */ + + /* ensure that remote control IDs are in sync with the relevant + order keys. + */ + + sync_remote_id_from_order_keys (sort_key_changed); +} + +void +Session::sync_remote_id_from_order_keys (RouteSortOrderKey sort_key_changed) +{ + /* update remote control IDs if that makes sense */ + + bool do_update = false; + + DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("sync RID to order key %1\n", enum_2_string (sort_key_changed))); + + switch (Config->get_remote_model()) { + case UserOrdered: + break; + case EditorOrdered: + if (sort_key_changed == EditorSort) { + do_update = true; + } + break; + case MixerOrdered: + if (sort_key_changed == MixerSort) { + do_update = true; + } + break; + } + + if (do_update) { + DEBUG_TRACE (DEBUG::OrderKeys, "\tactually update + signal\n"); + boost::shared_ptr<RouteList> r = routes.reader(); + for (RouteList::iterator i = r->begin(); i != r->end(); ++i) { + (*i)->set_remote_control_id_from_order_key (sort_key_changed); + } + + Route::RemoteControlIDChange (); /* EMIT SIGNAL - static */ + } } bool diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index da6f618c11..a3460dddfb 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -3506,8 +3506,33 @@ Session::config_changed (std::string p, bool ours) setup_fpu (); } else if (p == "history-depth") { set_history_depth (Config->get_history_depth()); + } else if (p == "remote-model") { + switch (Config->get_remote_model()) { + case UserOrdered: + break; + case MixerOrdered: + sync_remote_id_from_order_keys (MixerSort); + break; + case EditorOrdered: + sync_remote_id_from_order_keys (EditorSort); + break; + } } else if (p == "sync-all-route-ordering") { - /* XXX sync_order_keys (UndefinedSort); */ + + /* sync to editor order unless mixer is used for remote IDs + */ + + switch (Config->get_remote_model()) { + case UserOrdered: + sync_order_keys (EditorSort); + break; + case EditorOrdered: + sync_order_keys (EditorSort); + break; + case MixerOrdered: + sync_order_keys (MixerSort); + } + } else if (p == "initial-program-change") { if (MIDI::Manager::instance()->mmc()->output_port() && Config->get_initial_program_change() >= 0) { |