Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SplitGemini committed May 24, 2020
1 parent d3458d9 commit 2ce9a46
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 76 deletions.
11 changes: 10 additions & 1 deletion LyricEditor.sln
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Blend for Visual Studio 15
# Visual Studio 15
VisualStudioVersion = 15.0.26430.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LyricEditor", "LyricEditor\LyricEditor.csproj", "{2518686C-FC81-48A8-8A2F-34C803B9BE65}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2518686C-FC81-48A8-8A2F-34C803B9BE65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2518686C-FC81-48A8-8A2F-34C803B9BE65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2518686C-FC81-48A8-8A2F-34C803B9BE65}.Debug|x86.ActiveCfg = Debug|x86
{2518686C-FC81-48A8-8A2F-34C803B9BE65}.Debug|x86.Build.0 = Debug|x86
{2518686C-FC81-48A8-8A2F-34C803B9BE65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2518686C-FC81-48A8-8A2F-34C803B9BE65}.Release|Any CPU.Build.0 = Release|Any CPU
{2518686C-FC81-48A8-8A2F-34C803B9BE65}.Release|x86.ActiveCfg = Release|x86
{2518686C-FC81-48A8-8A2F-34C803B9BE65}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D3D08FE-B442-4140-A97C-0D0898204331}
EndGlobalSection
EndGlobal
Binary file added LyricEditor/Icons/ToolButtonIcons/TranslateNS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added LyricEditor/Icons/ToolButtonIcons/TranslateS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions LyricEditor/LyricEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@
<PropertyGroup>
<ApplicationIcon>Icons\LrcMaker.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="policy.2.0.taglib-sharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
<HintPath>..\packages\taglib.2.1.0.0\lib\policy.2.0.taglib-sharp.dll</HintPath>
Expand Down Expand Up @@ -238,5 +256,9 @@
<ItemGroup>
<Resource Include="Icons\ToolButtonIcons\translate.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Icons\ToolButtonIcons\TranslateNS.png" />
<Resource Include="Icons\ToolButtonIcons\TranslateS.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
9 changes: 7 additions & 2 deletions LyricEditor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
</Style>
</Grid.Resources>
<TextBlock Name="NextLrcText" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#FF9E4848" TextDecorations="{x:Null}" FontFamily="Microsoft YaHei"/>
<TextBlock Name="TMPLrcText" Visibility="Hidden" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#FF9E4848" TextDecorations="{x:Null}" FontFamily="Microsoft YaHei"/>
<TextBlock Name="AfterNextLrcText" Visibility="Hidden" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#FF9E4848" TextDecorations="{x:Null}" FontFamily="Microsoft YaHei"/>
</Grid>

<!--右侧工具列表-->
Expand Down Expand Up @@ -399,7 +399,12 @@
</Button.ToolTip>
<Image Source="Icons/ToolButtonIcons/Go-into.png"/>
</Button>
<Button Margin="0,0,0,10" Click="Translate_Click">
<ToggleButton Name="TranslateSwitchButton" Click="TranslateSwitch_Click" Style="{StaticResource ToolToggleButton}" Width="30">
<ToggleButton.ToolTip>
切换为设置翻译模式
</ToggleButton.ToolTip>
</ToggleButton>
<Button Name="TranslateButton" Margin="0,0,0,10" Click="Translate_Click">
<Button.ToolTip>
设为翻译 (Ctrl+T)
</Button.ToolTip>
Expand Down
113 changes: 48 additions & 65 deletions LyricEditor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,10 @@ public LrcManager Manager

#endregion
#region 计时器
private bool canRoll = false;
private bool isRight = true;
private bool shouldUpdate = false;
private bool canRoll = false;
private double nextTextWidth;
private double rollingInterval = 1.0; //每一步的偏移量
private double offset = 10; //滚动左右空余位置
private bool isFirst = true;

public void UpdateLyric()
{
shouldUpdate = true;
var value = Manager.GetNearestLrc(MediaPlayer.Position);
if (value != null)
{
string tmp = string.Empty;
value.TryGetValue("current", out tmp);
CurrentLrcText.Text = tmp;
value.TryGetValue("pre", out tmp);
PreLrcText.Text = tmp;
value.TryGetValue("next", out tmp);
NextLrcText.Text = tmp;
value.TryGetValue("afternext", out tmp);
TMPLrcText.Text = tmp;
value.TryGetValue("short", out tmp);
if (tmp.Equals("true"))
{
nextTextWidth = TMPLrcText.ActualWidth;
}
else
{
nextTextWidth = NextLrcText.ActualWidth;
}
}
}

