Skip to content
This repository was archived by the owner on Oct 30, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Commands/EditCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public static partial class UICommands
new KeyGesture(Key.F5, ModifierKeys.None, "F5")
}));

public static RoutedUICommand ClearLyrics { get; } = new RoutedUICommand(
"清空歌词(_C)...",
"ClearLyrics",
typeof(UICommands),
new InputGestureCollection());

public static RoutedUICommand EditSkipData { get; } = new RoutedUICommand(
"编辑跳过单字(_E)",
"EditSkipData",
Expand Down
7 changes: 6 additions & 1 deletion Dialogs/EditLineDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<RowDefinition/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Margin="0,0,0,12" Opacity="0.5">
<TextBlock.Style>
Expand Down Expand Up @@ -89,7 +90,11 @@
IsEnabled="False"
TypeList="{x:Static models:ModeType.PreType}"/>
</Grid>
<StackPanel Grid.Row="3" Orientation="Horizontal"
<StackPanel Orientation="Horizontal" Grid.Row="3">
<TextBlock>双语:</TextBlock>
<CheckBox x:Name="Dual_languageSwitch"></CheckBox>
</StackPanel>
<StackPanel Grid.Row="4" Orientation="Horizontal"
HorizontalAlignment="Right"
Margin="0,12,0,0">
<Button Margin="12,0" Content="确定" MinWidth="80"
Expand Down
4 changes: 4 additions & 0 deletions Dialogs/EditLineDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public static string GetData()
_data = null;
return data;
}
public static bool GetIsDualLanguage()
{
return (bool)Current.Dual_languageSwitch.IsChecked;
}

#endregion

Expand Down
20 changes: 18 additions & 2 deletions Models/LrcModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,20 @@ private void OnLrcModelPropertyChanged([CallerMemberName] string propertyName =

#region ItemOperations

public void AddLyrics(string lyrics)
public void AddLyrics(string lyrics, bool isDualLanguage = false)
{
AddLyrics(lyrics.Split('\n'));
if(isDualLanguage)
{
lyrics = lyrics.Replace("\r", "");
AddLyrics(lyrics.Split('\n').Where(x => string.IsNullOrEmpty(x) is false).ToList().Where((x, index) =>
{
return index % 2 == 0 ;
}).ToArray());
}
else
{
AddLyrics(lyrics.Split('\n'));
}
}

public void AddLyrics(string[] lyrics)
Expand Down Expand Up @@ -303,6 +314,11 @@ public void RemoveLine(LrcLine line)
if (decreaseIndex) GlobalIndex -= oldCount;
}

public void ClearAll()
{
Current.Items.Clear();
}

#endregion

}
Expand Down
14 changes: 13 additions & 1 deletion Views/LyricEditorViewCommandBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,26 @@ public void AddCommandBindings()
UICommands.AddLyrics,
AddLyrics_Executed,
CanExecute));
Application.Current.MainWindow?.CommandBindings.Add(new CommandBinding(
UICommands.ClearLyrics,
ClearLyrics_Executed,
CanExecute));
}

public void ClearLyrics_Executed(object sender, ExecutedRoutedEventArgs e)
{
if(MessageBox.Show("确认清空所有歌词吗?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
{
LrcModel.Current.ClearAll();
}
}

public void AddLyrics_Executed(object sender, ExecutedRoutedEventArgs e)
{
EditLineDialog.ShowAddDialog();
string data = EditLineDialog.GetData();
if (string.IsNullOrEmpty(data)) return;
LrcModel.Current.AddLyrics(data);
LrcModel.Current.AddLyrics(data, EditLineDialog.GetIsDualLanguage());
}

private void CanExecute(object sender, CanExecuteRoutedEventArgs e)
Expand Down
12 changes: 9 additions & 3 deletions Views/PlaybackView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,25 @@ public partial class PlaybackView : UserControl, IDockSource

public PlaybackView()
{
InitializeComponent();
InitializeComponent();
VideoElement.PositionChanged += (o, args) =>
Position.Time = (long)args.Position.TotalMilliseconds;
VideoElement.MediaOpened += (o, args) =>
Position.Total = (long)args.Info.Duration.TotalMilliseconds;
VideoElement.MediaFailed += (o, args) => Console.WriteLine(@"[FFME] MediaFailed : " + args.ErrorException);
VideoElement.MediaEnded += async (o, args) =>
{
await VideoElement.Seek(TimeSpan.Zero);
await VideoElement.Play();
//await VideoElement.Seek(TimeSpan.Zero);
//await VideoElement.Play();
};
//VideoElement.RenderingVideo += RenderPreviewOnVideo;
Position.OnPositionActiveChanged += () => SeekToPosition(Position.Time);
PlaySpeedChanged += PlaybackView_PlaySpeedChanged;
}

private void PlaybackView_PlaySpeedChanged(double speed)
{
VideoElement.SpeedRatio = speed;
}

private void RenderPreviewOnVideo(object sender, RenderingVideoEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion Views/PlaybackViewCommandBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private async void Commands_LoadMedia(object sender, ExecutedRoutedEventArgs e)
Playing = true;
//MediaPlayer.Play(new Media(_libVLC, fileDialog.FileName));
await VideoElement.Open(new Uri(fileDialog.FileName));
await VideoElement.Play();
//await VideoElement.Play();
}

private async void Command_UnloadMedia(object sender, ExecutedRoutedEventArgs e)
Expand Down
44 changes: 43 additions & 1 deletion Views/PlaybackViewDataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ public bool MediaLoaded
OnPropertyChanged();
}
}
private double _playSpeed = 1;

