Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix high precision mousewheel shortcuts in multiple actions on REAPER v6.76+ #1843

Merged
merged 1 commit into from
Feb 13, 2024

Conversation

cfillion
Copy link
Collaborator

@cfillion cfillion commented Feb 11, 2024

#1787 (comment)

v6.76 - February 28 2023

  • Mouse: improve precision of mouse gestures and mousewheel when bound to actions

The current SDK does not specify negative values other than -1:

val/val2 are used for actions triggered by MIDI/OSC/mousewheel
   - val = [0..127] and val2 = -1 for MIDI CC,
   - val2 >=0 for MIDI pitch or OSC with value = (val2|(val<<7))/16383.0
   - relmode absolute(0) or 1/2/3 for relative adjust modes
v5.99 & v6.75
mwdown val=63 val2=-1 relmode=2
mwup   val=65 val2=-1 relmode=2

v6.76 & v7.11 (typical, macOS)
mwdown val=127 val2=-161 relmode=1
mwup   val=1   val2=-161 relmode=1

REAPER v7.11 computes val2 (valhw in SWS) from WM_MOUSEWHEEL's delta in wParam the following way:

int MWDeltaToVal2(double delta)
{
#ifdef __APPLE__
  delta /= 16;
#elifdef _WIN32
  delta /= 8;
#endif
  delta = std::abs(delta);
  delta = std::ceil(delta) - delta;
  delta = delta * 256 + 0.5;
  return -1 - delta;
}

(On Linux, WM_MOUSEWHEEL with delta other than +-120 appear to be ignored.)

It then uses it like this in actions (validating that this PR is the correct approach for those values):

double AdjustRelative(const int relmode, int val, const int val2)
{
  switch(relmode) {
  case 1:
    if(val >= 0x40)
      val |= ~0x3f;
    break;
  case 2:
    val -= 0x40;
    break;
  case 3:
    if(val & 0x40)
      val = -(val & 0x3f);
    break;
  default:
    return val;
  }

  if(val == 0 || val2 >= -1)
    return val;

  const double fraction = static_cast<double>(-1 - val2) / 256.0;
  return val >= 0 ? val - fraction : val + fraction;
}

The following actions are affected by this commit (although most of them do not officially support the mousewheel):

  • SWS/BR: Adjust playrate
  • SWS/S&M: Live Config #n - Apply config
  • SWS/S&M: Live Config #n - Preload config
  • SWS/S&M: Select project
  • SWS/S&M: Trigger preset for FX n of selected track
  • SWS/S&M: Trigger preset for selected FX of selected track
  • SWS/wol: Adjust envelope or track height under mouse cursor
  • SWS/wol: Adjust selected envelope height
  • SWS/wol: Adjust selected envelope or last touched track height

… v6.76+

> v6.76 - February 28 2023
> - Mouse: improve precision of mouse gestures and mousewheel when bound to actions

v5.99 & v6.75
mwdown val=63 val2=-1 relmode=2
mwup   val=65 val2=-1 relmode=2

v6.76 & v7.11 (typical)
mwdown val=127 val2=-161 relmode=1
mwup   val=1   val2=-161 relmode=1

REAPER v6.76+ encodes val2 (valhw in SWS) from `WM_MOUSEWHEEL`'s delta in `wParam` the following way:

    int MWDeltaToVal2(double delta)
    {
    #ifdef __APPLE__
      delta /= 16;
    #elifdef _WIN32
      delta /= 8;
    #endif
      delta = std::abs(delta);
      delta = std::ceil(delta) - delta;
      delta = delta * 256 + 0.5;
      return -1 - delta;
    }

(On Linux, WM_MOUSEWHEEL with delta other than +-120 appear to be ignored.)

It then uses it like this:

    double AdjustRelative(const int relmode, int val, const int val2)
    {
      switch(relmode) {
      case 1:
        if(val >= 0x40)
          val |= ~0x3f;
        break;
      case 2:
        val -= 0x40;
      case 3:
        if(val & 0x40)
          val = -(val & 0x3f);
      default:
        return val;
      }

      if(val == 0 || val2 >= -1)
        return val;

      const double fraction = static_cast<double>(-1 - val2) / 256.0;
      return val >= 0 ? val - fraction : val + fraction;
    }

The following actions are affected by this commit (although most of them do not officially support the mousewheel):

- SWS/BR: Adjust playrate
- SWS/S&M: Live Config #n - Apply config
- SWS/S&M: Live Config #n - Preload config
- SWS/S&M: Select project
- SWS/S&M: Trigger preset for FX n of selected track
- SWS/S&M: Trigger preset for selected FX of selected track
- SWS/wol: Adjust envelope or track height under mouse cursor
- SWS/wol: Adjust selected envelope height
- SWS/wol: Adjust selected envelope or last touched track height
@cfillion cfillion merged commit 297571c into reaper-oss:master Feb 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants