調整 手機點歌 歌曲名稱不會顯示 20250721

This commit is contained in:
jasonchenwork 2025-07-21 12:57:23 +08:00
parent e532e26b54
commit e1d7653a1a
10 changed files with 104 additions and 91 deletions

View File

@ -22,10 +22,20 @@ namespace DBObj
basic=new(songNumber,song,songSimplified,filename,humanVoice); basic=new(songNumber,song,songSimplified,filename,humanVoice);
A= new Artist(artistA, artistASimplified); A= new Artist(artistA, artistASimplified);
if(artistB!=null){ if(artistB!=null){
B= new Artist(artistB, artistBSimplified); B = new Artist(artistB, artistBSimplified);
} }
isPublicSong = false; 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 getNumber() {return basic.getNumber();}
public string getName(bool IsSimplified=false) { return basic.getName(IsSimplified); } public string getName(bool IsSimplified=false) { return basic.getName(IsSimplified); }
public string getName() { return basic.getName();} public string getName() { return basic.getName();}
@ -79,15 +89,7 @@ namespace DBObj
return c; return c;
} }
public string GetStateTxt(bool IsSimplified){ public string GetStateTxt(bool IsSimplified){
string txt = string.Empty; return (state==PlayState.NotPlayed)?"":$"({state.GetDescription(IsSimplified)})";
if (state == PlayState.Played) {
txt = IsSimplified ? "(播毕)" : "(播畢)";
} else if (state == PlayState.Playing) {
txt = IsSimplified ? "(播放中)" : "(播放中)";
} else if (state == PlayState.InsertPlayback) {
txt = IsSimplified ? "(插播)" : "(插播)";
}
return txt;
} }
public void SetState(PlayState s) => state = s; public void SetState(PlayState s) => state = s;

View File

@ -68,14 +68,13 @@ namespace DBObj
public static void Add(SongData song) public static void Add(SongData song)
{ {
not_played.Add(song); not_played.Add(new SongData(song,PlayState.NotPlayed));
// PrimaryForm.Instance.AddSongCount(songData.Number); // PrimaryForm.Instance.AddSongCount(songData.Number);
chkCut(); chkCut();
} }
public static void Insert(SongData song) public static void Insert(SongData song)
{ {
song.SetState(PlayState.InsertPlayback); not_played.Insert(0, new SongData(song,PlayState.InsertPlayback));
not_played.Insert(0, song);
chkCut(); chkCut();
} }
private static void chkCut() private static void chkCut()

19
EnumExtensions.cs Normal file
View File

@ -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<LocalizedDescriptionAttribute>();
if (attr != null)
return isSimplified ? attr.Simplified : attr.Traditional;
return value.ToString();
}
}
}

View File

