From e1d7653a1a817c8ccf1b985869ed0872a5aeee90 Mon Sep 17 00:00:00 2001 From: jasonchenwork Date: Mon, 21 Jul 2025 12:57:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AA=BF=E6=95=B4=20=E6=89=8B=E6=A9=9F?= =?UTF-8?q?=E9=BB=9E=E6=AD=8C=20=E6=AD=8C=E6=9B=B2=E5=90=8D=E7=A8=B1?= =?UTF-8?q?=E4=B8=8D=E6=9C=83=E9=A1=AF=E7=A4=BA=2020250721?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DBObj/SongData.cs | 22 ++++--- DBObj/SongList.cs | 5 +- EnumExtensions.cs | 19 ++++++ HttpServer.cs | 78 +++++++++--------------- LocalizedDescriptionAttribute.cs | 17 ++++++ PlayState.cs | 27 +++++--- PrimaryFormParts/PrimaryForm.cs | 13 ---- Program.cs | 2 +- VideoPlayerForm.cs | 8 +-- themes/superstar/_www/search-singer.html | 4 -- 10 files changed, 104 insertions(+), 91 deletions(-) create mode 100644 EnumExtensions.cs create mode 100644 LocalizedDescriptionAttribute.cs diff --git a/DBObj/SongData.cs b/DBObj/SongData.cs index d879f66..bb9bc94 100644 --- a/DBObj/SongData.cs +++ b/DBObj/SongData.cs @@ -22,10 +22,20 @@ namespace DBObj basic=new(songNumber,song,songSimplified,filename,humanVoice); A= new Artist(artistA, artistASimplified); if(artistB!=null){ - B= new Artist(artistB, artistBSimplified); + B = new Artist(artistB, artistBSimplified); } isPublicSong = false; } + public SongData(SongData value,PlayState s){ + basic = value.getBasic(); + A = value.getA(); + B = value.getB(); + state =s; + } + public Song getBasic() => basic; + public Artist getA() => A; + public Artist getB() => B; + public string getNumber() {return basic.getNumber();} public string getName(bool IsSimplified=false) { return basic.getName(IsSimplified); } public string getName() { return basic.getName();} @@ -79,15 +89,7 @@ namespace DBObj return c; } public string GetStateTxt(bool IsSimplified){ - string txt = string.Empty; - if (state == PlayState.Played) { - txt = IsSimplified ? "(播毕)" : "(播畢)"; - } else if (state == PlayState.Playing) { - txt = IsSimplified ? "(播放中)" : "(播放中)"; - } else if (state == PlayState.InsertPlayback) { - txt = IsSimplified ? "(插播)" : "(插播)"; - } - return txt; + return (state==PlayState.NotPlayed)?"":$"({state.GetDescription(IsSimplified)})"; } public void SetState(PlayState s) => state = s; diff --git a/DBObj/SongList.cs b/DBObj/SongList.cs index 96f6e4a..71180e9 100644 --- a/DBObj/SongList.cs +++ b/DBObj/SongList.cs @@ -68,14 +68,13 @@ namespace DBObj public static void Add(SongData song) { - not_played.Add(song); + not_played.Add(new SongData(song,PlayState.NotPlayed)); // PrimaryForm.Instance.AddSongCount(songData.Number); chkCut(); } public static void Insert(SongData song) { - song.SetState(PlayState.InsertPlayback); - not_played.Insert(0, song); + not_played.Insert(0, new SongData(song,PlayState.InsertPlayback)); chkCut(); } private static void chkCut() diff --git a/EnumExtensions.cs b/EnumExtensions.cs new file mode 100644 index 0000000..4ffd274 --- /dev/null +++ b/EnumExtensions.cs @@ -0,0 +1,19 @@ +using System; +using System.Reflection; + +namespace DualScreenDemo +{ + public static class EnumExtensions + { + public static string GetDescription(this Enum value, bool isSimplified = false) + { + var field = value.GetType().GetField(value.ToString()); + + var attr = field?.GetCustomAttribute(); + if (attr != null) + return isSimplified ? attr.Simplified : attr.Traditional; + + return value.ToString(); + } + } +} diff --git a/HttpServer.cs b/HttpServer.cs index a5c8449..7c12d33 100644 --- a/HttpServer.cs +++ b/HttpServer.cs @@ -10,6 +10,7 @@ using ActionString = System.Action; // 现在可以在代码中使用 Ac using System.Collections.Concurrent; using DBObj; using OverlayFormObj; +using Newtonsoft.Json.Linq; namespace DualScreenDemo { @@ -369,8 +370,16 @@ namespace DualScreenDemo searchResults = new List(); break; } + var response = searchResults + .Select(song => new + { + Song = song.getName(), + ArtistA =song.getArtist_A(), + SongNumber = song.getNumber(), + }) + .ToList(); - await SendJsonResponseAsync(context, searchResults); + await SendJsonResponseAsync(context, response); } catch (Exception ex) { @@ -532,9 +541,6 @@ namespace DualScreenDemo break; case "male_key": // 执行男调操作 - //OverlayForm.MainForm.Invoke(new System.Action(() => { - // OverlayForm.MainForm.ShowTopRightLabelTime(" 男調 "); - //})); if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) { // 假設 0xA2, 0xC1, 0xA4 是升調的指令 @@ -552,9 +558,6 @@ namespace DualScreenDemo break; case "female_key": // 执行女调操作 - //OverlayForm.MainForm.Invoke(new System.Action(() => { - // OverlayForm.MainForm.ShowTopRightLabelTime(" 女調 "); - //})); if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) { // 假設 0xA2, 0xC1, 0xA4 是升調的指令 @@ -579,11 +582,6 @@ namespace DualScreenDemo break; case "lower_key": // 执行降调操作 - OverlayForm.MainForm.Invoke(new System.Action(() => { - OverlayForm.MainForm.ShowTopRightLabelTime("降 1# 調"); - })); - - // MessageBox.Show("降調功能啟動"); if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) { // 假設 0xA2, 0xC2, 0xA4 是降調的指令 @@ -598,9 +596,6 @@ namespace DualScreenDemo break; case "standard_key": // 执行标准调操作 - OverlayForm.MainForm.Invoke(new System.Action(() => { - OverlayForm.MainForm.ShowTopRightLabelTime(" 標準調 "); - })); if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) { // 假設 0xA2, 0xC1, 0xA4 是升調的指令 @@ -615,11 +610,6 @@ namespace DualScreenDemo break; case "raise_key": // 执行升调操作 - OverlayForm.MainForm.Invoke(new System.Action(() => { - OverlayForm.MainForm.ShowTopRightLabelTime("升 1# 調"); - })); - - // MessageBox.Show("升調功能啟動"); if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) { // 假設 0xA2, 0xC1, 0xA4 是升調的指令 @@ -670,25 +660,19 @@ namespace DualScreenDemo Console.WriteLine("Received order song request: " + requestBody); // 检查 playedSongsHistory 是否存在且不为空 - var response = new { status = "info", message = "No songs in the played history" }; - // 创建响应数据 - /* - response = new + var response = new { - playingSongList = PrimaryForm.playedSongsHistory + playingSongList = SongList.GetHistory() .Select((song, index) => new { - song.Name, - song.Artist_A, - song.FileName, - State = song.GetState() == PlayState.Playing ? "播放中" : "播放完畢" + Song=song.getName(), + ArtistA=song.getArtist_A(), + PlayState = song.GetState().GetDescription() }) - .ToList(), - // 生成播放历史 - currentSongIndexInHistory = PrimaryForm.currentSongIndexInHistory + .ToList() }; - */ + jsonResponse = JsonConvert.SerializeObject(response); context.Response.StatusCode = (int)HttpStatusCode.OK; @@ -716,22 +700,20 @@ namespace DualScreenDemo } Console.WriteLine("Received order song request: " + requestBody); - // 解析 JSON 为 Song 对象 - var song = JsonConvert.DeserializeObject(requestBody); + var json = JObject.Parse(requestBody); + SongData song =songListManager.SearchSongByNumber(json["SongNumber"]?.ToString()); - if (song != null) - { + if (song != null) { Console.WriteLine($"Ordering Song: {song.getName()} by {song.getArtist_A()}"); + // 这里可以添加处理逻辑,例如将歌曲加入到播放列表或数据库中 SongList.Add(song); var response = new { status = "success", message = "Song ordered successfully" }; string jsonResponse = JsonConvert.SerializeObject(response); await SendResponseAsync(context, jsonResponse); - } - else - { + } else { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; await SendResponseAsync(context, "{\"status\": \"error\", \"message\": \"Invalid song data\"}"); } @@ -757,19 +739,17 @@ namespace DualScreenDemo Console.WriteLine("Received insert song request: " + requestBody); // 解析 JSON 为 Song 对象 - var song = JsonConvert.DeserializeObject(requestBody); + var json = JObject.Parse(requestBody); + SongData song =songListManager.SearchSongByNumber(json["SongNumber"]?.ToString()); - if (song != null) - { + if (song != null){ Console.WriteLine($"Inserting Song: {song.getName()} by {song.getArtist_A()}"); // 这里可以添加插播歌曲的处理逻辑 SongList.Insert(song); var response = new { status = "success", message = "Song inserted successfully" }; string jsonResponse = JsonConvert.SerializeObject(response); await SendResponseAsync(context, jsonResponse); - } - else - { + } else { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; await SendResponseAsync(context, "{\"status\": \"error\", \"message\": \"Invalid song data\"}"); } @@ -1047,9 +1027,9 @@ namespace DualScreenDemo Name = song.getName(), ArtistA =song.getArtist_A(), Number = song.getNumber(), - //song.getArtist_A(true), - //song.getArtist_B(true), - //song.getName(true), + ArtistAFull = song.getArtist_A(true), + ArtistBFull = song.getArtist_B(true), + NameFull = song.getName(true), HumanVoice =song.getHumanVoice(), FileName = song.getFileName() }) diff --git a/LocalizedDescriptionAttribute.cs b/LocalizedDescriptionAttribute.cs new file mode 100644 index 0000000..9b56e30 --- /dev/null +++ b/LocalizedDescriptionAttribute.cs @@ -0,0 +1,17 @@ +using System; + +namespace DualScreenDemo +{ + [AttributeUsage(AttributeTargets.Field)] + public class LocalizedDescriptionAttribute : Attribute + { + public string Traditional { get; } + public string Simplified { get; } + + public LocalizedDescriptionAttribute(string traditional, string simplified) + { + Traditional = traditional; + Simplified = simplified; + } + } +} diff --git a/PlayState.cs b/PlayState.cs index d3f3480..eb45d89 100644 --- a/PlayState.cs +++ b/PlayState.cs @@ -1,13 +1,26 @@ +using System.ComponentModel; namespace DualScreenDemo { - + public enum PlayState { - NotPlayed, // 未播放 - Playing, // 正在播放 - Played, // 已播放 - InsertPlayback, // 插入播放 - NoFile, // 沒有文件 - Skipped // 已跳過 + [LocalizedDescription("", "")]//未播放 + NotPlayed, + + [LocalizedDescription("播放中", "播放中")] + Playing, + + [LocalizedDescription("播畢", "播毕")] + Played, + + [LocalizedDescription("插播", "插播")] + InsertPlayback, + + [LocalizedDescription("無文件", "无文件")] + NoFile, + + [LocalizedDescription("已跳過", "已跳过")] + Skipped + } } \ No newline at end of file diff --git a/PrimaryFormParts/PrimaryForm.cs b/PrimaryFormParts/PrimaryForm.cs index 1d0c7a9..3f7f99b 100644 --- a/PrimaryFormParts/PrimaryForm.cs +++ b/PrimaryFormParts/PrimaryForm.cs @@ -1938,19 +1938,14 @@ namespace DualScreenDemo private void MaleKeyButton_Click(object sender, EventArgs e) { - //verlayForm.MainForm.ShowTopRightLabelTime(" 男調 "); if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) { byte[] commandBytesIncreasePitch1 = new byte[] { 0xA2, 0x7F, 0xA4 }; SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch1, 0, commandBytesIncreasePitch1.Length); - //OverlayForm.MainForm.HideAllLabels(); byte[] commandBytesDecreasePitch = new byte[] { 0xA2, 0xB2, 0xA4 }; SerialPortManager.mySerialPort.Write(commandBytesDecreasePitch, 0, commandBytesDecreasePitch.Length); - //OverlayForm.MainForm.HideAllLabels(); SerialPortManager.mySerialPort.Write(commandBytesDecreasePitch, 0, commandBytesDecreasePitch.Length); - //OverlayForm.MainForm.HideAllLabels(); - } else { @@ -1961,17 +1956,13 @@ namespace DualScreenDemo private void FemaleKeyButton_Click(object sender, EventArgs e) { - //OverlayForm.MainForm.ShowTopRightLabelTime(" 女調 "); if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) { byte[] commandBytesIncreasePitch1 = new byte[] { 0xA2, 0x7F, 0xA4 }; SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch1, 0, commandBytesIncreasePitch1.Length); - //OverlayForm.MainForm.HideAllLabels(); byte[] commandBytesIncreasePitch = new byte[] { 0xA2, 0xB1, 0xA4 }; SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch, 0, commandBytesIncreasePitch.Length); - //OverlayForm.MainForm.HideAllLabels(); SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch, 0, commandBytesIncreasePitch.Length); - //OverlayForm.MainForm.HideAllLabels(); } else { @@ -1982,8 +1973,6 @@ namespace DualScreenDemo private void StandardKeyButton_Click(object sender, EventArgs e) { - OverlayForm.MainForm.ShowTopRightLabelTime(" 標準調 "); - if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) { byte[] commandBytesIncreasePitch = new byte[] { 0xA2, 0x7F, 0xA4 }; @@ -1997,7 +1986,6 @@ namespace DualScreenDemo private void PitchUpButton_Click(object sender, EventArgs e) { - OverlayForm.MainForm.ShowTopRightLabelTime("升 1# 調 "); if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) { byte[] commandBytesIncreasePitch = new byte[] { 0xA2, 0xB1, 0xA4 }; @@ -2011,7 +1999,6 @@ namespace DualScreenDemo private void PitchDownButton_Click(object sender, EventArgs e) { - OverlayForm.MainForm.ShowTopRightLabelTime("降 1# 調 "); if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) { byte[] commandBytesDecreasePitch = new byte[] { 0xA2, 0xB2, 0xA4 }; diff --git a/Program.cs b/Program.cs index 41393cf..067201a 100644 --- a/Program.cs +++ b/Program.cs @@ -17,7 +17,7 @@ namespace DualScreenDemo [STAThread] static void Main() { - Console.WriteLine("Server V.1.2.2 202507171805"); + Console.WriteLine("Server V.1.2.3 202507211300"); if (Utils.Env.GetBool("IsCursor", true)) Cursor.Hide(); AppDomain.CurrentDomain.ProcessExit += (s, e) => Cursor.Show(); //Console.WriteLine("正在與中控取得聯繫..."); diff --git a/VideoPlayerForm.cs b/VideoPlayerForm.cs index 41cd909..6f354f3 100644 --- a/VideoPlayerForm.cs +++ b/VideoPlayerForm.cs @@ -623,8 +623,8 @@ namespace DualScreenDemo if (videoWindowSecondary != null) videoWindowSecondary.put_Visible(OABool.False); // 清理並初始化 DirectShow 圖表 - //RemoveAllFilters(graphBuilderPrimary); - //RemoveAllFilters(graphBuilderSecondary); + RemoveAllFilters(graphBuilderPrimary); + RemoveAllFilters(graphBuilderSecondary); InitializeGraphBuilderPrimary(); InitializeGraphBuilderSecondary(); @@ -667,8 +667,8 @@ namespace DualScreenDemo if (videoWindowSecondary != null) videoWindowSecondary.put_Visible(OABool.False); // 隐藏副屏幕窗口,避免闪烁 // 清理并初始化 DirectShow 图表 - //RemoveAllFilters(graphBuilderPrimary); - //RemoveAllFilters(graphBuilderSecondary); + RemoveAllFilters(graphBuilderPrimary); + RemoveAllFilters(graphBuilderSecondary); InitializeGraphBuilderPrimary(); InitializeGraphBuilderSecondary(); diff --git a/themes/superstar/_www/search-singer.html b/themes/superstar/_www/search-singer.html index c447a93..9b1c5d4 100644 --- a/themes/superstar/_www/search-singer.html +++ b/themes/superstar/_www/search-singer.html @@ -389,8 +389,6 @@ Song: row.cells[0].textContent, ArtistA: row.cells[1].textContent, SongNumber: row.cells[2].textContent, - SongFilePathHost1: row.cells[3].textContent, - SongFilePathHost2: row.cells[4].textContent }; window.selectedSong = song; @@ -543,8 +541,6 @@ ${song.Song} ${song.ArtistA} ${song.SongNumber} - ${song.SongFilePathHost1} - ${song.SongFilePathHost2} `; row.addEventListener('click', function(e) { e.preventDefault();