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

trackpad scrolling improvements #361

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion Assets/__Scripts/MapEditor/AudioTimeSyncController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ 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;
#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

private AudioClip clip;

private bool controlSnap;
Expand Down Expand Up @@ -209,14 +220,34 @@ public void OnChangeTimeandPrecision(InputAction.CallbackContext context)
else
{
if (Settings.Instance.InvertScrollTime) value *= -1;

var scrollSize = value / scrollSizeDivisor;
internalScrollStepCounter += scrollSize;

// +1 beat if we're going forward, -1 beat if we're going backwards
var beatShiftRaw = 1f / GridMeasureSnapping * (value > 0 ? 1f : -1f);
var direction = Mathf.Sign(internalScrollStepCounter);
var beatShiftRaw = 0f;
while ((internalScrollStepCounter * direction) > 0.5f)
{
beatShiftRaw += 1f / GridMeasureSnapping * direction;
internalScrollStepCounter -= direction;
}

MoveToTimeInBeats(CurrentBeat + bpmChangesContainer.LocalBeatsToSongBeats(beatShiftRaw, CurrentBeat));

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) =>
Expand Down