Skip to content

Commit

Permalink
can now open zero songs
Browse files Browse the repository at this point in the history
  • Loading branch information
jooapa committed Dec 17, 2023
1 parent 0b8497f commit 95f82c7
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 22 deletions.
10 changes: 6 additions & 4 deletions src/Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace jammer
{
public partial class Start
{
public static string playerView = "default"; // default, all
public static string playerView = "default"; // default, all, help, settings, fake
public static void CheckKeyboard()
{
if (Console.KeyAvailable)
Expand Down Expand Up @@ -43,7 +43,6 @@ public static void CheckKeyboard()
else
//NOTE(ra) Resumed is not called at all. PlaySong resumes after pause.
{
Console.WriteLine("Resumed");
Play.ResumeSong();
}
break;
Expand Down Expand Up @@ -167,11 +166,14 @@ public static void CheckKeyboard()
}
break;
}
if (playerView != "all" && playerView != "help" && playerView != "settings")
if (playerView != "all" && playerView != "help" && playerView != "settings" && playerView != "fake")
{
AnsiConsole.Clear();
}
TUI.DrawPlayer();
if (playerView != "fake")
{
TUI.DrawPlayer();
}
Preferences.SaveSettings();
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public static void PlaySong(string[] songs, int Currentindex)
{
if (Currentindex < 0 || Currentindex >= songs.Length)
{
Console.WriteLine("Index out of range");
Start.playerView = "fake";
Start.FakeLoop();
return;
}
Debug.dprint("Play song");
Expand Down Expand Up @@ -99,11 +100,19 @@ public static void PauseSong()

public static void ResumeSong()
{
if (Utils.songs.Length == 0)
{
return;
}
Utils.currentMusic.Play();
}

public static void PlaySong()
{
if (Utils.songs.Length == 0)
{
return;
}
// Utils.currentMusic.Stop();
Utils.currentMusic.Play();
}
Expand Down Expand Up @@ -242,6 +251,7 @@ public static void MaybeNextSong()
if (Preferences.isLoop && Utils.audioStream != null)
{
Utils.audioStream.Position = 0;
Start.state = MainStates.playing;
// Start.lastSeconds = -1;
}
else if (Utils.songs.Length == 1 && !Preferences.isLoop && Utils.audioStream != null){
Expand Down
38 changes: 31 additions & 7 deletions src/Start.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public static void Run(string[] args)
// Turns relative paths into absolute paths, and adds https:// to urls
Utils.songs = Absolute.Correctify(Utils.songs);
// if no args, ask for input
if (Utils.songs.Length == 0) {
AnsiConsole.MarkupLine("[red]No arguments given, please enter a URL or file path.[/] Type -help for help");
Utils.songs = new string[1];
Utils.songs[0] = AnsiConsole.Ask<string>("Enter URL or file path: ");
}
// if (Utils.songs.Length == 0) {
// AnsiConsole.MarkupLine("[red]No arguments given, please enter a URL or file path.[/] Type -help for help");
// Utils.songs = new string[1];
// Utils.songs[0] = AnsiConsole.Ask<string>("Enter URL or file path: ");
// }

StartPlaying();
TUI.ClearScreen();
Expand Down Expand Up @@ -181,10 +181,10 @@ public static void Loop()

// this check is to prevent lastSeconds from being greater than the song length,
// early bug when AudioStream.position was changed to 0
if (lastSeconds + 1 >= Utils.currentMusicLength)
if (lastSeconds >= Utils.currentMusicLength)
{
lastSeconds = -1;
treshhold += 69;
treshhold += 1;
}
TUI.DrawPlayer();
}
Expand All @@ -211,5 +211,29 @@ public static void Loop()
}
}
}
public static void FakeLoop()
{
Utils.currentMusicLength = 0;
Utils.MusicTimePlayed = 0;
Utils.currentSong = "";
Utils.currentSongIndex = 0;
AnsiConsole.Clear();
TUI.DrawFakePlayer();
while (true)
{
if (consoleWidth != Console.WindowWidth || consoleHeight != Console.WindowHeight) {
consoleHeight = Console.WindowHeight;
consoleWidth = Console.WindowWidth;
TUI.ClearScreen();
TUI.DrawPlayer();
}
CheckKeyboard();
if (Utils.songs.Length != 0) {
playerView = "default";
TUI.ClearScreen();
Run(Utils.songs);
}
}
}
}
}
60 changes: 50 additions & 10 deletions src/TUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ static public void DrawPlayer() {
{
return;
}
if (Start.playerView == "fake")
{
DrawFakePlayer();
}
var table = new Table();
var controlsTable = new Table();

Expand All @@ -45,7 +49,7 @@ static public void DrawPlayer() {
AnsiConsole.Clear();
cls = false;
}
if (Start.playerView == "default") {
if (Start.playerView == "default" || Start.playerView == "fake") {
AnsiConsole.Cursor.SetPosition(0, 0);
}

Expand All @@ -63,6 +67,9 @@ static public void ClearScreen() {
}

static public string GetAllSongs() {
if (Utils.songs.Length == 0) {
return "[grey]No songs in playlist[/]";
}
string allSongs = "";
foreach (string song in Utils.songs) {
// add green color to current song, based on the index
Expand All @@ -79,23 +86,34 @@ static public string GetAllSongs() {

public static string GetPrevCurrentNextSong() {
// return previous, current and next song in playlist
string prevSong = "";
string currentSong = "";
string nextSong = "";
string prevSong;
string nextSong;
string currentSong;
if (Utils.songs.Length == 0)
{
currentSong = "[grey]current : -[/]";
}
else
{
currentSong = "[green]current : " + Utils.songs[Utils.currentSongIndex] + "[/]";
}

if (Utils.currentSongIndex > 0) {
if (Utils.currentSongIndex > 0)
{
prevSong = "[grey]previous : " + Utils.songs[Utils.currentSongIndex - 1] + "[/]";
}
else {
else
{
prevSong = "[grey]previous : -[/]";
}

currentSong = "[grey]current : [/]" + Utils.songs[Utils.currentSongIndex];

if (Utils.currentSongIndex < Utils.songs.Length - 1) {
if (Utils.currentSongIndex < Utils.songs.Length - 1)
{
nextSong = "[grey]next : " + Utils.songs[Utils.currentSongIndex + 1] + "[/]";
}
else {
else
{
nextSong = "[grey]next : -[/]";
}

Expand Down Expand Up @@ -345,6 +363,7 @@ static void PlaylistHelp() {

AnsiConsole.Write(table);
}

public static void Help() {
var table = new Table();
table.AddColumn("Commands");
Expand All @@ -361,4 +380,25 @@ public static void Help() {

PlaylistHelp();
}
}

public static void DrawFakePlayer() {
var table = new Table();
table.AddColumn("State");
table.AddColumn("Current Position");
table.AddColumn("Looping");
table.AddColumn("Suffle");
table.AddColumn("Volume");
table.AddColumn("Muted");

table.AddRow(Start.state + "", CalculateTime(Utils.MusicTimePlayed) + " / " + CalculateTime(Utils.currentMusicLength), Preferences.isLoop + "", Preferences.isShuffle + "", Math.Round(Preferences.volume * 100) + "%", Preferences.isMuted + "");
var table1 = new Table();
Comp_Normal(table1);
AnsiConsole.Cursor.SetPosition(0, 0);

AnsiConsole.Write(table1);
AnsiConsole.Write(table);
AnsiConsole.Markup("Press [red]h[/] for help");
AnsiConsole.Markup("\nPress [yellow]c[/] for settings");
AnsiConsole.Markup("\nPress [green]f[/] to show playlist");
}
}

0 comments on commit 95f82c7

Please sign in to comment.