@ -10,6 +10,7 @@ using ActionString = System.Action<string>; // 现在可以在代码中使用 Ac
using System.Collections.Concurrent; using System.Collections.Concurrent;
using DBObj; using DBObj;
using OverlayFormObj; using OverlayFormObj;
using Newtonsoft.Json.Linq;
namespace DualScreenDemo namespace DualScreenDemo
{ {
@ -369,8 +370,16 @@ namespace DualScreenDemo
searchResults = new List<SongData>(); searchResults = new List<SongData>();
break; 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) catch (Exception ex)
{ {
@ -532,9 +541,6 @@ namespace DualScreenDemo
break; break;
case "male_key": case "male_key":
// 执行男调操作 // 执行男调操作
//OverlayForm.MainForm.Invoke(new System.Action(() => {
// OverlayForm.MainForm.ShowTopRightLabelTime(" 男調 ");
//}));
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{ {
// 假設 0xA2, 0xC1, 0xA4 是升調的指令 // 假設 0xA2, 0xC1, 0xA4 是升調的指令
@ -552,9 +558,6 @@ namespace DualScreenDemo
break; break;
case "female_key": case "female_key":
// 执行女调操作 // 执行女调操作
//OverlayForm.MainForm.Invoke(new System.Action(() => {
// OverlayForm.MainForm.ShowTopRightLabelTime(" 女調 ");
//}));
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{ {
// 假設 0xA2, 0xC1, 0xA4 是升調的指令 // 假設 0xA2, 0xC1, 0xA4 是升調的指令
@ -579,11 +582,6 @@ namespace DualScreenDemo
break; break;
case "lower_key": case "lower_key":
// 执行降调操作 // 执行降调操作
OverlayForm.MainForm.Invoke(new System.Action(() => {
OverlayForm.MainForm.ShowTopRightLabelTime("降 1# 調");
}));
// MessageBox.Show("降調功能啟動");
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{ {
// 假設 0xA2, 0xC2, 0xA4 是降調的指令 // 假設 0xA2, 0xC2, 0xA4 是降調的指令
@ -598,9 +596,6 @@ namespace DualScreenDemo
break; break;
case "standard_key": case "standard_key":
// 执行标准调操作 // 执行标准调操作
OverlayForm.MainForm.Invoke(new System.Action(() => {
OverlayForm.MainForm.ShowTopRightLabelTime(" 標準調 ");
}));
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{ {
// 假設 0xA2, 0xC1, 0xA4 是升調的指令 // 假設 0xA2, 0xC1, 0xA4 是升調的指令
@ -615,11 +610,6 @@ namespace DualScreenDemo
break; break;
case "raise_key": case "raise_key":
// 执行升调操作 // 执行升调操作
OverlayForm.MainForm.Invoke(new System.Action(() => {
OverlayForm.MainForm.ShowTopRightLabelTime("升 1# 調");
}));
// MessageBox.Show("升調功能啟動");
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{ {
// 假設 0xA2, 0xC1, 0xA4 是升調的指令 // 假設 0xA2, 0xC1, 0xA4 是升調的指令
@ -670,25 +660,19 @@ namespace DualScreenDemo
Console.WriteLine("Received order song request: " + requestBody); Console.WriteLine("Received order song request: " + requestBody);
// 检查 playedSongsHistory 是否存在且不为空 // 检查 playedSongsHistory 是否存在且不为空
var response = new { status = "info", message = "No songs in the played history" };
// 创建响应数据 // 创建响应数据
/* var response = new
response = new
{ {
playingSongList = PrimaryForm.playedSongsHistory playingSongList = SongList.GetHistory()
.Select((song, index) => new .Select((song, index) => new
{ {
song.Name, Song=song.getName(),
song.Artist_A, ArtistA=song.getArtist_A(),
song.FileName, PlayState = song.GetState().GetDescription()
State = song.GetState() == PlayState.Playing ? "播放中" : "播放完畢"
}) })
.ToList(), .ToList()
// 生成播放历史
currentSongIndexInHistory = PrimaryForm.currentSongIndexInHistory
}; };
*/
jsonResponse = JsonConvert.SerializeObject(response); jsonResponse = JsonConvert.SerializeObject(response);
context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.StatusCode = (int)HttpStatusCode.OK;
@ -716,22 +700,20 @@ namespace DualScreenDemo
} }
Console.WriteLine("Received order song request: " + requestBody); Console.WriteLine("Received order song request: " + requestBody);
// 解析 JSON 为 Song 对象 // 解析 JSON 为 Song 对象
var song = JsonConvert.DeserializeObject<SongData>(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()}"); Console.WriteLine($"Ordering Song: {song.getName()} by {song.getArtist_A()}");
// 这里可以添加处理逻辑,例如将歌曲加入到播放列表或数据库中 // 这里可以添加处理逻辑,例如将歌曲加入到播放列表或数据库中
SongList.Add(song); SongList.Add(song);
var response = new { status = "success", message = "Song ordered successfully" }; var response = new { status = "success", message = "Song ordered successfully" };
string jsonResponse = JsonConvert.SerializeObject(response); string jsonResponse = JsonConvert.SerializeObject(response);
await SendResponseAsync(context, jsonResponse); await SendResponseAsync(context, jsonResponse);
} } else {
else
{
context.Response.StatusCode = (int)HttpStatusCode.BadRequest; context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
await SendResponseAsync(context, "{\"status\": \"error\", \"message\": \"Invalid song data\"}"); await SendResponseAsync(context, "{\"status\": \"error\", \"message\": \"Invalid song data\"}");
} }
@ -757,19 +739,17 @@ namespace DualScreenDemo
Console.WriteLine("Received insert song request: " + requestBody); Console.WriteLine("Received insert song request: " + requestBody);
// 解析 JSON 为 Song 对象 // 解析 JSON 为 Song 对象
var song = JsonConvert.DeserializeObject<SongData>(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()}"); Console.WriteLine($"Inserting Song: {song.getName()} by {song.getArtist_A()}");
// 这里可以添加插播歌曲的处理逻辑 // 这里可以添加插播歌曲的处理逻辑
SongList.Insert(song); SongList.Insert(song);
var response = new { status = "success", message = "Song inserted successfully" }; var response = new { status = "success", message = "Song inserted successfully" };
string jsonResponse = JsonConvert.SerializeObject(response); string jsonResponse = JsonConvert.SerializeObject(response);
await SendResponseAsync(context, jsonResponse); await SendResponseAsync(context, jsonResponse);
} } else {
else
{
context.Response.StatusCode = (int)HttpStatusCode.BadRequest; context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
await SendResponseAsync(context, "{\"status\": \"error\", \"message\": \"Invalid song data\"}"); await SendResponseAsync(context, "{\"status\": \"error\", \"message\": \"Invalid song data\"}");
} }
@ -1047,9 +1027,9 @@ namespace DualScreenDemo
Name = song.getName(), Name = song.getName(),
ArtistA =song.getArtist_A(), ArtistA =song.getArtist_A(),
Number = song.getNumber(), Number = song.getNumber(),
//song.getArtist_A(true), ArtistAFull = song.getArtist_A(true),
//song.getArtist_B(true), ArtistBFull = song.getArtist_B(true),
//song.getName(true), NameFull = song.getName(true),
HumanVoice =song.getHumanVoice(), HumanVoice =song.getHumanVoice(),
FileName = song.getFileName() FileName = song.getFileName()
}) })

View File

@ -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;
}
}
}

