#include "surface.h"
#include "control_group.h"
+using namespace ArdourSurface;
using namespace Mackie;
int const Pot::External = 0x2e; /* specific ID for "vpot" representing external control */
{
// TODO do an exact calc for 0.50? To allow manually re-centering the port.
- // center on or off
- MIDI::byte msg = (val > 0.45 && val < 0.55 ? 1 : 0) << 6;
-
- // mode
- msg |= (onoff << 4);
-
- // val, but only if off hasn't explicitly been set
+ // center on if val is "very close" to 0.50
+ MIDI::byte msg = (val > 0.48 && val < 0.58 ? 1 : 0) << 6;
+
+ // Pot/LED mode
+ msg |= (mode << 4);
- if (onoff) {
+ /*
+ * Even though a width value may be negative, there is
+ * technically still width there, it is just reversed,
+ * so make sure to show it on the LED ring appropriately.
+ */
+ if (val < 0){
+ val = val * -1;
+ }
+
+ // val, but only if off hasn't explicitly been set
+ if (onoff) {
if (mode == spread) {
- msg += (lrintf (val * 6) + 1) & 0x0f; // 0b00001111
+ msg |= (lrintf (val * 6)) & 0x0f; // 0b00001111
} else {
- msg += (lrintf (val * 10.0) + 1) & 0x0f; // 0b00001111
+ msg |= (lrintf (val * 10.0) + 1) & 0x0f; // 0b00001111
}
}
return MidiByteArray (3, 0xb0, 0x20 + id(), msg);
}
-
+