From d7832fcc2153e3d086c3bfabffb7fe2eef8d946e Mon Sep 17 00:00:00 2001 From: GalaxyMaster2 <10052298+GalaxyMaster2@users.noreply.github.com> Date: Mon, 29 Nov 2021 02:55:46 +0100 Subject: [PATCH 1/4] initial attempt at improving scrolling on trackpads --- .../MapEditor/AudioTimeSyncController.cs | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs b/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs index 30df46b21..e8819dfba 100644 --- a/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs +++ b/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs @@ -28,6 +28,14 @@ public class AudioTimeSyncController : MonoBehaviour, CMInput.IPlaybackActions, private int gridMeasureSnapping = 1; private float audioLatencyCompensationSeconds; + private float internalScrollStepCounter = 0; + private Coroutine resetScrollCounterCoroutine; +#if UNITY_STANDALONE_WIN + private const float scrollSizeDivisor = 120; +#else + private const float scrollSizeDivisor = 1; +#endif + private AudioClip clip; private bool controlSnap; @@ -209,14 +217,31 @@ public void OnChangeTimeandPrecision(InputAction.CallbackContext context) else { if (Settings.Instance.InvertScrollTime) value *= -1; - // +1 beat if we're going forward, -1 beat if we're going backwards - var beatShiftRaw = 1f / GridMeasureSnapping * (value > 0 ? 1f : -1f); - MoveToTimeInBeats(CurrentBeat + bpmChangesContainer.LocalBeatsToSongBeats(beatShiftRaw, CurrentBeat)); + var scrollSize = value / scrollSizeDivisor; + internalScrollStepCounter += scrollSize; + if (Mathf.Abs(internalScrollStepCounter) >= 0.5f) + { + // +1 beat if we're going forward, -1 beat if we're going backwards + var direction = value > 0 ? 1f : -1f; + var beatShiftRaw = 1f / GridMeasureSnapping * direction; + MoveToTimeInBeats(CurrentBeat + bpmChangesContainer.LocalBeatsToSongBeats(beatShiftRaw, CurrentBeat)); + internalScrollStepCounter -= direction; + } + + if (resetScrollCounterCoroutine != null) StopCoroutine(resetScrollCounterCoroutine); + resetScrollCounterCoroutine = StartCoroutine(ResetInternalScrollStepCounter()); } } } + private IEnumerator ResetInternalScrollStepCounter() + { + yield return new WaitForSecondsRealtime(0.5f); + internalScrollStepCounter = 0; + resetScrollCounterCoroutine = null; + } + public void OnChangePrecisionModifier(InputAction.CallbackContext context) => controlSnap = context.performed; public void OnPreciseSnapModification(InputAction.CallbackContext context) => From 6cf3fb3e04faa4180246ffcaafbc4f1d723e3f97 Mon Sep 17 00:00:00 2001 From: GalaxyMaster2 <10052298+GalaxyMaster2@users.noreply.github.com> Date: Mon, 29 Nov 2021 04:19:05 +0100 Subject: [PATCH 2/4] account for large scroll sizes properly --- .../__Scripts/MapEditor/AudioTimeSyncController.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs b/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs index e8819dfba..72d122ccd 100644 --- a/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs +++ b/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs @@ -220,15 +220,18 @@ public void OnChangeTimeandPrecision(InputAction.CallbackContext context) var scrollSize = value / scrollSizeDivisor; internalScrollStepCounter += scrollSize; - if (Mathf.Abs(internalScrollStepCounter) >= 0.5f) + + // +1 beat if we're going forward, -1 beat if we're going backwards + var direction = Mathf.Sign(internalScrollStepCounter); + var beatShiftRaw = 0f; + while (Mathf.Abs(internalScrollStepCounter) >= 0.5f) { - // +1 beat if we're going forward, -1 beat if we're going backwards - var direction = value > 0 ? 1f : -1f; - var beatShiftRaw = 1f / GridMeasureSnapping * direction; - MoveToTimeInBeats(CurrentBeat + bpmChangesContainer.LocalBeatsToSongBeats(beatShiftRaw, CurrentBeat)); + beatShiftRaw += 1f / GridMeasureSnapping * direction; internalScrollStepCounter -= direction; } + MoveToTimeInBeats(CurrentBeat + bpmChangesContainer.LocalBeatsToSongBeats(beatShiftRaw, CurrentBeat)); + if (resetScrollCounterCoroutine != null) StopCoroutine(resetScrollCounterCoroutine); resetScrollCounterCoroutine = StartCoroutine(ResetInternalScrollStepCounter()); } From 4eb881402747b54edb82a38e42a8e4fc7d36336e Mon Sep 17 00:00:00 2001 From: GalaxyMaster2 <10052298+GalaxyMaster2@users.noreply.github.com> Date: Mon, 29 Nov 2021 12:55:29 +0100 Subject: [PATCH 3/4] fix potential infinite loop --- Assets/__Scripts/MapEditor/AudioTimeSyncController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs b/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs index 72d122ccd..317872c21 100644 --- a/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs +++ b/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs @@ -224,7 +224,7 @@ public void OnChangeTimeandPrecision(InputAction.CallbackContext context) // +1 beat if we're going forward, -1 beat if we're going backwards var direction = Mathf.Sign(internalScrollStepCounter); var beatShiftRaw = 0f; - while (Mathf.Abs(internalScrollStepCounter) >= 0.5f) + while ((internalScrollStepCounter * direction) > 0.5f) { beatShiftRaw += 1f / GridMeasureSnapping * direction; internalScrollStepCounter -= direction; From 90fe8c8ec88a48d5065021625f2e791e72b95a95 Mon Sep 17 00:00:00 2001 From: GalaxyMaster2 <10052298+GalaxyMaster2@users.noreply.github.com> Date: Fri, 3 Dec 2021 19:33:43 +0100 Subject: [PATCH 4/4] update scrollSizeDivisor for macOS --- Assets/__Scripts/MapEditor/AudioTimeSyncController.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs b/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs index 317872c21..1b61f5619 100644 --- a/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs +++ b/Assets/__Scripts/MapEditor/AudioTimeSyncController.cs @@ -32,6 +32,9 @@ public class AudioTimeSyncController : MonoBehaviour, CMInput.IPlaybackActions, private Coroutine resetScrollCounterCoroutine; #if UNITY_STANDALONE_WIN private const float scrollSizeDivisor = 120; +#elif UNITY_STANDALONE_OSX + // A bit weird but this seems to be the base scroll value regardless of scroll speed system setting + private const float scrollSizeDivisor = 2.000122; #else private const float scrollSizeDivisor = 1; #endif