├── .gitattributes ├── .gitignore ├── App.config ├── App.xaml ├── App.xaml.cs ├── Assets ├── Ruminoid.Trimmer.Colored.Transparent.ico └── Ruminoid.Trimmer.Half.Transparent.png ├── Commands ├── EditCommands.cs ├── MainCommands.cs ├── PlaybackCommands.cs └── ViewCommands.cs ├── Config.cs ├── Controls ├── ModeTypeControl.xaml └── ModeTypeControl.xaml.cs ├── Dialogs ├── EditLineDialog.xaml ├── EditLineDialog.xaml.cs ├── SaveFileDialog.xaml └── SaveFileDialog.xaml.cs ├── LICENSE ├── LibAss └── LibAssContext.cs ├── Models ├── Export.cs ├── LrcModel.cs └── ModeType.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── README.md ├── Resources └── SkipData.txt ├── Ruminoid.Trimmer.csproj ├── Styles └── ControlButtonStyles.xaml ├── Views ├── LyricEditorView.xaml ├── LyricEditorView.xaml.cs ├── LyricEditorViewCommandBinding.cs ├── LyricEditorViewDataContext.cs ├── PlaybackView.xaml ├── PlaybackView.xaml.cs ├── PlaybackViewCommandBinding.cs └── PlaybackViewDataContext.cs └── Windows ├── MainWindow.xaml ├── MainWindow.xaml.cs └── MainWindowCommandBindings.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /App.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Diagnostics; 6 | using System.Globalization; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Threading.Tasks; 10 | using System.Windows; 11 | using System.Xml; 12 | using MetroRadiance.UI; 13 | using Ruminoid.Trimmer.Windows; 14 | 15 | namespace Ruminoid.Trimmer 16 | { 17 | /// 18 | /// App.xaml 的交互逻辑 19 | /// 20 | public partial class App : Application 21 | { 22 | public App() 23 | { 24 | DispatcherUnhandledException += (sender, args) => 25 | { 26 | args.Handled = true; 27 | MessageBox.Show( 28 | args.Exception.Message, 29 | "灾难性故障", 30 | MessageBoxButton.OK, 31 | MessageBoxImage.Error, 32 | MessageBoxResult.OK); 33 | }; 34 | 35 | AppDomain.CurrentDomain.UnhandledException += (sender, args) => 36 | { 37 | MessageBox.Show( 38 | ((Exception)args.ExceptionObject)?.Message ?? "Exception", 39 | "灾难性故障", 40 | MessageBoxButton.OK, 41 | MessageBoxImage.Error, 42 | MessageBoxResult.OK); 43 | }; 44 | 45 | Ruminoid.Trimmer.Properties.Resources.Culture = CultureInfo.CurrentUICulture; 46 | 47 | Unosquare.FFME.Library.FFmpegDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Libraries\ffmpeg") + '\\'; 48 | 49 | if (MainWindow is null) MainWindow = new MainWindow(); 50 | MainWindow.Show(); 51 | 52 | Current.Dispatcher?.Invoke(() => ThemeService.Current.ChangeTheme(Theme.Dark)); 53 | Current.Dispatcher?.Invoke(() => ThemeService.Current.ChangeAccent(Accent.Blue)); 54 | 55 | } 56 | 57 | protected override void OnStartup(StartupEventArgs e) 58 | { 59 | base.OnStartup(e); 60 | 61 | ThemeService.Current.Register(this, Theme.Windows, Accent.Windows); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Assets/Ruminoid.Trimmer.Colored.Transparent.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ruminoid/Trimmer/97caf2a44198670082af6aeda24fd61f078c4747/Assets/Ruminoid.Trimmer.Colored.Transparent.ico -------------------------------------------------------------------------------- /Assets/Ruminoid.Trimmer.Half.Transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ruminoid/Trimmer/97caf2a44198670082af6aeda24fd61f078c4747/Assets/Ruminoid.Trimmer.Half.Transparent.png -------------------------------------------------------------------------------- /Commands/EditCommands.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Input; 7 | 8 | namespace Ruminoid.Trimmer.Commands 9 | { 10 | public static partial class UICommands 11 | { 12 | 13 | public static RoutedUICommand AddLyrics { get; } = new RoutedUICommand( 14 | "添加歌词(_A)...", 15 | "AddLyrics", 16 | typeof(UICommands), 17 | new InputGestureCollection(new List 18 | { 19 | new KeyGesture(Key.T, ModifierKeys.Control, "Ctrl+T"), 20 | new KeyGesture(Key.F5, ModifierKeys.None, "F5") 21 | })); 22 | 23 | public static RoutedUICommand EditSkipData { get; } = new RoutedUICommand( 24 | "编辑跳过单字(_E)", 25 | "EditSkipData", 26 | typeof(UICommands), 27 | new InputGestureCollection()); 28 | 29 | public static RoutedUICommand ReloadSkipData { get; } = new RoutedUICommand( 30 | "重载跳过单字(_R)", 31 | "ReloadSkipData", 32 | typeof(UICommands), 33 | new InputGestureCollection()); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Commands/MainCommands.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Input; 8 | 9 | namespace Ruminoid.Trimmer.Commands 10 | { 11 | public static partial class UICommands 12 | { 13 | 14 | public static RoutedUICommand Export { get; } = new RoutedUICommand( 15 | "导出ASS", 16 | "Export", 17 | typeof(UICommands), 18 | new InputGestureCollection(new Collection() 19 | { 20 | new KeyGesture(Key.S, ModifierKeys.Control | ModifierKeys.Shift, "Ctrl+Shift+S") 21 | })); 22 | 23 | public static RoutedUICommand ExitApp { get; } = new RoutedUICommand( 24 | "退出(_E)", 25 | "Exit", 26 | typeof(UICommands), 27 | new InputGestureCollection(new List() 28 | { 29 | new KeyGesture(Key.F4, ModifierKeys.Alt, "Alt+F4") 30 | })); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Commands/PlaybackCommands.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Input; 7 | 8 | namespace Ruminoid.Trimmer.Commands 9 | { 10 | public static partial class UICommands 11 | { 12 | 13 | public static RoutedUICommand LoadMedia { get; } = new RoutedUICommand( 14 | "加载媒体(_L)", 15 | "LoadMedia", 16 | typeof(UICommands), 17 | new InputGestureCollection(new List 18 | { 19 | new KeyGesture(Key.L, ModifierKeys.Control, "Ctrl+L"), 20 | new KeyGesture(Key.F7, ModifierKeys.None, "F7") 21 | })); 22 | 23 | public static RoutedUICommand UnloadMedia { get; } = new RoutedUICommand( 24 | "卸载媒体(_U)", 25 | "UnloadMedia", 26 | typeof(UICommands), 27 | new InputGestureCollection(new List 28 | { 29 | new KeyGesture(Key.U, ModifierKeys.Control, "Ctrl+U") 30 | })); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Commands/ViewCommands.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Input; 7 | 8 | namespace Ruminoid.Trimmer.Commands 9 | { 10 | public static partial class UICommands 11 | { 12 | 13 | public static RoutedUICommand ShowLyricsEditorView { get; } = new RoutedUICommand( 14 | "编辑(_E)", 15 | "ShowLyricsEditorView", 16 | typeof(UICommands), 17 | new InputGestureCollection(new List 18 | { 19 | new KeyGesture(Key.F3, ModifierKeys.None, "F3") 20 | })); 21 | 22 | public static RoutedUICommand ShowPlaybackView { get; } = new RoutedUICommand( 23 | "回放(_P)", 24 | "ShowPlaybackView", 25 | typeof(UICommands), 26 | new InputGestureCollection(new List 27 | { 28 | new KeyGesture(Key.F4, ModifierKeys.None, "F4") 29 | })); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Runtime.CompilerServices; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using Newtonsoft.Json; 9 | using Ruminoid.Common.Helpers; 10 | 11 | namespace Ruminoid.Trimmer 12 | { 13 | [RuminoidProduct("Trimmer")] 14 | [JsonObject(MemberSerialization.OptIn)] 15 | public class Config : INotifyPropertyChanged 16 | { 17 | #region Current 18 | 19 | public static Config Current { get; set; } = ConfigHelper.OpenConfig(); 20 | 21 | #endregion 22 | 23 | #region MainWindow 24 | 25 | [JsonProperty] 26 | private bool hideWelcome; 27 | 28 | public bool HideWelcome 29 | { 30 | get => hideWelcome; 31 | set 32 | { 33 | hideWelcome = value; 34 | OnPropertyChanged(); 35 | } 36 | } 37 | 38 | #endregion 39 | 40 | #region PropertyChanged 41 | 42 | public event PropertyChangedEventHandler PropertyChanged; 43 | 44 | protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) 45 | { 46 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 47 | } 48 | 49 | #endregion 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Controls/ModeTypeControl.xaml: -------------------------------------------------------------------------------- 1 |  16 | 17 | 18 | 19 | 20 | 21 | 27 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Controls/ModeTypeControl.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.ComponentModel; 5 | using System.Linq; 6 | using System.Runtime.CompilerServices; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows; 10 | using System.Windows.Controls; 11 | using System.Windows.Data; 12 | using System.Windows.Documents; 13 | using System.Windows.Input; 14 | using System.Windows.Media; 15 | using System.Windows.Media.Imaging; 16 | using System.Windows.Navigation; 17 | using System.Windows.Shapes; 18 | using Ruminoid.Trimmer.Models; 19 | 20 | namespace Ruminoid.Trimmer.Controls 21 | { 22 | /// 23 | /// ModeTypeControl.xaml 的交互逻辑 24 | /// 25 | public partial class ModeTypeControl : UserControl, INotifyPropertyChanged 26 | { 27 | 28 | public ModeTypeControl() 29 | { 30 | InitializeComponent(); 31 | } 32 | 33 | #region DataContext 34 | 35 | public static readonly DependencyProperty TypeListProperty = DependencyProperty.Register( 36 | "TypeList", 37 | typeof(ObservableCollection), 38 | typeof(ModeTypeControl), 39 | new PropertyMetadata(default(ObservableCollection))); 40 | 41 | public ObservableCollection TypeList 42 | { 43 | get => (ObservableCollection)GetValue(TypeListProperty); 44 | set 45 | { 46 | SetValue(TypeListProperty, value); 47 | OnPropertyChanged(); 48 | } 49 | } 50 | 51 | public static readonly DependencyProperty SelectedTypeProperty = DependencyProperty.Register( 52 | "SelectedType", typeof(ModeType), typeof(ModeTypeControl), new PropertyMetadata(default(ModeType))); 53 | 54 | public ModeType SelectedType 55 | { 56 | get => (ModeType)GetValue(SelectedTypeProperty); 57 | set 58 | { 59 | SetValue(SelectedTypeProperty, value); 60 | OnPropertyChanged(); 61 | } 62 | } 63 | 64 | #endregion 65 | 66 | #region PropertyChanged 67 | 68 | public event PropertyChangedEventHandler PropertyChanged; 69 | 70 | protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) 71 | { 72 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 73 | } 74 | 75 | #endregion 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Dialogs/EditLineDialog.xaml: -------------------------------------------------------------------------------- 1 |  25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 54 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 76 | 77 | 78 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 91 | 92 | 95 | 179 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /Views/LyricEditorView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | using Ruminoid.Trimmer.Models; 16 | using YDock.Interface; 17 | 18 | namespace Ruminoid.Trimmer.Views 19 | { 20 | /// 21 | /// LyricEditorView.xaml 的交互逻辑 22 | /// 23 | public partial class LyricEditorView : UserControl, IDockSource 24 | { 25 | 26 | public LyricEditorView() 27 | { 28 | 29 | InitializeComponent(); 30 | 31 | Loaded += OnLoaded; 32 | 33 | } 34 | 35 | #region Loaded 36 | 37 | private void OnLoaded(object sender, RoutedEventArgs e) 38 | { 39 | LrcModel.Current.SetTargeting += OnSetTargeting; 40 | } 41 | 42 | #endregion 43 | 44 | #region Current 45 | 46 | public static LyricEditorView Current = new LyricEditorView(); 47 | 48 | #endregion 49 | 50 | #region DockSource 51 | 52 | public IDockControl DockControl { get; set; } 53 | public string Header => "编辑"; 54 | public ImageSource Icon => null; 55 | 56 | #endregion 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Views/LyricEditorViewCommandBinding.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Input; 9 | using Ruminoid.Common.Timing; 10 | using Ruminoid.Trimmer.Commands; 11 | using Ruminoid.Trimmer.Dialogs; 12 | using Ruminoid.Trimmer.Models; 13 | 14 | namespace Ruminoid.Trimmer.Views 15 | { 16 | public partial class LyricEditorView 17 | { 18 | 19 | public void AddCommandBindings() 20 | { 21 | Application.Current.MainWindow?.CommandBindings.Add(new CommandBinding( 22 | UICommands.AddLyrics, 23 | AddLyrics_Executed, 24 | CanExecute)); 25 | } 26 | 27 | public void AddLyrics_Executed(object sender, ExecutedRoutedEventArgs e) 28 | { 29 | EditLineDialog.ShowAddDialog(); 30 | string data = EditLineDialog.GetData(); 31 | if (string.IsNullOrEmpty(data)) return; 32 | LrcModel.Current.AddLyrics(data); 33 | } 34 | 35 | private void CanExecute(object sender, CanExecuteRoutedEventArgs e) 36 | { 37 | e.CanExecute = true; 38 | e.Handled = true; 39 | } 40 | 41 | #region Operations 42 | 43 | public void Apply() => LrcModel.Current.Apply(new Position(PlaybackView.Current.PositionRealTime)); 44 | 45 | public void Undo() => LrcModel.Current.Undo(); 46 | 47 | public void Skip() => LrcModel.Current.Skip(); 48 | 49 | public void Break() => LrcModel.Current.Break(new Position(PlaybackView.Current.PositionRealTime)); 50 | 51 | private void EditLineButtonBase_OnClick(object sender, RoutedEventArgs e) 52 | { 53 | Button s = sender as Button; 54 | if (!(s?.DataContext is LrcLine line)) return; 55 | EditLineDialog.ShowEditDialog((line.Origin ?? "").Replace("\r", "").Replace("\n", "")); 56 | string data = EditLineDialog.GetData(); 57 | if (string.IsNullOrEmpty(data)) return; 58 | LrcModel.Current.ResetLineData(line, data); 59 | } 60 | 61 | private void DeleteLineButtonBase_OnClick(object sender, RoutedEventArgs e) 62 | { 63 | MessageBoxResult result = MessageBox.Show( 64 | "删除这行?", 65 | "删除", 66 | MessageBoxButton.YesNo, 67 | MessageBoxImage.Warning, 68 | MessageBoxResult.No); 69 | if (result != MessageBoxResult.Yes) return; 70 | if (!(sender is Button s)) return; 71 | LrcLine line = s.DataContext as LrcLine; 72 | LrcModel.Current.RemoveLine(line); 73 | } 74 | 75 | #endregion 76 | 77 | #region Auto Scroll 78 | 79 | private void OnSetTargeting(LrcLine lrcline) 80 | { 81 | try 82 | { 83 | RootView.ScrollIntoView(lrcline); 84 | } 85 | catch (Exception) 86 | { 87 | // Ignore 88 | } 89 | } 90 | 91 | #endregion 92 | 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Views/LyricEditorViewDataContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Ruminoid.Trimmer.Views 8 | { 9 | public partial class LyricEditorView 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Views/PlaybackView.xaml: -------------------------------------------------------------------------------- 1 |  17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Views/PlaybackView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Threading; 14 | using Ruminoid.Trimmer.LibAss; 15 | using Unosquare.FFME.Common; 16 | using YDock.Interface; 17 | using System.Windows.Navigation; 18 | using System.Windows.Shapes; 19 | using Microsoft.WindowsAPICodePack.Dialogs; 20 | using Ruminoid.Trimmer.Commands; 21 | using Ruminoid.Trimmer.Models; 22 | 23 | namespace Ruminoid.Trimmer.Views 24 | { 25 | /// 26 | /// PlaybackView.xaml 的交互逻辑 27 | /// 28 | public partial class PlaybackView : UserControl, IDockSource 29 | { 30 | 31 | public PlaybackView() 32 | { 33 | InitializeComponent(); 34 | VideoElement.PositionChanged += (o, args) => 35 | Position.Time = (long)args.Position.TotalMilliseconds; 36 | VideoElement.MediaOpened += (o, args) => 37 | Position.Total = (long)args.Info.Duration.TotalMilliseconds; 38 | VideoElement.MediaFailed += (o, args) => Console.WriteLine(@"[FFME] MediaFailed : " + args.ErrorException); 39 | VideoElement.MediaEnded += async (o, args) => 40 | { 41 | await VideoElement.Seek(TimeSpan.Zero); 42 | await VideoElement.Play(); 43 | }; 44 | //VideoElement.RenderingVideo += RenderPreviewOnVideo; 45 | Position.OnPositionActiveChanged += () => SeekToPosition(Position.Time); 46 | } 47 | 48 | private void RenderPreviewOnVideo(object sender, RenderingVideoEventArgs e) 49 | { 50 | //_libAss.RenderAndBlend((int)e.Clock.TotalMilliseconds, e.Bitmap); 51 | } 52 | 53 | #region Current 54 | 55 | public static PlaybackView Current { get; } = new PlaybackView(); 56 | 57 | #endregion 58 | 59 | //private LibASSContext _libAss = new LibASSContext(); 60 | 61 | #region DockSource 62 | 63 | public IDockControl DockControl { get; set; } 64 | public string Header => "回放"; 65 | public ImageSource Icon => null; 66 | 67 | #endregion 68 | 69 | public long PositionRealTime => (long)VideoElement.Position.TotalMilliseconds; 70 | 71 | private void SeekToPosition(long time) 72 | { 73 | var target = TimeSpan.FromMilliseconds(time); 74 | if (target.TotalMilliseconds < 0) 75 | target = TimeSpan.Zero; 76 | VideoElement.Seek(target).GetAwaiter().GetResult(); 77 | Position.Time = (long)target.TotalMilliseconds; 78 | } 79 | 80 | public void JumpDuration(long duration) 81 | { 82 | var target = VideoElement.Position + TimeSpan.FromMilliseconds(duration); 83 | if (target.TotalMilliseconds < 0) 84 | target = TimeSpan.Zero; 85 | VideoElement.Seek(target).GetAwaiter().GetResult(); 86 | Position.Time = (long)target.TotalMilliseconds; 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Views/PlaybackViewCommandBinding.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Input; 8 | using Microsoft.WindowsAPICodePack.Dialogs; 9 | using Ruminoid.Trimmer.Commands; 10 | 11 | namespace Ruminoid.Trimmer.Views 12 | { 13 | public partial class PlaybackView 14 | { 15 | 16 | public void AddCommandBindings() 17 | { 18 | 19 | #region Playback 20 | 21 | Application.Current.MainWindow?.CommandBindings.Add(new CommandBinding( 22 | UICommands.LoadMedia, 23 | Commands_LoadMedia, 24 | CanExecute)); 25 | 26 | Application.Current.MainWindow?.CommandBindings.Add(new CommandBinding( 27 | UICommands.UnloadMedia, 28 | Command_UnloadMedia, 29 | (sender, args) => 30 | { 31 | args.CanExecute = MediaLoaded; 32 | args.Handled = true; 33 | })); 34 | 35 | #endregion 36 | 37 | } 38 | 39 | #region Playback 40 | 41 | private async void Commands_LoadMedia(object sender, ExecutedRoutedEventArgs e) 42 | { 43 | Command_UnloadMedia(null, null); 44 | CommonOpenFileDialog fileDialog = new CommonOpenFileDialog 45 | { 46 | Title = "打开媒体文件", 47 | DefaultDirectory = Environment.CurrentDirectory, 48 | IsFolderPicker = false, 49 | AllowNonFileSystemItems = true, 50 | EnsurePathExists = true, 51 | Multiselect = false, 52 | //Filters = { new CommonFileDialogFilter("波形音频", ".wav") }, 53 | EnsureFileExists = true 54 | }; 55 | if (fileDialog.ShowDialog() != CommonFileDialogResult.Ok) 56 | return; 57 | if (!DockControl?.IsVisible ?? true) 58 | DockControl?.Show(); 59 | MediaLoaded = true; 60 | Playing = true; 61 | //MediaPlayer.Play(new Media(_libVLC, fileDialog.FileName)); 62 | await VideoElement.Open(new Uri(fileDialog.FileName)); 63 | await VideoElement.Play(); 64 | } 65 | 66 | private async void Command_UnloadMedia(object sender, ExecutedRoutedEventArgs e) 67 | { 68 | //MediaPlayer.Stop(); 69 | await VideoElement.Stop(); 70 | await VideoElement.Close(); 71 | MediaLoaded = false; 72 | Position.Time = 0; 73 | } 74 | 75 | #endregion 76 | 77 | private void CanExecute(object sender, CanExecuteRoutedEventArgs e) 78 | { 79 | e.CanExecute = true; 80 | e.Handled = true; 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Views/PlaybackViewDataContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Runtime.CompilerServices; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using MetroRadiance.UI; 9 | using Ruminoid.Common.Timing; 10 | using Ruminoid.Trimmer.Models; 11 | 12 | namespace Ruminoid.Trimmer.Views 13 | { 14 | public partial class PlaybackView : INotifyPropertyChanged 15 | { 16 | 17 | #region PlaybackControl 18 | 19 | private bool _mediaLoaded; 20 | 21 | public bool MediaLoaded 22 | { 23 | get => _mediaLoaded; 24 | set 25 | { 26 | _mediaLoaded = value; 27 | OnPropertyChanged(); 28 | } 29 | } 30 | 31 | public Position Position { get; } = new Position(); 32 | 33 | private bool _playing; 34 | 35 | public bool Playing 36 | { 37 | get => _playing; 38 | set 39 | { 40 | if (!MediaLoaded) return; 41 | _playing = value; 42 | if (value) 43 | VideoElement.Play(); 44 | else 45 | VideoElement.Pause(); 46 | if (value) ThemeService.Current.ChangeAccent(Accent.Orange); 47 | else ThemeService.Current.ChangeAccent(Accent.Blue); 48 | OnPropertyChanged(); 49 | } 50 | } 51 | 52 | #endregion 53 | 54 | #region PropertyChanged 55 | 56 | public event PropertyChangedEventHandler PropertyChanged; 57 | 58 | protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) 59 | { 60 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 61 | } 62 | 63 | #endregion 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Windows/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 57 | 59 | 60 | 61 | 62 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 97 | 102 | 107 | 112 | 117 | 122 | 127 | 128 | 129 | 130 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 144 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 167 | 176 | 182 | 183 | 184 | 193 | 202 | 211 | 220 | 221 | 222 | 223 | 224 | 226 | 228 | 229 | 230 | 231 | 233 | 235 | 236 | 237 | 238 | 240 | 242 | 243 | 244 | 245 | 248 | 249 | 251 | 253 | 254 | 255 | 264 | 265 | 266 | 267 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 282 | 283 | 284 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | -------------------------------------------------------------------------------- /Windows/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows; 10 | using System.Windows.Controls; 11 | using System.Windows.Controls.Primitives; 12 | using System.Windows.Data; 13 | using System.Windows.Documents; 14 | using System.Windows.Input; 15 | using System.Windows.Interop; 16 | using System.Windows.Media; 17 | using System.Windows.Media.Imaging; 18 | using System.Windows.Navigation; 19 | using System.Xml.Linq; 20 | using Enterwell.Clients.Wpf.Notifications; 21 | using Ruminoid.Common.Helpers; 22 | using Ruminoid.Trimmer.Commands; 23 | using Ruminoid.Trimmer.Views; 24 | 25 | namespace Ruminoid.Trimmer.Windows 26 | { 27 | /// 28 | /// MainWindow.xaml 的交互逻辑 29 | /// 30 | public partial class MainWindow 31 | { 32 | public MainWindow() 33 | { 34 | InitializeComponent(); 35 | 36 | Loaded += OnLoaded; 37 | 38 | Closing += OnClosing; 39 | 40 | Closed += (sender, args) => Application.Current.Shutdown(0); 41 | 42 | AddCommandBindings(); 43 | 44 | #region Document Register 45 | 46 | DockManager.RegisterDocument(LyricEditorView.Current); 47 | DockManager.RegisterDock(PlaybackView.Current); 48 | 49 | #endregion 50 | } 51 | 52 | #region Notifications 53 | 54 | public NotificationMessageManager NotificationManager { get; } = new NotificationMessageManager(); 55 | 56 | #endregion 57 | 58 | #region Closing 59 | 60 | private void OnClosing(object sender, CancelEventArgs e) 61 | { 62 | e.Cancel = ExitApp(); 63 | if (e.Cancel) return; 64 | LayoutHelper.SaveLayoutAndDispose(DockManager, this); 65 | ConfigHelper.SaveConfig(Config.Current); 66 | } 67 | 68 | #endregion 69 | 70 | #region Loaded 71 | 72 | private void OnLoaded(object sender, RoutedEventArgs e) 73 | { 74 | IntPtr hwnd = new WindowInteropHelper(this).Handle; 75 | HwndSource.FromHwnd(hwnd).AddHook(WndProc); 76 | wndList = new List 77 | {Wnd1, Wnd2, Wnd3, Wnd4, Wnd5, Wnd6, Wnd7}; 78 | 79 | PlaybackView.Current.DockControl.Show(); 80 | if (!LayoutHelper.ApplyLayout(DockManager, this)) LyricEditorView.Current.DockControl.Show(); 81 | 82 | //sliderBinding = new Binding(); 83 | //sliderBinding.Source = PlaybackView.Current.Position; 84 | //sliderBinding.Path = new PropertyPath("Percentage"); 85 | 86 | if(Config.Current.HideWelcome) return; 87 | 88 | CheckBox welcomeBox = new CheckBox 89 | { 90 | Margin = new Thickness(12, 8, 12, 8), 91 | HorizontalAlignment = HorizontalAlignment.Left, 92 | Content = "不要再提醒。" 93 | }; 94 | welcomeBox.Checked += (o, args) => Config.Current.HideWelcome = true; 95 | welcomeBox.Unchecked += (o, args) => Config.Current.HideWelcome = false; 96 | NotificationManager 97 | .CreateMessage() 98 | .Accent("#007ACC") 99 | .Background("#333") 100 | .HasMessage("欢迎回来!点击“添加歌词”或轻敲 Ctrl+T 以开始。") 101 | .Dismiss().WithButton("添加歌词", button => 102 | { 103 | LyricEditorView.Current.AddLyrics_Executed(null, null); 104 | }) 105 | .Dismiss().WithButton("消除", button => { }) 106 | .WithAdditionalContent(ContentLocation.Bottom, 107 | new Border 108 | { 109 | BorderThickness = new Thickness(0, 1, 0, 0), 110 | BorderBrush = new SolidColorBrush(Color.FromArgb(128, 28, 28, 28)), 111 | Child = welcomeBox 112 | }) 113 | .Queue(); 114 | } 115 | 116 | #endregion 117 | 118 | #region CaptionBar Hook 119 | 120 | private List wndList; 121 | 122 | private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) 123 | { 124 | if (msg == WM_NCHITTEST) 125 | { 126 | if (wndList is null) return IntPtr.Zero; 127 | Point p = new Point(); 128 | int pInt = lParam.ToInt32(); 129 | p.X = (pInt << 16) >> 16; 130 | p.Y = pInt >> 16; 131 | if (WndCaption.PointFromScreen(p).Y > WndCaption.ActualHeight) return IntPtr.Zero; 132 | foreach (FrameworkElement element in wndList) 133 | { 134 | Point rel = element.PointFromScreen(p); 135 | if (rel.X >= 0 && rel.X <= element.ActualWidth && rel.Y >= 0 && rel.Y <= element.ActualHeight) 136 | { 137 | return IntPtr.Zero; 138 | } 139 | } 140 | handled = true; 141 | return new IntPtr(2); 142 | } 143 | 144 | return IntPtr.Zero; 145 | } 146 | 147 | private const int WM_NCHITTEST = 0x0084; 148 | 149 | #endregion 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /Windows/MainWindowCommandBindings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Runtime.CompilerServices; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows; 10 | using System.Windows.Controls; 11 | using System.Windows.Input; 12 | using Ruminoid.Trimmer.Commands; 13 | using Ruminoid.Trimmer.Dialogs; 14 | using Ruminoid.Trimmer.Models; 15 | using Ruminoid.Trimmer.Views; 16 | 17 | namespace Ruminoid.Trimmer.Windows 18 | { 19 | public partial class MainWindow : INotifyPropertyChanged 20 | { 21 | private void AddCommandBindings() 22 | { 23 | #region File 24 | 25 | CommandBindings.Add(new CommandBinding( 26 | UICommands.Export, 27 | Command_Export, 28 | (sender, args) => 29 | { 30 | args.CanExecute = LrcModel.Current.IsModified; 31 | args.Handled = true; 32 | })); 33 | 34 | CommandBindings.Add(new CommandBinding( 35 | UICommands.ExitApp, 36 | Command_ExitApp, 37 | CanExecute)); 38 | 39 | #endregion 40 | 41 | #region Edit 42 | 43 | CommandBindings.Add(new CommandBinding( 44 | UICommands.EditSkipData, 45 | (sender, args) => Process.Start(LrcModel.UserSkipDataPath), 46 | CanExecute)); 47 | 48 | CommandBindings.Add(new CommandBinding( 49 | UICommands.ReloadSkipData, 50 | (sender, args) => LrcModel.ReloadSkipData(), 51 | CanExecute)); 52 | 53 | #endregion 54 | 55 | #region View 56 | 57 | CommandBindings.Add(new CommandBinding( 58 | UICommands.ShowLyricsEditorView, 59 | (sender, args) => LyricEditorView.Current.DockControl?.Show(), 60 | CanExecute)); 61 | 62 | CommandBindings.Add(new CommandBinding( 63 | UICommands.ShowPlaybackView, 64 | (sender, args) => PlaybackView.Current.DockControl?.Show(), 65 | CanExecute)); 66 | 67 | #endregion 68 | 69 | #region Other Window 70 | 71 | LyricEditorView.Current.AddCommandBindings(); 72 | PlaybackView.Current.AddCommandBindings(); 73 | 74 | #endregion 75 | } 76 | 77 | #region File 78 | 79 | private void Command_Export(object sender, ExecutedRoutedEventArgs e) => new SaveFileDialog().ShowDialog(); 80 | 81 | private void Command_ExitApp(object sender, ExecutedRoutedEventArgs e) => Close(); 82 | 83 | /// 84 | /// 请求退出应用。 85 | /// 86 | /// 是否获得了句柄。 87 | private bool ExitApp() 88 | { 89 | if (!LrcModel.Current.IsModified) 90 | return false; 91 | MessageBoxResult result = MessageBox.Show( 92 | "存在未保存的修改。是否保存?", 93 | "修改未保存", 94 | MessageBoxButton.YesNoCancel, 95 | MessageBoxImage.Warning, 96 | MessageBoxResult.Yes); 97 | switch (result) 98 | { 99 | case MessageBoxResult.Yes: 100 | Command_Export(null, null); 101 | return false; 102 | case MessageBoxResult.No: 103 | return false; 104 | default: 105 | return true; 106 | } 107 | } 108 | 109 | #endregion 110 | 111 | private void CanExecute(object sender, CanExecuteRoutedEventArgs e) 112 | { 113 | e.CanExecute = true; 114 | e.Handled = true; 115 | } 116 | 117 | #region KeyDown 118 | 119 | private void MainWindow_OnPreviewKeyDown(object sender, KeyEventArgs e) 120 | { 121 | if (!IsHandling) return; 122 | if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) return; 123 | if ( 124 | e.Key == Key.Z || 125 | e.Key == Key.OemComma || 126 | e.Key == Key.X || 127 | e.Key == Key.OemPeriod || 128 | e.Key == Key.Space || 129 | e.Key == Key.A || 130 | e.Key == Key.K || 131 | e.Key == Key.Left || 132 | e.Key == Key.D || 133 | e.Key == Key.OemSemicolon || 134 | e.Key == Key.Right || 135 | e.Key == Key.W || 136 | e.Key == Key.O || 137 | e.Key == Key.Up || 138 | e.Key == Key.S || 139 | e.Key == Key.L || 140 | e.Key == Key.Down) e.Handled = true; 141 | switch (e.Key) 142 | { 143 | case Key.A: 144 | case Key.K: 145 | case Key.Left: 146 | IsLeftPressed = true; 147 | break; 148 | case Key.D: 149 | case Key.OemSemicolon: 150 | case Key.Right: 151 | IsRightPressed = true; 152 | break; 153 | case Key.W: 154 | case Key.O: 155 | case Key.Up: 156 | IsUpPressed = true; 157 | break; 158 | case Key.S: 159 | case Key.L: 160 | case Key.Down: 161 | IsDownPressed = true; 162 | break; 163 | case Key.Z: 164 | case Key.OemComma: 165 | IsSkipPressed = true; 166 | break; 167 | case Key.X: 168 | case Key.OemPeriod: 169 | IsReturnPressed = true; 170 | break; 171 | } 172 | TriggerKeyPress(e.Key); 173 | } 174 | 175 | private void MainWindow_OnPreviewKeyUp(object sender, KeyEventArgs e) 176 | { 177 | if (!IsHandling) return; 178 | if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) return; 179 | switch (e.Key) 180 | { 181 | case Key.A: 182 | case Key.K: 183 | case Key.Left: 184 | IsLeftPressed = false; 185 | break; 186 | case Key.D: 187 | case Key.OemSemicolon: 188 | case Key.Right: 189 | IsRightPressed = false; 190 | break; 191 | case Key.W: 192 | case Key.O: 193 | case Key.Up: 194 | IsUpPressed = false; 195 | break; 196 | case Key.S: 197 | case Key.L: 198 | case Key.Down: 199 | IsDownPressed = false; 200 | break; 201 | case Key.Z: 202 | case Key.OemComma: 203 | IsSkipPressed = false; 204 | break; 205 | case Key.X: 206 | case Key.OemPeriod: 207 | IsReturnPressed = false; 208 | break; 209 | } 210 | } 211 | 212 | private void WwControl_OnClick(object sender, RoutedEventArgs e) 213 | { 214 | if (!IsHandling) return; 215 | Button s = sender as Button; 216 | switch (s?.Tag) 217 | { 218 | case "Left": 219 | TriggerKeyPress(Key.Left); 220 | break; 221 | case "Right": 222 | TriggerKeyPress(Key.Right); 223 | break; 224 | case "Up": 225 | TriggerKeyPress(Key.Up); 226 | break; 227 | case "Down": 228 | TriggerKeyPress(Key.Down); 229 | break; 230 | case "Skip": 231 | TriggerKeyPress(Key.Z); 232 | break; 233 | case "Return": 234 | TriggerKeyPress(Key.X); 235 | return; 236 | } 237 | } 238 | 239 | private void TriggerKeyPress(Key key) 240 | { 241 | switch (key) 242 | { 243 | case Key.Space: 244 | if (PlaybackView.Current.MediaLoaded) PlaybackView.Current.Playing = !PlaybackView.Current.Playing; 245 | break; 246 | case Key.S: 247 | case Key.L: 248 | case Key.Down: 249 | LyricEditorView.Current.Apply(); 250 | break; 251 | case Key.W: 252 | case Key.O: 253 | case Key.Up: 254 | LyricEditorView.Current.Undo(); 255 | break; 256 | case Key.Z: 257 | case Key.OemComma: 258 | LyricEditorView.Current.Skip(); 259 | break; 260 | case Key.X: 261 | case Key.OemPeriod: 262 | LyricEditorView.Current.Break(); 263 | break; 264 | case Key.A: 265 | case Key.K: 266 | case Key.Left: 267 | PlaybackView.Current.JumpDuration(-1000); 268 | break; 269 | case Key.D: 270 | case Key.OemSemicolon: 271 | case Key.Right: 272 | PlaybackView.Current.JumpDuration(+1000); 273 | break; 274 | } 275 | } 276 | 277 | #endregion 278 | 279 | #region DataContext 280 | 281 | private bool _isHandling = true; 282 | 283 | public bool IsHandling 284 | { 285 | get => _isHandling; 286 | set 287 | { 288 | _isHandling = value; 289 | OnPropertyChanged(); 290 | } 291 | } 292 | 293 | private bool _isLeftPressed; 294 | 295 | public bool IsLeftPressed 296 | { 297 | get => _isLeftPressed; 298 | set 299 | { 300 | _isLeftPressed = value; 301 | OnPropertyChanged(); 302 | } 303 | } 304 | 305 | private bool _isRightPressed; 306 | 307 | public bool IsRightPressed 308 | { 309 | get => _isRightPressed; 310 | set 311 | { 312 | _isRightPressed = value; 313 | OnPropertyChanged(); 314 | } 315 | } 316 | 317 | private bool _isUpPressed; 318 | 319 | public bool IsUpPressed 320 | { 321 | get => _isUpPressed; 322 | set 323 | { 324 | _isUpPressed = value; 325 | OnPropertyChanged(); 326 | } 327 | } 328 | 329 | private bool _isDownPressed; 330 | 331 | public bool IsDownPressed 332 | { 333 | get => _isDownPressed; 334 | set 335 | { 336 | _isDownPressed = value; 337 | OnPropertyChanged(); 338 | } 339 | } 340 | 341 | private bool _isSkipPressed; 342 | 343 | public bool IsSkipPressed 344 | { 345 | get => _isSkipPressed; 346 | set 347 | { 348 | _isSkipPressed = value; 349 | OnPropertyChanged(); 350 | } 351 | } 352 | 353 | private bool _isReturnPressed; 354 | 355 | public bool IsReturnPressed 356 | { 357 | get => _isReturnPressed; 358 | set 359 | { 360 | _isReturnPressed = value; 361 | OnPropertyChanged(); 362 | } 363 | } 364 | 365 | #endregion 366 | 367 | #region PropertyChanged 368 | 369 | public event PropertyChangedEventHandler PropertyChanged; 370 | 371 | protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) 372 | { 373 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 374 | } 375 | 376 | #endregion 377 | 378 | } 379 | } 380 | --------------------------------------------------------------------------------