Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <cmath>
+
+#include "pbd/compose.h"
+
+#include "ardour/debug.h"
+
#include "fader.h"
#include "surface.h"
#include "control_group.h"
+#include "mackie_control_protocol.h"
+using namespace ArdourSurface;
using namespace Mackie;
+using namespace PBD;
Control*
-Fader::factory (Surface& surface, int id, int ordinal, const char* name, Group& group)
+Fader::factory (Surface& surface, int id, const char* name, Group& group)
{
- Fader* f = new Fader (id, ordinal, name, group);
-
- std::cerr << "Registering fader " << id << " ord " << ordinal << std::endl;
+ Fader* f = new Fader (id, name, group);
surface.faders[id] = f;
surface.controls.push_back (f);
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 (16384.0 * position);
+
+ if (posi == last_update_position) {
+ return MidiByteArray();
+ }
+
+ last_update_position = posi;
+
+ DEBUG_TRACE (DEBUG::MackieControl, string_compose ("generate fader message for position %1 (%2)\n", position, posi));
+ return MidiByteArray (3, 0xe0 + id(), posi & 0x7f, posi >> 7);
+}