This should be done

This commit is contained in:
minster586
2025-08-27 18:16:59 -04:00
parent 12cdde5044
commit 8fa429575d

View File

@@ -28,6 +28,16 @@ namespace RadioDJViewer
private System.Windows.Forms.Timer apiTimer; private System.Windows.Forms.Timer apiTimer;
private string lastApiXml = null; private string lastApiXml = null;
private System.Windows.Forms.Timer marqueeTimerTitle;
private System.Windows.Forms.Timer marqueeTimerArtist;
private System.Windows.Forms.Timer marqueeTimerAlbum;
private int marqueeOffsetTitle = 0;
private int marqueeOffsetArtist = 0;
private int marqueeOffsetAlbum = 0;
private string marqueeTextTitle = "";
private string marqueeTextArtist = "";
private string marqueeTextAlbum = "";
public Main() public Main()
{ {
InitializeComponent(); InitializeComponent();
@@ -39,16 +49,18 @@ namespace RadioDJViewer
apiTimer = new System.Windows.Forms.Timer(); apiTimer = new System.Windows.Forms.Timer();
apiTimer.Interval = 3000; // 3 seconds apiTimer.Interval = 3000; // 3 seconds
apiTimer.Tick += ApiTimer_Tick; apiTimer.Tick += ApiTimer_Tick;
// Set up marquee timer for title // Marquee timers for each label
marqueeTimer = new System.Windows.Forms.Timer(); marqueeTimerTitle = new System.Windows.Forms.Timer();
marqueeTimer.Interval = 100; // Adjust speed as needed marqueeTimerTitle.Interval = 100; // Adjust speed as needed
marqueeTimer.Tick += MarqueeTimer_Tick; marqueeTimerTitle.Tick += MarqueeTimerTitle_Tick;
marqueeTimerArtist = new System.Windows.Forms.Timer();
marqueeTimerArtist.Interval = 100; // Adjust speed as needed
marqueeTimerArtist.Tick += MarqueeTimerArtist_Tick;
marqueeTimerAlbum = new System.Windows.Forms.Timer();
marqueeTimerAlbum.Interval = 100; // Adjust speed as needed
marqueeTimerAlbum.Tick += MarqueeTimerAlbum_Tick;
} }
private System.Windows.Forms.Timer marqueeTimer;
private int marqueeOffset = 0;
private string marqueeText = "";
private void EnsureDefaultImageExists() private void EnsureDefaultImageExists()
{ {
if (!File.Exists(defaultImagePath)) if (!File.Exists(defaultImagePath))
@@ -62,22 +74,52 @@ namespace RadioDJViewer
} }
} }
private void MarqueeTimer_Tick(object sender, EventArgs e) private void MarqueeTimerTitle_Tick(object sender, EventArgs e)
{
if (marqueeText.Length > 0)
{ {
int visibleChars = 30; // Adjust for label width int visibleChars = 30; // Adjust for label width
if (marqueeText.Length > visibleChars) if (marqueeTextTitle.Length > visibleChars)
{ {
marqueeOffset = (marqueeOffset + 1) % marqueeText.Length; string scrollText = marqueeTextTitle + " |";
string display = marqueeText.Substring(marqueeOffset) + " " + marqueeText.Substring(0, marqueeOffset); marqueeOffsetTitle = (marqueeOffsetTitle + 1) % scrollText.Length;
string display = scrollText.Substring(marqueeOffsetTitle) + " " + scrollText.Substring(0, marqueeOffsetTitle);
label4.Text = display.Substring(0, Math.Min(visibleChars, display.Length)); label4.Text = display.Substring(0, Math.Min(visibleChars, display.Length));
} }
else else
{ {
label4.Text = marqueeText; label4.Text = marqueeTextTitle;
} }
} }
private void MarqueeTimerArtist_Tick(object sender, EventArgs e)
{
int visibleChars = 30; // Adjust for label width
if (marqueeTextArtist.Length > visibleChars)
{
string scrollText = marqueeTextArtist + " |";
marqueeOffsetArtist = (marqueeOffsetArtist + 1) % scrollText.Length;
string display = scrollText.Substring(marqueeOffsetArtist) + " " + scrollText.Substring(0, marqueeOffsetArtist);
label5.Text = display.Substring(0, Math.Min(visibleChars, display.Length));
}
else
{
label5.Text = marqueeTextArtist;
}
}
private void MarqueeTimerAlbum_Tick(object sender, EventArgs e)
{
int visibleChars = 30; // Adjust for label width
if (marqueeTextAlbum.Length > visibleChars)
{
string scrollText = marqueeTextAlbum + " |";
marqueeOffsetAlbum = (marqueeOffsetAlbum + 1) % scrollText.Length;
string display = scrollText.Substring(marqueeOffsetAlbum) + " " + scrollText.Substring(0, marqueeOffsetAlbum);
label6.Text = display.Substring(0, Math.Min(visibleChars, display.Length));
}
else
{
label6.Text = marqueeTextAlbum;
}
} }
private void ApiTimer_Tick(object sender, EventArgs e) private void ApiTimer_Tick(object sender, EventArgs e)
@@ -280,6 +322,23 @@ namespace RadioDJViewer
} }
} }
private void StartMarqueeTimers()
{
marqueeOffsetTitle = 0;
marqueeOffsetArtist = 0;
marqueeOffsetAlbum = 0;
marqueeTimerTitle.Start();
marqueeTimerArtist.Start();
marqueeTimerAlbum.Start();
}
private void StopMarqueeTimers()
{
marqueeTimerTitle.Stop();
marqueeTimerArtist.Stop();
marqueeTimerAlbum.Stop();
}
private void ParseAndDisplaySongInfo(string xml) private void ParseAndDisplaySongInfo(string xml)
{ {
try try
@@ -292,18 +351,17 @@ namespace RadioDJViewer
string album = doc.SelectSingleNode("//*[translate(local-name(), 'ALBUM', 'album')='album']")?.InnerText; string album = doc.SelectSingleNode("//*[translate(local-name(), 'ALBUM', 'album')='album']")?.InnerText;
string albumArt = doc.SelectSingleNode("//*[translate(local-name(), 'ALBUMART', 'albumart')='albumart']")?.InnerText; string albumArt = doc.SelectSingleNode("//*[translate(local-name(), 'ALBUMART', 'albumart')='albumart']")?.InnerText;
marqueeText = !string.IsNullOrWhiteSpace(title) ? title : "No title"; marqueeTextTitle = !string.IsNullOrWhiteSpace(title) ? title : "No title";
marqueeOffset = 0; marqueeTextArtist = !string.IsNullOrWhiteSpace(artist) ? artist : "No artist";
marqueeTimer.Start(); marqueeTextAlbum = !string.IsNullOrWhiteSpace(album) ? album : "No album";
label5.Text = !string.IsNullOrWhiteSpace(artist) ? artist : "No artist"; StartMarqueeTimers();
label6.Text = !string.IsNullOrWhiteSpace(album) ? album : "No album";
// Write to output files // Write to output files
if (!string.IsNullOrEmpty(outputFolderPath)) if (!string.IsNullOrEmpty(outputFolderPath))
{ {
File.WriteAllText(Path.Combine(outputFolderPath, "title.txt"), marqueeText); File.WriteAllText(Path.Combine(outputFolderPath, "title.txt"), marqueeTextTitle);
File.WriteAllText(Path.Combine(outputFolderPath, "artist.txt"), label5.Text); File.WriteAllText(Path.Combine(outputFolderPath, "artist.txt"), marqueeTextArtist);
File.WriteAllText(Path.Combine(outputFolderPath, "album.txt"), label6.Text); File.WriteAllText(Path.Combine(outputFolderPath, "album.txt"), marqueeTextAlbum);
} }
// Handle album art image // Handle album art image
@@ -318,11 +376,10 @@ namespace RadioDJViewer
} }
catch catch
{ {
marqueeText = "No title"; marqueeTextTitle = "No title";
marqueeOffset = 0; marqueeTextArtist = "No artist";
marqueeTimer.Start(); marqueeTextAlbum = "No album";
label5.Text = "No artist"; StartMarqueeTimers();
label6.Text = "No album";
pictureBox1.Image = null; pictureBox1.Image = null;
} }
} }