/// <summary>
/// 每个计时器时刻,更新时间轴上的全部信息
/// </summary>
Expand All @@ -118,60 +87,60 @@ private void Timer_Tick(object sender, EventArgs e)

TimeBackground.Value = MediaPlayer.Position.TotalSeconds / MediaPlayer.NaturalDuration.TimeSpan.TotalSeconds;
var value = Manager.GetNearestLrc(MediaPlayer.Position);
if(value != null)
var shouldSetToLeft = false;
if (value != null)
{
if (isFirst)
{
UpdateLyric();
isFirst = false;
}
string tmp = string.Empty;

value.TryGetValue("current", out tmp);
if (!CurrentLrcText.Text.Equals(tmp) && !shouldUpdate)
if (!CurrentLrcText.Text.Equals(tmp))
{
CurrentLrcText.Text = tmp;
CurrentLrcText.Left = (CurrentLrcText.ActualWidth - nextTextWidth) / 2;
value.TryGetValue("pre", out tmp);
PreLrcText.Text = tmp;
value.TryGetValue("next", out tmp);
NextLrcText.Text = tmp;
value.TryGetValue("afternext", out tmp);
TMPLrcText.Text = tmp;
shouldSetToLeft = true;
if(!canRoll)
CurrentLrcText.Left = (CurrentLrcText.ActualWidth - nextTextWidth) / 2;
}else
{
shouldSetToLeft = false;
if (!canRoll)
CurrentLrcText.Left = (CurrentLrcText.ActualWidth - CurrentLrcText.currentTextBlock.ActualWidth) / 2;
}
CurrentLrcText.Text = tmp;
value.TryGetValue("pre", out tmp);
PreLrcText.Text = tmp;
value.TryGetValue("next", out tmp);
NextLrcText.Text = tmp;
value.TryGetValue("afternext", out tmp);
AfterNextLrcText.Text = tmp;
value.TryGetValue("short", out tmp);
if (tmp.Equals("true"))
{
nextTextWidth = TMPLrcText.ActualWidth;
nextTextWidth = AfterNextLrcText.ActualWidth;
}
else {
nextTextWidth = NextLrcText.ActualWidth;
}
if (shouldUpdate)
{
CurrentLrcText.Left = (CurrentLrcText.ActualWidth - CurrentLrcText.currentTextBlock.ActualWidth) / 2;
shouldUpdate = false;
}

}
var last = canRoll;
canRoll = CurrentLrcText.currentTextBlock.ActualWidth > CurrentLrcText.ActualWidth;
if (canRoll)
{
if (!last)
var offset = 10.0; //滚动左右空余位置
double rollingInterval = (CurrentLrcText.currentTextBlock.ActualWidth - CurrentLrcText.ActualWidth)/ 50; //每一步的偏移量,根据每段长度
if (shouldSetToLeft)
{
CurrentLrcText.Left = offset;
}
if (Math.Abs(CurrentLrcText.Left) <= CurrentLrcText.currentTextBlock.ActualWidth - CurrentLrcText.ActualWidth + offset && isRight)
}
else if (Math.Abs(CurrentLrcText.Left) <= CurrentLrcText.currentTextBlock.ActualWidth - CurrentLrcText.ActualWidth + offset && isRight)
{
CurrentLrcText.Left -= rollingInterval;
}
/* 需要回滚取消注释
else if (CurrentLrcText.Left <= offset)
{
CurrentLrcText.Left += rollingInterval;
isRight = CurrentLrcText.Left >= offset;
}

*/
}
}

Expand Down Expand Up @@ -338,6 +307,9 @@ private void ImportMedia(string filename)
Title = "歌词编辑器 :" + Path.GetFileNameWithoutExtension(filename);
Cover.Source = GetAlbumArt(filename);
GetLyric(filename);
CurrentLrcText.Text = string.Empty;
PreLrcText.Text = string.Empty;
NextLrcText.Text = string.Empty;
}
catch (Exception e)
{
Expand Down Expand Up @@ -651,6 +623,8 @@ private void SwitchLrcPanel_Click(object sender, RoutedEventArgs e)
SortTime.IsEnabled = true;
ResetAllTime.IsEnabled = true;
ShiftAllTime.IsEnabled = true;
TranslateButton.IsEnabled = true;
TranslateSwitchButton.IsEnabled = true;
break;
}
}
Expand All @@ -667,6 +641,8 @@ private void SwitchToTextLrcPanel() {
SortTime.IsEnabled = false;
ResetAllTime.IsEnabled = false;
ShiftAllTime.IsEnabled = false;
TranslateButton.IsEnabled = false;
TranslateSwitchButton.IsEnabled = false;
}

