Skip to content

Commit

Permalink
Fix inverted yellow/green velocity on XInput 4-lane drumkits
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNathannator committed Nov 15, 2023
1 parent ba14fcd commit 26f7259
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions Packages/com.thenathannator.plasticband/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Dates are relative to UTC.
- Fixed Pro Keyboard `GetKeyMask` returning an inverted mask (i.e. bit 24 was key 1 rather than bit 0).
- Fixed Santroller guitars not having the correct default state value set.
- Fixed various input control extensions not working on devices that use the new state translation infrastructure.
- Fixed yellow/green pad/cymbal velocities on XInput 4-lane drumkits being inverted.

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,51 +118,57 @@ public bool dpadRight

byte IFourLaneDrumkitState_Flags.redPadVelocity
{
get => GetVelocity(redVelocity);
set => SetVelocity(ref redVelocity, value);
get => GetVelocity_Positive(redVelocity);
set => SetVelocity_Positive(ref redVelocity, value);
}

byte IFourLaneDrumkitState_Flags.yellowPadVelocity
{
get => GetVelocity(yellowVelocity);
set => SetVelocity(ref yellowVelocity, value);
get => GetVelocity_Negative(yellowVelocity);
set => SetVelocity_Negative(ref yellowVelocity, value);
}

byte IFourLaneDrumkitState_Flags.bluePadVelocity
{
get => GetVelocity(blueVelocity);
set => SetVelocity(ref blueVelocity, value);
get => GetVelocity_Positive(blueVelocity);
set => SetVelocity_Positive(ref blueVelocity, value);
}

byte IFourLaneDrumkitState_Flags.greenPadVelocity
{
get => GetVelocity(greenVelocity);
set => SetVelocity(ref greenVelocity, value);
get => GetVelocity_Negative(greenVelocity);
set => SetVelocity_Negative(ref greenVelocity, value);
}

byte IFourLaneDrumkitState_Flags.yellowCymbalVelocity
{
get => GetVelocity(yellowVelocity);
set => SetVelocity(ref yellowVelocity, value);
get => GetVelocity_Negative(yellowVelocity);
set => SetVelocity_Negative(ref yellowVelocity, value);
}

byte IFourLaneDrumkitState_Flags.blueCymbalVelocity
{
get => GetVelocity(blueVelocity);
set => SetVelocity(ref blueVelocity, value);
get => GetVelocity_Positive(blueVelocity);
set => SetVelocity_Positive(ref blueVelocity, value);
}

byte IFourLaneDrumkitState_Flags.greenCymbalVelocity
{
get => GetVelocity(greenVelocity);
set => SetVelocity(ref greenVelocity, value);
get => GetVelocity_Negative(greenVelocity);
set => SetVelocity_Negative(ref greenVelocity, value);
}

private static byte GetVelocity(short velocity)
private static byte GetVelocity_Positive(short velocity)
=> (byte)((~velocity & 0x7FFF) >> 7);

private static void SetVelocity(ref short velocity, byte value)
private static byte GetVelocity_Negative(short velocity)
=> (byte)((velocity & 0x7FFF) >> 7);

private static void SetVelocity_Positive(ref short velocity, byte value)
=> velocity = (short)(~value << 7);

private static void SetVelocity_Negative(ref short velocity, byte value)
=> velocity = (short)(value << 7);
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
Expand Down

0 comments on commit 26f7259

Please sign in to comment.