put all of the Mackie control surface code into the ArdourSurface namespace
[ardour.git] / libs / surfaces / mackie / fader.cc
index 80928d85ebc6c2b1625868e6813e82a6d72e75a5..cc43bf3387e3062cda1690215f1e220d8a7dca47 100644 (file)
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include <cmath>
+
 #include "fader.h"
 #include "surface.h"
 #include "control_group.h"
+#include "mackie_control_protocol.h"
 
+using namespace ArdourSurface;
 using namespace Mackie;
 
 Control*
@@ -34,3 +38,22 @@ Fader::factory (Surface& surface, int id, const char* name, Group& group)
        return f;
 }
 
+MidiByteArray
+Fader::set_position (float normalized)
+{
+       position = normalized;
+       return update_message ();
+}
+
+MidiByteArray
+Fader::update_message ()
+{
+       MackieControlProtocol* mcp = MackieControlProtocol::instance ();
+       if (mcp && mcp->flip_mode() == MackieControlProtocol::Zero) {
+               /* do not send messages to move the faders when in this mode */
+               return MidiByteArray();
+       }
+
+       int posi = lrintf (0x3fff * position);
+       return MidiByteArray  (3, 0xe0 + id(), posi & 0x7f, posi >> 7);
+}