/// <summary>
Expand Down Expand Up @@ -713,7 +689,6 @@ private void TimeShift_Click(object sender, RoutedEventArgs e)
MediaPlayer.Position += LongTimeShift;
break;
}
UpdateLyric();
}
/// <summary>
/// 时间轴点击
Expand All @@ -727,7 +702,6 @@ private void TimeClickBar_MouseDown(object sender, MouseButtonEventArgs e)
TimeBackground.Value = percent;

MediaPlayer.Position = new TimeSpan(0, 0, 0, 0, (int)(MediaPlayer.NaturalDuration.TimeSpan.TotalMilliseconds * percent));
UpdateLyric();
}
/// <summary>
/// 撤销
Expand Down Expand Up @@ -851,6 +825,18 @@ private void Translate_Click(object sender, RoutedEventArgs e)

LrcLinePanel.SetCurrentLineTimeForTranslate();
}

private void TranslateSwitch_Click(object sender, RoutedEventArgs e)
{
if (CurrentLrcPanel != LrcPanelType.LrcLinePanel) return;
if (TranslateSwitchButton.IsChecked == true)
{
LrcLinePanel.LrcLinePanel.SelectionMode = SelectionMode.Multiple;
}
else {
LrcLinePanel.LrcLinePanel.SelectionMode = SelectionMode.Single;
}
}
#endregion

#region 快捷键
Expand Down Expand Up @@ -892,25 +878,21 @@ private void InsertShortcut_Executed(object sender, ExecutedRoutedEventArgs e)
private void Jump1Shortcut_Executed(object sender, ExecutedRoutedEventArgs e)
{
MediaPlayer.Position += ShortTimeShift;
UpdateLyric();
}

private void Jump2Shortcut_Executed(object sender, ExecutedRoutedEventArgs e)
{
MediaPlayer.Position += LongTimeShift;
UpdateLyric();
}

private void Rewind1Shortcut_Executed(object sender, ExecutedRoutedEventArgs e)
{
MediaPlayer.Position -= ShortTimeShift;
UpdateLyric();
}

private void Rewind2Shortcut_Executed(object sender, ExecutedRoutedEventArgs e)
{
MediaPlayer.Position -= LongTimeShift;
UpdateLyric();
}

private void StopShortcut_Executed(object sender, ExecutedRoutedEventArgs e)
Expand All @@ -928,9 +910,10 @@ private void TranslateShortcut_Executed(object sender, ExecutedRoutedEventArgs e
Translate_Click(this, null);
}


//Delete, Up, Down快捷键处理在LrcLineView.xaml.cs实现
#endregion


}
}
57 changes: 57 additions & 0 deletions LyricEditor/Styles/Styles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,61 @@
</Style.Triggers>
</Style>

<Style x:Key="ToolToggleButton" TargetType="{x:Type ToggleButton}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="4"/>
<Setter Property="Height" Value="{Binding RelativeSource={RelativeSource Self},Path=Width}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter Property="Content">
<Setter.Value>
<Image Source="/LyricEditor;component/Icons/ToolButtonIcons/TranslateS.png"/>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsChecked" Value="false">
<Setter Property="Content">
<Setter.Value>
<Image Source="/LyricEditor;component/Icons/ToolButtonIcons/TranslateNS.png"/>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Resources>
<Style TargetType="{x:Type Image}">
<Setter Property="RenderOptions.BitmapScalingMode" Value="Fant"/>
</Style>
</Style.Resources>
<Style.Triggers>
<EventTrigger RoutedEvent="Button.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard TargetProperty="Padding">
<ThicknessAnimation From="4" To="1" Duration="0:0:0.25"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="Button.MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard TargetProperty="Padding">
<ThicknessAnimation From="1" To="4" Duration="0:0:0.25"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>

</ResourceDictionary>
Loading

0 comments on commit 2ce9a46

Please sign in to comment.