X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fsurfaces%2Fmackie%2Fpot.cc;h=3ac991116f2153aa19982d1c8ecd5232015dca99;hb=0c448c387bf4fc11c1bc2494055303ed12a15208;hp=3b8e8b65a5de4180fa61ea30f2efea75a497fb24;hpb=337b420266cc1a3dd476f9997caeb107407dd86c;p=ardour.git diff --git a/libs/surfaces/mackie/pot.cc b/libs/surfaces/mackie/pot.cc index 3b8e8b65a5..3ac991116f 100644 --- a/libs/surfaces/mackie/pot.cc +++ b/libs/surfaces/mackie/pot.cc @@ -22,8 +22,12 @@ #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 */ +int const Pot::ID = 0x10; /* base value for v-pot IDs */ + Control* Pot::factory (Surface& surface, int id, const char* name, Group& group) { @@ -35,53 +39,38 @@ Pot::factory (Surface& surface, int id, const char* name, Group& group) } MidiByteArray -Pot::set_mode (Pot::Mode m) -{ - mode = m; - return update_message (); -} - -MidiByteArray -Pot::set_onoff (bool onoff) -{ - on = onoff; - return update_message (); -} - -MidiByteArray -Pot::set_value (float normalized) -{ - value = normalized; - return update_message (); -} - -MidiByteArray -Pot::set_all (float val, bool onoff, Mode m) -{ - value = val; - on = onoff; - mode = m; - return update_message (); -} - -MidiByteArray -Pot::update_message () +Pot::set (float val, bool onoff, Mode mode) { // TODO do an exact calc for 0.50? To allow manually re-centering the port. - // center on or off - MIDI::byte msg = (value > 0.45 && value < 0.55 ? 1 : 0) << 6; - - // mode + // 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); - - // value, but only if off hasn't explicitly been set - if (on) { - msg += (lrintf (value * 10.0) + 1) & 0x0f; // 0b00001111 + /* + * 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)) & 0x0f; // 0b00001111 + } else { + msg |= (lrintf (val * 10.0) + 1) & 0x0f; // 0b00001111 + } } - return MidiByteArray (3, 0xb0, id(), msg); + /* outbound LED message requires 0x20 to be added to the LED's id + */ + + return MidiByteArray (3, 0xb0, 0x20 + id(), msg); } - +