fix initialization of control protocols so that brand new sessions get working contro...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 26 Apr 2012 16:18:03 +0000 (16:18 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 26 Apr 2012 16:18:03 +0000 (16:18 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@12096 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/control_protocol_manager.cc
libs/surfaces/mackie/device_profile.cc
libs/surfaces/mackie/gui.cc
libs/surfaces/mackie/mackie_control_protocol.cc
libs/surfaces/mackie/mackie_control_protocol.h
libs/surfaces/mackie/mcp_buttons.cc
libs/surfaces/mackie/strip.cc
libs/surfaces/mackie/surface.cc

index c72d3f31d04beab581e924d35546268c193c0b89..6aa0c51da24cd20d2fb290bcf33a7e9e03ae94a3 100644 (file)
@@ -41,7 +41,6 @@ const string ControlProtocolManager::state_node_name = X_("ControlProtocols");
 
 ControlProtocolManager::ControlProtocolManager ()
 {
-
 }
 
 ControlProtocolManager::~ControlProtocolManager()
@@ -320,13 +319,15 @@ ControlProtocolManager::set_state (const XMLNode& node, int /*version*/)
                        if (prop && string_is_affirmative (prop->value())) {
                                if ((prop = (*citer)->property (X_("name"))) != 0) {
                                        ControlProtocolInfo* cpi = cpi_by_name (prop->value());
+
                                        if (cpi) {
-                                               if (!(*citer)->children().empty()) {
-                                                       cpi->state = (*citer)->children().front ();
-                                               } else {
-                                                       cpi->state = 0;
+
+                                               if (cpi->state) {
+                                                       delete cpi->state;
                                                }
 
+                                               cpi->state = new XMLNode (**citer);
+
                                                if (_session) {
                                                        instantiate (*cpi);
                                                } else {
index 04975270abe41ea4a90875f86647c487ea6ac7f9..110038ca2bcb1e8bd259fd11724d3079a728cb58 100644 (file)
@@ -120,8 +120,6 @@ DeviceProfile::reload_device_profiles ()
 
                XMLTree tree;
 
-               std::cerr << "Loading " << fullpath << std::endl;
-               
                if (!tree.read (fullpath.c_str())) {
                        continue;
                }
index adaf2df94507f646aff0c6a02e0920696ddb8a9a..8728b4a88c51e8c097a371d9f98557a08098cc4e 100644 (file)
@@ -84,6 +84,7 @@ MackieControlProtocolGUI::MackieControlProtocolGUI (MackieControlProtocol& p)
        table->set_row_spacings (4);
        table->set_col_spacings (6);
        l = manage (new Gtk::Label (_("Device Type:")));
+       l->set_alignment (1.0, 0.5);
        table->attach (*l, 0, 1, 0, 1, AttachOptions(FILL|EXPAND), AttachOptions(0));
        table->attach (_surface_combo, 1, 2, 0, 1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 20);
 
index 78fed5cb82b7679adc439172896ecc70aa76cbd8..c1f53179763f85c038a0fc8f58a74ba0ecdd4330 100644 (file)
@@ -321,13 +321,6 @@ MackieControlProtocol::switch_banks (uint32_t initial, bool force)
                return;
        }
 
-       uint32_t delta = sorted.size() - strip_cnt;
-
-       if (delta > 0 && initial > delta) {
-               DEBUG_TRACE (DEBUG::MackieControl, string_compose ("not switching to %1\n", initial));
-               return;
-       }
-
        _current_initial_bank = initial;
        _current_selected_track = -1;
 
@@ -548,7 +541,7 @@ MackieControlProtocol::set_profile (const string& profile_name)
 }      
 
 void
-MackieControlProtocol::set_device (const string& device_name)
+MackieControlProtocol::set_device (const string& device_name, bool allow_activation)
 {
        map<string,DeviceInfo>::iterator d = DeviceInfo::device_info.find (device_name);
 
@@ -563,9 +556,13 @@ MackieControlProtocol::set_device (const string& device_name)
 
        _device_info = d->second;
 
-       if (_active) {
-               create_surfaces ();
-               switch_banks (0, true);
+       if (allow_activation) {
+               set_active (true);
+       } else {
+               if (_active) {
+                       create_surfaces ();
+                       switch_banks (0, true);
+               }
        }
 }
 
@@ -691,7 +688,7 @@ MackieControlProtocol::set_state (const XMLNode & node, int /*version*/)
        }
 
        if ((prop = node.property (X_("device-name"))) != 0) {
-               set_device (prop->value());
+               set_device (prop->value(), false);
        }
 
        if ((prop = node.property (X_("device-profile"))) != 0) {
index 801434c30ca25b63d96840e3e96c39117c3c7b1a..0df770b36eab788ad46da8e55edb9cd3943ec232 100644 (file)
@@ -122,7 +122,7 @@ class MackieControlProtocol
        Mackie::DeviceProfile& device_profile() { return _device_profile; }
 
        int set_active (bool yn);
-       void set_device (const std::string&);
+       void set_device (const std::string&, bool allow_activation = true);
        void set_profile (const std::string&);
 
        bool     flip_mode () const { return _flip_mode; }
index f8ebedb7b923b133048ab0dcb6b8e10b320ca93d..6ded9a9d2088f48b522a82fa3e3b69067367c8f8 100644 (file)
@@ -17,6 +17,8 @@
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include <algorithm>
+
 #include "pbd/memento_command.h"
 
 #include "ardour/debug.h"
@@ -94,25 +96,22 @@ LedState
 MackieControlProtocol::left_press (Button &)
 {
        Sorted sorted = get_sorted_routes();
-       uint32_t strip_cnt = n_strips ();
+       uint32_t strip_cnt = n_strips (); 
+       uint32_t route_cnt = sorted.size();
 
        DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank left with current initial = %1 nstrips = %2 tracks/busses = %3\n",
-                                                          _current_initial_bank, strip_cnt, sorted.size()));
+                                                          _current_initial_bank, strip_cnt, route_cnt));
 
-       if (sorted.size() > strip_cnt) {
-               int new_initial = _current_initial_bank - strip_cnt;
-               if (new_initial < 0) {
-                       new_initial = 0;
-               }
-               
-               if (new_initial != int (_current_initial_bank)) {
-                       switch_banks (new_initial);
+       if (route_cnt && route_cnt > strip_cnt) {
+               if (_current_initial_bank > strip_cnt) {
+                       switch_banks (_current_initial_bank - strip_cnt);
+               } else {
+                       switch_banks (0);
                }
 
                return on;
-       } else {
-               return flashing;
        }
+       return off;
 }
 
 LedState 
@@ -126,25 +125,17 @@ MackieControlProtocol::right_press (Button &)
 {
        Sorted sorted = get_sorted_routes();
        uint32_t strip_cnt = n_strips();
+       uint32_t route_cnt = sorted.size();
 
        DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank right with current initial = %1 nstrips = %2 tracks/busses = %3\n",
                                                           _current_initial_bank, strip_cnt, sorted.size()));
 
-       if (sorted.size() > strip_cnt) {
-               uint32_t delta = sorted.size() - (strip_cnt + _current_initial_bank);
-
-               if (delta > strip_cnt) {
-                       delta = strip_cnt;
-               }
-               
-               if (delta > 0) {
-                       switch_banks (_current_initial_bank + delta);
-               }
-
+       if (route_cnt && route_cnt > strip_cnt) {
+               uint32_t new_initial = std::min (_current_initial_bank + strip_cnt, route_cnt - 1);
+               switch_banks (new_initial);
                return on;
-       } else {
-               return flashing;
        }
+
        return off;
 }
 
index 76fcc25a6c768e8bedcc2df0e78f2217c42857ff..af859ab41d1abb9a49e4fdb96533571a324a30c3 100644 (file)
@@ -151,6 +151,7 @@ Strip::set_route (boost::shared_ptr<Route> r, bool with_messages)
        reset_saved_values ();
 
        if (!r) {
+               zero ();
                return;
        }
 
@@ -213,8 +214,6 @@ Strip::set_route (boost::shared_ptr<Route> r, bool with_messages)
                        if ((a = automatable.find (PanWidthAutomation)) != automatable.end()) {
                                possible_pot_parameters.push_back (PanWidthAutomation);
                        }
-               } else {
-                       std::cerr << "connected to route without a panner\n";
                }
        }
 }
index f27ac3893eebe78bf45f5525684615b0c31e43f3..fecc4d5a33e76d99d34868a85d406c904673a15c 100644 (file)
@@ -606,9 +606,9 @@ void
 Surface::map_routes (const vector<boost::shared_ptr<Route> >& routes)
 {
        vector<boost::shared_ptr<Route> >::const_iterator r;
-       Strips::iterator s;
+       Strips::iterator s = strips.begin();
 
-       for (r = routes.begin(), s = strips.begin(); r != routes.end() && s != strips.end(); ++s) {
+       for (r = routes.begin(); r != routes.end() && s != strips.end(); ++s) {
 
                /* don't try to assign routes to a locked strip. it won't
                   use it anyway, but if we do, then we get out of sync