Merge branch 'master' into windows
[ardour.git] / libs / surfaces / mackie / mackie_control_protocol.cc
index ffda2435d038d6a78faa4d14ecf19c4feed86ca1..5b772d9af5f4900de89ee8e8541831b29edf067a 100644 (file)
@@ -29,7 +29,6 @@
 #include <float.h>
 #include <sys/time.h>
 #include <errno.h>
-#include <poll.h>
 
 #include <boost/shared_array.hpp>
 
@@ -101,7 +100,7 @@ MackieControlProtocol::MackieControlProtocol (Session& session)
        , _gui (0)
        , _zoom_mode (false)
        , _scrub_mode (false)
-       , _flip_mode (false)
+       , _flip_mode (Normal)
        , _view_mode (Mixer)
        , _current_selected_track (-1)
        , _modifier_state (0)
@@ -393,7 +392,9 @@ MackieControlProtocol::set_active (bool yn)
                
                BaseUI::run ();
                
-               create_surfaces ();
+               if (create_surfaces ()) {
+                       return -1;
+               }
                connect_session_signals ();
                _active = true;
                update_surfaces ();
@@ -606,7 +607,7 @@ MackieControlProtocol::set_profile (const string& profile_name)
        _device_profile = d->second;
 }      
 
-void
+int
 MackieControlProtocol::set_device (const string& device_name, bool allow_activation)
 {
        map<string,DeviceInfo>::iterator d = DeviceInfo::device_info.find (device_name);
@@ -615,7 +616,7 @@ MackieControlProtocol::set_device (const string& device_name, bool allow_activat
                                                           device_name, allow_activation));
 
        if (d == DeviceInfo::device_info.end()) {
-               return;
+               return -1;
        }
        
        if (_active) {
@@ -629,13 +630,16 @@ MackieControlProtocol::set_device (const string& device_name, bool allow_activat
                set_active (true);
        } else {
                if (_active) {
-                       create_surfaces ();
+                       if (create_surfaces ()) {
+                               return -1;
+                       }
                        switch_banks (0, true);
                }
        }
+       return 0;
 }
 
-void 
+int
 MackieControlProtocol::create_surfaces ()
 {
        string device_name;
@@ -652,7 +656,13 @@ MackieControlProtocol::create_surfaces ()
 
        for (uint32_t n = 0; n < 1 + _device_info.extenders(); ++n) {
 
-               boost::shared_ptr<Surface> surface (new Surface (*this, device_name, n, stype));
+               boost::shared_ptr<Surface> surface;
+
+               try {
+                       surface.reset (new Surface (*this, device_name, n, stype));
+               } catch (...) {
+                       return -1;
+               }
 
                {
                        Glib::Threads::Mutex::Lock lm (surfaces_lock);
@@ -698,6 +708,8 @@ MackieControlProtocol::create_surfaces ()
                        g_source_ref (psrc->gobj());
                }
        }
+
+       return 0;
 }
 
 void 
@@ -1232,7 +1244,9 @@ MackieControlProtocol::midi_input_handler (IOCondition ioc, MIDI::Port* port)
                */
 
                if (!_device_info.uses_ipmidi()) {
+#ifndef PLATFORM_WINDOWS
                        CrossThreadChannel::drain (port->selectable());
+#endif
                }
 
                DEBUG_TRACE (DEBUG::MackieControl, string_compose ("data available on %1\n", port->name()));
@@ -1271,11 +1285,11 @@ MackieControlProtocol::set_view_mode (ViewMode m)
 }
 
 void
-MackieControlProtocol::set_flip_mode (bool yn)
+MackieControlProtocol::set_flip_mode (FlipMode fm)
 {
        Glib::Threads::Mutex::Lock lm (surfaces_lock);
 
-       _flip_mode = yn;
+       _flip_mode = fm;
        
        for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
                (*s)->update_flip_mode_display ();
@@ -1369,7 +1383,7 @@ MackieControlProtocol::add_down_select_button (int surface, int strip)
 void
 MackieControlProtocol::remove_down_select_button (int surface, int strip)
 {
-       DownButtonList::iterator x = find (_down_select_buttons.begin(), _down_select_buttons.end(), (surface<<8)|(strip&0xf));
+       DownButtonList::iterator x = find (_down_select_buttons.begin(), _down_select_buttons.end(), (uint32_t) (surface<<8)|(strip&0xf));
        DEBUG_TRACE (DEBUG::MackieControl, string_compose ("removing surface %1 strip %2 from down select buttons\n", surface, strip));
        if (x != _down_select_buttons.end()) {
                _down_select_buttons.erase (x);
@@ -1573,14 +1587,17 @@ MackieControlProtocol::set_ipmidi_base (int16_t portnum)
        }
 }
 
-void
+int
 MackieControlProtocol::ipmidi_restart ()
 {
        clear_ports ();
        clear_surfaces ();
-       create_surfaces ();
+       if (create_surfaces ()) {
+               return -1;
+       }
        switch_banks (_current_initial_bank, true);
        needs_ipmidi_restart = false;
+       return 0;
 }
 
 void