Skip to content

Commit

Permalink
feat: 在只有单语言时支持显示下一行歌词
Browse files Browse the repository at this point in the history
  • Loading branch information
cqjjjzr committed Mar 30, 2023
1 parent 145b8a8 commit 4bc9c91
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 303 deletions.
1 change: 1 addition & 0 deletions DesktopLyrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public bool Configure(IntPtr panelHandle)
SaveSettings(_settings);
_frmLyrics?.UpdateFromSettings(_settings);
LyricParser.PreserveSlash = _settings.PreserveSlash;
_lyricsCtrl.NextLineWhenNoTranslation = _settings.NextLineWhenNoTranslation;
};
configPanel.Controls.Add(btnSettings);

Expand Down
20 changes: 10 additions & 10 deletions FrmLyrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public void DrawLyrics1Line(string lyrics)
{
using (var g = CreateGraphics())
{
var bitmap = LyricsRenderer.Render1LineLyrics(lyrics, g);

if (bitmap == null)
return;

var bitmap = LyricsRenderer.Render1LineLyrics(lyrics, g);

if (bitmap == null)
return;

using (bitmap)
{
if (Width != bitmap.Width) Width = bitmap.Width;
Expand All @@ -113,11 +113,11 @@ public void DrawLyrics2Line(string line1, string line2)
{
using (var g = CreateGraphics())
{
var bitmap = LyricsRenderer.Render2LineLyrics(line1, line2, g);

if (bitmap == null)
return;

var bitmap = LyricsRenderer.Render2LineLyrics(line1, line2, g);

if (bitmap == null)
return;

using (bitmap)
{
if (Width != bitmap.Width) Width = bitmap.Width;
Expand Down
339 changes: 179 additions & 160 deletions FrmSettings.Designer.cs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions FrmSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private void Settings_Load(object sender, EventArgs e)
btnBorderColor.BackColor = _settings.BorderColor;
checkBoxPreserveSlash.Checked = _settings.PreserveSlash;
checkBoxAutoHide.Checked = _settings.AutoHide;
checkBoxNextLineWhenNoTranslation.Checked = _settings.NextLineWhenNoTranslation;
}
catch (Exception)
{
Expand Down Expand Up @@ -87,6 +88,11 @@ private void checkBoxAutoHide_CheckedChanged(object sender, EventArgs e)
}

public SettingsObj Settings => _settings;

private void checkBoxNextLineWhenNoTranslation_CheckedChanged(object sender, EventArgs e)
{
_settings.NextLineWhenNoTranslation = checkBoxNextLineWhenNoTranslation.Checked;
}
}

public class SettingsObj
Expand All @@ -98,6 +104,7 @@ public class SettingsObj
public int GradientType;
public bool PreserveSlash = false;
public bool AutoHide = false;
public bool NextLineWhenNoTranslation = false;
public bool HideOnStartup = false;
public int PosY = -1;
public int PosX = -1;
Expand Down
244 changes: 122 additions & 122 deletions FrmSettings.resx
Original file line number Diff line number Diff line change
@@ -1,123 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="dlgFont.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="dlgFont.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
17 changes: 11 additions & 6 deletions LyricParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,33 @@ public static Lyrics ParseLyric(string lyric)
}

if (rawLyrics.Count <= 0) return null;
var entries = CollapseLyric(rawLyrics);
var (entries, hasTranslation) = FoldLyricTranslation(rawLyrics);
return new Lyrics
{
Entries = entries,
Offset = lyricOffset
Offset = lyricOffset,
HasTranslation = hasTranslation
};
}

private static List<LyricEntry> CollapseLyric(IEnumerable<RawLyricEntry> rawLyrics)
private static (List<LyricEntry>, bool) FoldLyricTranslation(IEnumerable<RawLyricEntry> rawLyrics)
{
var entries = new List<LyricEntry>();
var entries = new List<LyricEntry>();
bool hasTranslation = false;

foreach (var rawLyricEntry in rawLyrics)
{
if (!PreserveSlash && rawLyricEntry.LyricLine.Contains("/"))
{
var segs = rawLyricEntry.LyricLine.Split(new[] {'/'}, 2);
entries.Add(new LyricEntry(rawLyricEntry.Time, segs[0], segs[1]));
hasTranslation = true;
}
else
entries.Add(new LyricEntry(rawLyricEntry.Time, rawLyricEntry.LyricLine, null));
}
entries.Sort(new LyricEntry.LyricEntryComparer());
return entries;
return (entries, hasTranslation);
}

private static double ProcessOffset(string line)
Expand Down Expand Up @@ -147,8 +151,9 @@ public RawLyricEntry(double time, string lyricLine)

public class Lyrics
{
public List<LyricEntry> Entries;
public List<LyricEntry> Entries; // Sorted guaranteed
public double Offset;
public bool HasTranslation;
}
}
}
Loading

0 comments on commit 4bc9c91

Please sign in to comment.