Skip to content

Commit

Permalink
Add keyboard seeking with arrow keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
VPKSoft committed Feb 27, 2023
1 parent 4f7b7e8 commit 36dbd1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion amp.EtoForms/FormMain.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private async void FormMain_KeyDown(object? sender, KeyEventArgs e)
{
if (e.Key is Keys.Up or Keys.Down or Keys.PageDown or Keys.PageUp or Keys.Equal or
Keys.F1 or Keys.F2 or Keys.F3 or Keys.F4 or Keys.F5 or Keys.F6 or Keys.F7 or Keys.F8 or Keys.F9 or
Keys.Escape or Keys.Enter or Keys.Add or Keys.Multiply)
Keys.Escape or Keys.Enter or Keys.Add or Keys.Multiply or Keys.Left or Keys.Right)
{
if (gvAudioTracks.SelectedItem == null && gvAudioTracks.DataStore.Any())
{
Expand Down Expand Up @@ -184,6 +184,11 @@ await playbackOrder.MoveToQueueTopOrBottom(tracks, shift, e.Key == Keys.PageUp,
return;
}

if (e.Key is Keys.Right or Keys.Left)
{
playbackManager.SeekSeconds(e.Key == Keys.Right ? 5 : -5);
}

if (e.Modifiers == Keys.None)
{
if (e.IsChar && !(e.Key is Keys.Up or Keys.Down or Keys.PageDown or Keys.PageUp))
Expand Down
19 changes: 19 additions & 0 deletions amp.Playback/PlaybackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,25 @@ public double PlaybackPositionPercentage
set => PlaybackPosition = value == 0 ? 0 : PlaybackLength * value / 100;
}

/// <summary>
/// Seeks the <see cref="PlaybackPosition"/> with the specified amount of seconds.
/// </summary>
/// <param name="value">The value in seconds to seek.</param>
public void SeekSeconds(int value)
{
var newPosition = PlaybackPosition + value;
if (newPosition < 0)
{
PlaybackPosition = 0;
return;
}

if (newPosition >= 0 && newPosition < PlaybackLength)
{
PlaybackPosition = newPosition;
}
}

/// <summary>
/// Gets or sets the playback position in seconds.
/// </summary>
Expand Down

0 comments on commit 36dbd1a

Please sign in to comment.