do not crash if an unknown action is used by Mackie Control support
[ardour.git] / libs / surfaces / mackie / button.cc
index c9ae1f5d717f2f4a3192456e0b728acd8a79780f..ecb3f22b8b4653e15403f1a971f46382a5a95125 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <glib.h>
 
+#include "ardour/ardour.h"
+
 #include "button.h"
 #include "surface.h"
 #include "control_group.h"
@@ -29,7 +31,7 @@ using namespace Mackie;
 Control*
 Button::factory (Surface& surface, Button::ID bid, int id, const std::string& name, Group& group)
 {
-       Button* b = new Button (bid, id, name, group);
+       Button* b = new Button (surface, bid, id, name, group);
        /* store button with the device-specific ID */
        surface.buttons[id] = b;
        surface.controls.push_back (b);
@@ -37,6 +39,35 @@ Button::factory (Surface& surface, Button::ID bid, int id, const std::string& na
        return b;
 }
 
+void
+Button::pressed ()
+{
+       press_time = ARDOUR::get_microseconds ();
+}
+
+void
+Button::released ()
+{
+       press_time = 0;
+}
+
+int32_t
+Button::long_press_count ()
+{
+       if (press_time == 0) {
+               return -1; /* button is not pressed */
+       }
+
+       const ARDOUR::microseconds_t delta = ARDOUR::get_microseconds () - press_time;
+
+       if (delta < 500000) {
+               return 0;
+       } else if (delta < 1000000) {
+               return 1;
+       }
+
+       return 2;
+}
 int
 Button::name_to_id (const std::string& name)
 {
@@ -70,6 +101,8 @@ Button::name_to_id (const std::string& name)
        if (!g_ascii_strcasecmp (name.c_str(), "Busses")) { return Busses; }
        if (!g_ascii_strcasecmp (name.c_str(), "Outputs")) { return Outputs; }
        if (!g_ascii_strcasecmp (name.c_str(), "User")) { return User; }
+       if (!g_ascii_strcasecmp (name.c_str(), "UserA")) { return UserA; }
+       if (!g_ascii_strcasecmp (name.c_str(), "UserB")) { return UserB; }
        if (!g_ascii_strcasecmp (name.c_str(), "Shift")) { return Shift; }
        if (!g_ascii_strcasecmp (name.c_str(), "Option")) { return Option; }
        if (!g_ascii_strcasecmp (name.c_str(), "Ctrl")) { return Ctrl; }
@@ -104,9 +137,9 @@ Button::name_to_id (const std::string& name)
        if (!g_ascii_strcasecmp (name.c_str(), "Scrub")) { return Scrub; }
        if (!g_ascii_strcasecmp (name.c_str(), "User A")) { return UserA; }
        if (!g_ascii_strcasecmp (name.c_str(), "User B")) { return UserB; }
-               
+
                /* Strip buttons */
-               
+
        if (!g_ascii_strcasecmp (name.c_str(), "Record Enable")) { return RecEnable; }
        if (!g_ascii_strcasecmp (name.c_str(), "Solo")) { return Solo; }
        if (!g_ascii_strcasecmp (name.c_str(), "Mute")) { return Mute; }