Skip to content

Commit

Permalink
add - doc - Added lyric seeking to the player
Browse files Browse the repository at this point in the history
---

We've added lyric seeking.

---

Type: add
Breaking: False
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed May 30, 2024
1 parent 8a1c3cf commit f0187d8
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
18 changes: 18 additions & 0 deletions BassBoom.Basolia/Lyrics/Lyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public LyricLine[] GetLinesCurrent()
return GetLinesToSpan(currentSpan);
}

/// <summary>
/// Gets all the lines from the current music duration to the end
/// </summary>
/// <returns>Array of lyric lines from the current music duration to the end</returns>
public LyricLine[] GetLinesUpcoming()
{
var currentSpan = PlaybackPositioningTools.GetCurrentDurationSpan();
return GetLinesFromSpan(currentSpan);
}

/// <summary>
/// Gets the last lyric line from the current music duration
/// </summary>
Expand Down Expand Up @@ -76,6 +86,14 @@ public List<LyricLineWord> GetLastLineWordsCurrent()
public LyricLine[] GetLinesToSpan(TimeSpan span) =>
Lines.Where((line) => line.LineSpan <= span).ToArray();

/// <summary>
/// Gets all the lines from the current span to the end
/// </summary>
/// <param name="span">Time span in which it usually represents the current music duration</param>
/// <returns>Array of lyric lines from the current span to the end</returns>
public LyricLine[] GetLinesFromSpan(TimeSpan span) =>
Lines.Where((line) => line.LineSpan > span).ToArray();

/// <summary>
/// Gets the last lyric line from the given time span
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions BassBoom.Basolia/Playback/PlaybackPositioningTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using BassBoom.Native.Runtime;
using System;
using System.Threading;
using BassBoom.Basolia.Lyrics;

namespace BassBoom.Basolia.Playback
{
Expand Down Expand Up @@ -143,6 +144,23 @@ public static void SeekToFrame(int frame)
}
}

public static void SeekLyric(LyricLine lyricLine)

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / Make API Reference

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / Make API Reference

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'

Check warning on line 147 in BassBoom.Basolia/Playback/PlaybackPositioningTools.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing XML comment for publicly visible type or member 'PlaybackPositioningTools.SeekLyric(LyricLine)'
{
lock (PositionLock)
{
InitBasolia.CheckInited();

// Check to see if the file is open
if (!FileTools.IsOpened)
throw new BasoliaException("Can't seek a file that's not open", mpg123_errors.MPG123_BAD_FILE);

// Get the length, convert it to frames, and seek
var length = lyricLine.LineSpan.TotalSeconds;
int frame = (int)(length * FormatTools.GetFormatInfo().rate);
SeekToFrame(frame);
}
}

/// <summary>
/// Drops all MPEG frames to the device
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions BassBoom.Cli/CliBase/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ [N] Next song
[R] Remove current song
[CTRL] + [R] Remove all songs
[S] (when playing) Selectively seek
[F] (when playing) Seek to previous lyric
[G] (when playing) Seek to next lyric
[J] (when playing) Seek to current lyric
[K] (when playing) Seek to which lyric
[E] Opens the equalizer
[D] (when playing) Device and driver info
[Z] System info
Expand Down
13 changes: 13 additions & 0 deletions BassBoom.Cli/CliBase/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,19 @@ private static void HandleKeypressPlayMode(ConsoleKeyInfo keystroke, Screen play
playerThread = new(HandlePlay);
PlayerControls.Play();
break;
case ConsoleKey.F:
PlayerControls.SeekPreviousLyric();
break;
case ConsoleKey.G:
PlayerControls.SeekNextLyric();
break;
case ConsoleKey.J:
PlayerControls.SeekCurrentLyric();
break;
case ConsoleKey.K:
PlayerControls.SeekWhichLyric();
playerScreen.RequireRefresh();
break;
case ConsoleKey.N:
PlayerControls.Stop(false);
PlayerControls.SeekBeginning();
Expand Down
66 changes: 66 additions & 0 deletions BassBoom.Cli/CliBase/PlayerControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using Terminaux.Base;
using Terminaux.Base.Buffered;
using Terminaux.Colors.Data;
using Terminaux.Inputs;
using Terminaux.Inputs.Styles.Infobox;
using Terminaux.Writer.ConsoleWriters;
using Terminaux.Writer.FancyWriters;
Expand Down Expand Up @@ -75,6 +76,71 @@ internal static void SeekBeginning()
Player.position = 0;
}

internal static void SeekPreviousLyric()
{
// In case we have no songs in the playlist, or we have no lyrics...
if (Common.cachedInfos.Count == 0)
return;
if (Common.CurrentCachedInfo.LyricInstance is null)
return;

var lyrics = Common.CurrentCachedInfo.LyricInstance.GetLinesCurrent();
if (lyrics.Length == 0)
return;
var lyric = lyrics.Length == 1 ? lyrics[0] : lyrics[lyrics.Length - 2];
PlaybackPositioningTools.SeekLyric(lyric);
}

internal static void SeekCurrentLyric()
{
// In case we have no songs in the playlist, or we have no lyrics...
if (Common.cachedInfos.Count == 0)
return;
if (Common.CurrentCachedInfo.LyricInstance is null)
return;

var lyrics = Common.CurrentCachedInfo.LyricInstance.GetLinesCurrent();
if (lyrics.Length == 0)
return;
var lyric = lyrics[lyrics.Length - 1];
PlaybackPositioningTools.SeekLyric(lyric);
}

internal static void SeekNextLyric()
{
// In case we have no songs in the playlist, or we have no lyrics...
if (Common.cachedInfos.Count == 0)
return;
if (Common.CurrentCachedInfo.LyricInstance is null)
return;

var lyrics = Common.CurrentCachedInfo.LyricInstance.GetLinesUpcoming();
if (lyrics.Length == 0)
{
SeekCurrentLyric();
return;
}
var lyric = lyrics[0];
PlaybackPositioningTools.SeekLyric(lyric);
}

internal static void SeekWhichLyric()
{
// In case we have no songs in the playlist, or we have no lyrics...
if (Common.cachedInfos.Count == 0)
return;
if (Common.CurrentCachedInfo.LyricInstance is null)
return;

var lyrics = Common.CurrentCachedInfo.LyricInstance.Lines;
var choices = lyrics.Select((line) => new InputChoiceInfo($"{line.LineSpan}", line.Line)).ToArray();
int index = InfoBoxSelectionColor.WriteInfoBoxSelection(choices, "Select a lyric to seek to");
if (index == -1)
return;
var lyric = lyrics[index];
PlaybackPositioningTools.SeekLyric(lyric);
}

internal static void Play()
{
// In case we have no songs in the playlist...
Expand Down

0 comments on commit f0187d8

Please sign in to comment.