public double PlaySpeed
{
get => _playSpeed;
set
{
if (value > 3) value = 3;
if (value < 0.1) value = 0.1;
_playSpeed = value;
OnPropertyChanged();
PlaySpeedChanged?.Invoke(_playSpeed);
}
}
public delegate void PlaySpeedChangedHandler(double speed);
public event PlaySpeedChangedHandler PlaySpeedChanged;
public Position Position { get; } = new Position();

private bool _playing;
Expand All @@ -40,15 +55,42 @@ public bool Playing
if (!MediaLoaded) return;
_playing = value;
if (value)
{
VideoElement.Play();
PlayButtonIconType = "Pause";
PlayButtonText = "暂停";
}
else
{
VideoElement.Pause();
PlayButtonIconType = "Run";
PlayButtonText = "播放";
}
if (value) ThemeService.Current.ChangeAccent(Accent.Orange);
else ThemeService.Current.ChangeAccent(Accent.Blue);
OnPropertyChanged();
}
}

public string _playButtonIconType = "Run";
public string PlayButtonIconType
{
get => _playButtonIconType;
set
{
_playButtonIconType = value;
OnPropertyChanged();
}
}
public string _playButtonText = "播放";
public string PlayButtonText
{
get => _playButtonText;
set
{
_playButtonText = value;
OnPropertyChanged();
}
}
#endregion

#region PropertyChanged
Expand Down
34 changes: 27 additions & 7 deletions Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
</MenuItem>
<MenuItem Header="编辑(_E)">
<MenuItem Command="{x:Static commands:UICommands.AddLyrics}" />
<MenuItem Command="{x:Static commands:UICommands.ClearLyrics}" />
<Separator/>
<MenuItem Command="{x:Static commands:UICommands.EditSkipData}" />
<MenuItem Command="{x:Static commands:UICommands.ReloadSkipData}" />
Expand Down Expand Up @@ -134,12 +135,31 @@

<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>

<StackPanel Grid.Column="1" HorizontalAlignment="Center" Orientation="Horizontal" Name="WndCaption"
<StackPanel x:Name="SpeedPanel" Orientation="Horizontal" VerticalAlignment="Center" Grid.Column="1" Margin="0,32,0,0">
<TextBlock VerticalAlignment="Center">倍速:</TextBlock>
<Slider
ToolTip="E/P加速 Q/I减速"
Width="100"
Minimum="0.1"
Maximum="3"
DataContext="{x:Static views:PlaybackView.Current}"
Value="{Binding PlaySpeed}"
></Slider>
<TextBlock DataContext="{x:Static views:PlaybackView.Current}" VerticalAlignment="Center">
<TextBlock.Text>
<Binding Path="PlaySpeed" StringFormat="×{0:f2}"/>
</TextBlock.Text>
</TextBlock>
<Button Margin="5,0,0,0" Name="ResetSpeed" Click="ResetSpeed_Click">
重置
</Button>
</StackPanel>
<StackPanel Grid.Column="2" HorizontalAlignment="Center" Orientation="Horizontal" Name="WndCaption"
DataContext="{x:Static views:PlaybackView.Current}">
<Grid
Name="Wnd7"
Expand Down Expand Up @@ -246,10 +266,10 @@
Height="80" Width="80" Padding="0" Name="Wnd4"
IsEnabled="{Binding MediaLoaded}" IsChecked="{Binding Playing}">
<Grid Height="80" Width="80">
<visualIcon:Icon Type="Run" Width="35" Height="35" Size="2"
<visualIcon:Icon Type="{Binding PlayButtonIconType}" Width="35" Height="35" Size="2"
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="4,0" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Bottom"
Margin="-2,0,0,6" Text="播放/暂停" />
Margin="-2,0,0,6" Text="{Binding PlayButtonText}" />
</Grid>
</ToggleButton>
<!--<ToggleButton HorizontalAlignment="Right" VerticalAlignment="Bottom"
Expand All @@ -263,7 +283,7 @@
</ToggleButton>-->
</StackPanel>

<Grid Grid.Column="2" Margin="0,32,0,0">
<Grid Grid.Column="3" Margin="0,32,0,0">
<Slider Margin="12" Name="Wnd6"
DataContext="{x:Static views:PlaybackView.Current}"
Minimum="0" Maximum="1"
Expand Down
7 changes: 6 additions & 1 deletion Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void OnLoaded(object sender, RoutedEventArgs e)
IntPtr hwnd = new WindowInteropHelper(this).Handle;
HwndSource.FromHwnd(hwnd).AddHook(WndProc);
wndList = new List<FrameworkElement>
{Wnd1, Wnd2, Wnd3, Wnd4, Wnd5, Wnd6, Wnd7};
{Wnd1, Wnd2, Wnd3, Wnd4, Wnd5, Wnd6, Wnd7, SpeedPanel};

PlaybackView.Current.DockControl.Show();
if (!LayoutHelper<Config>.ApplyLayout(DockManager, this)) LyricEditorView.Current.DockControl.Show();
Expand Down Expand Up @@ -147,5 +147,10 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
private const int WM_NCHITTEST = 0x0084;

#endregion

private void ResetSpeed_Click(object sender, RoutedEventArgs e)
{
PlaybackView.Current.PlaySpeed = 1.0;
}
}
}
9 changes: 9 additions & 0 deletions Windows/MainWindowCommandBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ private void TriggerKeyPress(Key key)
case Key.Right:
PlaybackView.Current.JumpDuration(+1000);
break;
case Key.Q:
case Key.I:
PlaybackView.Current.PlaySpeed -= 0.1;
break;
case Key.E:
case Key.P:
PlaybackView.Current.PlaySpeed += 0.1;
break;

}
}

Expand Down