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

qu #44

Merged
merged 2 commits into from
Mar 30, 2024
Merged

qu #44

Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src/Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ public static void CheckKeyboard()
}
if(key.Key == ConsoleKey.Enter){
// EDIT MENU
Action = "";
Utils.currentSongIndex = Utils.currentPlaylistSongIndex;
Play.PlaySong(Utils.songs, Utils.currentSongIndex);
} else if(Action == "DeleteCurrentSong"){
Action = "";
Play.DeleteSong(Utils.currentPlaylistSongIndex);
} else if(key.Key == ConsoleKey.F1){
Utils.queueSongs.Add(Utils.songs[Utils.currentPlaylistSongIndex]);
}
}

Expand Down
16 changes: 13 additions & 3 deletions src/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,19 @@ public static void ResetMusic()
}
public static void NextSong()
{
Utils.currentSongIndex = (Utils.currentSongIndex + 1) % Utils.songs.Length;
PlayDrawReset();
PlaySong(Utils.songs, Utils.currentSongIndex);
if(Utils.queueSongs.Count > 0){
PlayDrawReset();
PlaySong(Utils.queueSongs.ToArray(), 0);
PlaySong();
int index = Array.IndexOf(Utils.songs, Utils.queueSongs[0]);
Utils.previousSongIndex = Utils.currentSongIndex;
Utils.currentSongIndex = index;
Utils.queueSongs.RemoveAt(0);
} else {
Utils.currentSongIndex = (Utils.currentSongIndex + 1) % Utils.songs.Length;
PlayDrawReset();
PlaySong(Utils.songs, Utils.currentSongIndex);
}
}

public static void PlayDrawReset() // play, draw, reset lastSeconds
Expand Down
18 changes: 16 additions & 2 deletions src/TUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ static public string[] GetAllSongs() {



return results.ToArray();
}
static string[] GetAllSongsQueue() {
int maximum = 10;
List<string> results = new();
for (int i = 0; i < Utils.queueSongs.Count; i++) {
if (results.Count != maximum) {
results.Add(Utils.queueSongs[i]);
}
}
return results.ToArray();
}

Expand Down Expand Up @@ -417,12 +427,16 @@ static public void UIComponent_Controls(Table table) {
}

static public void UIComponent_Songs(Table table) {
// AnsiConsole.Clear();
if (Utils.currentPlaylist == "") {
// Print lines
table.AddColumn("");
// TODO ADD LOCALE
table.AddColumn("Current playlist");
table.AddColumn("Current queue");
string[] lines = GetAllSongs();
string[] queueLines = GetAllSongsQueue();
for(int i = 0; i < lines.Length; i++){
table.AddRow($"{lines[i]}");
table.AddRow(lines[i], queueLines.Length > i ? queueLines[i] : "");
}
} else {
table.AddColumn($"{Locale.Player.Playlist} [cyan]" + Utils.currentPlaylist + "[/]");
Expand Down
2 changes: 2 additions & 0 deletions src/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ public struct Utils
{
public static int currentMusic { get; set; }
public static string[] songs = { "" };
public static List<string> queueSongs = new List<string>();
public static string currentSong = ""; // current path to song
public static double currentMusicLength = 0; // length in seconds
public static double MusicTimePlayed = 0; // time played in seconds
public static double preciseTime = 0;
public static int currentSongIndex = 0;
public static int previousSongIndex = 0;
public static int currentPlaylistSongIndex = 0;
public static string scSongPattern = @"^(https?:\/\/)?(www\.)?(soundcloud\.com|snd\.sc)\/(.*)$";
public static string scPlaylistPattern = @"^https?:\/\/(?:www\.)?soundcloud\.com\/[^\/]+\/sets\/[^\/]+$";
Expand Down