View File

@ -1,13 +1,26 @@
using System.ComponentModel;
namespace DualScreenDemo namespace DualScreenDemo
{ {
public enum PlayState public enum PlayState
{ {
NotPlayed, // 未播放 [LocalizedDescription("", "")]//未播放
Playing, // 正在播放 NotPlayed,
Played, // 已播放
InsertPlayback, // 插入播放 [LocalizedDescription("播放中", "播放中")]
NoFile, // 沒有文件 Playing,
Skipped // 已跳過
[LocalizedDescription("播畢", "播毕")]
Played,
[LocalizedDescription("插播", "插播")]
InsertPlayback,
[LocalizedDescription("無文件", "无文件")]
NoFile,
[LocalizedDescription("已跳過", "已跳过")]
Skipped
} }
} }

View File

@ -1938,19 +1938,14 @@ namespace DualScreenDemo
private void MaleKeyButton_Click(object sender, EventArgs e) private void MaleKeyButton_Click(object sender, EventArgs e)
{ {
//verlayForm.MainForm.ShowTopRightLabelTime(" 男調 ");
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{ {
byte[] commandBytesIncreasePitch1 = new byte[] { 0xA2, 0x7F, 0xA4 }; byte[] commandBytesIncreasePitch1 = new byte[] { 0xA2, 0x7F, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch1, 0, commandBytesIncreasePitch1.Length); SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch1, 0, commandBytesIncreasePitch1.Length);
//OverlayForm.MainForm.HideAllLabels();
byte[] commandBytesDecreasePitch = new byte[] { 0xA2, 0xB2, 0xA4 }; byte[] commandBytesDecreasePitch = new byte[] { 0xA2, 0xB2, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytesDecreasePitch, 0, commandBytesDecreasePitch.Length); SerialPortManager.mySerialPort.Write(commandBytesDecreasePitch, 0, commandBytesDecreasePitch.Length);
//OverlayForm.MainForm.HideAllLabels();
SerialPortManager.mySerialPort.Write(commandBytesDecreasePitch, 0, commandBytesDecreasePitch.Length); SerialPortManager.mySerialPort.Write(commandBytesDecreasePitch, 0, commandBytesDecreasePitch.Length);
//OverlayForm.MainForm.HideAllLabels();
} }
else else
{ {
@ -1961,17 +1956,13 @@ namespace DualScreenDemo
private void FemaleKeyButton_Click(object sender, EventArgs e) private void FemaleKeyButton_Click(object sender, EventArgs e)
{ {
//OverlayForm.MainForm.ShowTopRightLabelTime(" 女調 ");
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{ {
byte[] commandBytesIncreasePitch1 = new byte[] { 0xA2, 0x7F, 0xA4 }; byte[] commandBytesIncreasePitch1 = new byte[] { 0xA2, 0x7F, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch1, 0, commandBytesIncreasePitch1.Length); SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch1, 0, commandBytesIncreasePitch1.Length);
//OverlayForm.MainForm.HideAllLabels();
byte[] commandBytesIncreasePitch = new byte[] { 0xA2, 0xB1, 0xA4 }; byte[] commandBytesIncreasePitch = new byte[] { 0xA2, 0xB1, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch, 0, commandBytesIncreasePitch.Length); SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch, 0, commandBytesIncreasePitch.Length);
//OverlayForm.MainForm.HideAllLabels();
SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch, 0, commandBytesIncreasePitch.Length); SerialPortManager.mySerialPort.Write(commandBytesIncreasePitch, 0, commandBytesIncreasePitch.Length);
//OverlayForm.MainForm.HideAllLabels();
} }
else else
{ {
@ -1982,8 +1973,6 @@ namespace DualScreenDemo
private void StandardKeyButton_Click(object sender, EventArgs e) private void StandardKeyButton_Click(object sender, EventArgs e)
{ {
OverlayForm.MainForm.ShowTopRightLabelTime(" 標準調 ");
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{ {
byte[] commandBytesIncreasePitch = new byte[] { 0xA2, 0x7F, 0xA4 }; byte[] commandBytesIncreasePitch = new byte[] { 0xA2, 0x7F, 0xA4 };
@ -1997,7 +1986,6 @@ namespace DualScreenDemo
private void PitchUpButton_Click(object sender, EventArgs e) private void PitchUpButton_Click(object sender, EventArgs e)
{ {
OverlayForm.MainForm.ShowTopRightLabelTime("升 1# 調 ");
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{ {
byte[] commandBytesIncreasePitch = new byte[] { 0xA2, 0xB1, 0xA4 }; byte[] commandBytesIncreasePitch = new byte[] { 0xA2, 0xB1, 0xA4 };
@ -2011,7 +1999,6 @@ namespace DualScreenDemo
private void PitchDownButton_Click(object sender, EventArgs e) private void PitchDownButton_Click(object sender, EventArgs e)
{ {
OverlayForm.MainForm.ShowTopRightLabelTime("降 1# 調 ");
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen) if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{ {
byte[] commandBytesDecreasePitch = new byte[] { 0xA2, 0xB2, 0xA4 }; byte[] commandBytesDecreasePitch = new byte[] { 0xA2, 0xB2, 0xA4 };

View File

@ -17,7 +17,7 @@ namespace DualScreenDemo
[STAThread] [STAThread]
static void Main() 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(); if (Utils.Env.GetBool("IsCursor", true)) Cursor.Hide();
AppDomain.CurrentDomain.ProcessExit += (s, e) => Cursor.Show(); AppDomain.CurrentDomain.ProcessExit += (s, e) => Cursor.Show();
//Console.WriteLine("正在與中控取得聯繫..."); //Console.WriteLine("正在與中控取得聯繫...");

View File

@ -623,8 +623,8 @@ namespace DualScreenDemo
if (videoWindowSecondary != null) videoWindowSecondary.put_Visible(OABool.False); if (videoWindowSecondary != null) videoWindowSecondary.put_Visible(OABool.False);
// 清理並初始化 DirectShow 圖表 // 清理並初始化 DirectShow 圖表
//RemoveAllFilters(graphBuilderPrimary); RemoveAllFilters(graphBuilderPrimary);
//RemoveAllFilters(graphBuilderSecondary); RemoveAllFilters(graphBuilderSecondary);
InitializeGraphBuilderPrimary(); InitializeGraphBuilderPrimary();
InitializeGraphBuilderSecondary(); InitializeGraphBuilderSecondary();
@ -667,8 +667,8 @@ namespace DualScreenDemo
if (videoWindowSecondary != null) videoWindowSecondary.put_Visible(OABool.False); // 隐藏副屏幕窗口,避免闪烁 if (videoWindowSecondary != null) videoWindowSecondary.put_Visible(OABool.False); // 隐藏副屏幕窗口,避免闪烁
// 清理并初始化 DirectShow 图表 // 清理并初始化 DirectShow 图表
//RemoveAllFilters(graphBuilderPrimary); RemoveAllFilters(graphBuilderPrimary);
//RemoveAllFilters(graphBuilderSecondary); RemoveAllFilters(graphBuilderSecondary);
InitializeGraphBuilderPrimary(); InitializeGraphBuilderPrimary();
InitializeGraphBuilderSecondary(); InitializeGraphBuilderSecondary();

View File

@ -389,8 +389,6 @@
Song: row.cells[0].textContent, Song: row.cells[0].textContent,
ArtistA: row.cells[1].textContent, ArtistA: row.cells[1].textContent,
SongNumber: row.cells[2].textContent, SongNumber: row.cells[2].textContent,
SongFilePathHost1: row.cells[3].textContent,
SongFilePathHost2: row.cells[4].textContent
}; };
window.selectedSong = song; window.selectedSong = song;
@ -543,8 +541,6 @@
<td>${song.Song}</td> <td>${song.Song}</td>
<td>${song.ArtistA}</td> <td>${song.ArtistA}</td>
<td>${song.SongNumber}</td> <td>${song.SongNumber}</td>
<td style="display:none;">${song.SongFilePathHost1}</td>
<td style="display:none;">${song.SongFilePathHost2}</td>
`; `;
row.addEventListener('click', function(e) { row.addEventListener('click', function(e) {
e.preventDefault(); e.preventDefault();