diff --git a/butterflow-ui/ButterflowWrapper.cs b/butterflow-ui/ButterflowWrapper.cs index 1fe2b20..d2efbeb 100644 --- a/butterflow-ui/ButterflowWrapper.cs +++ b/butterflow-ui/ButterflowWrapper.cs @@ -1,4 +1,5 @@ -using System; +using csmic; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -17,8 +18,12 @@ namespace butterflow_ui /// The RegEx string for matching probed resolution. private const string REGEX_RESOLUTION = @"Resolution\s*:\s(?\d+)x(?\d+)"; - /// The RegEx string for matching the probed playback rate.. + /// The RegEx string for matching the probed playback rate. private const string REGEX_RATE = @"Rate\s*:\s(?\d+\.\d+) fps"; + /// The RegEx string for detecting progress made when rendering a video. + private const string REGEX_PROGRESS = @"To write\:\s*\w*\s*\w*\,*\w*\s*(?\d+\.*\d*)%"; + /// An alternative RegEx string for detecting progress made when rendering a video. + private const string REGEX_PROGRESS_ALT = @"\\d+\.*\d*)%\>"; /// Full pathname of the butterflow executable file. private Lazy executablePath = new Lazy(() => Path.Combine(Directory.GetCurrentDirectory(), "ThirdPartyCompiled", "butterflow.exe")); @@ -26,6 +31,12 @@ namespace butterflow_ui private string consoleOutput = string.Empty; /// True if butterflow is running, false if not. private bool isRunning; + /// The progress percentage as reported by butterflow. + private double progressPercentage; + /// The running butterflow process. + private Process runningProcess; + /// An input interpreter used for converting string values to numeric values. + private InputInterpreter interpreter = new InputInterpreter(); /// Event queue for all listeners interested in ParsedConsoleOutputRecieved events. public event EventHandler ParsedConsoleOutputRecieved; @@ -48,7 +59,7 @@ namespace butterflow_ui } } - /// Gets or sets a value indicating whether butterflow is currently running. + /// Gets a value indicating whether butterflow is currently running. /// True if butterflow is running, false if not. public bool IsRunning { @@ -56,13 +67,28 @@ namespace butterflow_ui { return this.isRunning; } - set + private set { this.isRunning = value; OnPropertyChanged(); } } + /// Gets the progress percentage as reported by butterflow. + /// The progress percentage as reported by butterflow. + public double ProgressPercentage + { + get + { + return this.progressPercentage; + } + private set + { + this.progressPercentage = value; + OnPropertyChanged(); + } + } + #endregion #region Methods @@ -76,6 +102,15 @@ namespace butterflow_ui Run(arguments); } + /// Kills the running instance of butterflow, cancelling its current operation. + public void Cancel() + { + if(this.IsRunning && this.runningProcess != null) + { + this.runningProcess.Kill(); + } + } + /// Probes a video file. /// The video file to be probed. public void Probe(string videoFile) @@ -107,6 +142,7 @@ namespace butterflow_ui process.BeginErrorReadLine(); this.IsRunning = true; + this.runningProcess = process; } } @@ -116,6 +152,7 @@ namespace butterflow_ui private void Process_Exited(object sender, EventArgs e) { this.IsRunning = false; + this.runningProcess = null; } /// @@ -131,7 +168,7 @@ namespace butterflow_ui return; } - //Test for resolution + // Test for resolution var regex = new Regex(REGEX_RESOLUTION); foreach (Match match in regex.Matches(consoleOutput)) { @@ -142,7 +179,7 @@ namespace butterflow_ui OnParsedConsoleOutputRecieved(ButterflowOutputType.Height, height, consoleOutput); } - //Test for playback rate + // Test for playback rate regex = new Regex(REGEX_RATE); foreach(Match match in regex.Matches(consoleOutput)) { @@ -150,6 +187,29 @@ namespace butterflow_ui OnParsedConsoleOutputRecieved(ButterflowOutputType.Rate, rate, consoleOutput); } + + // Test for progress being made when rendering a video + regex = new Regex(REGEX_PROGRESS); + foreach(Match match in regex.Matches(consoleOutput)) + { + var progress = match.Groups["Progress"].Value; + + this.interpreter.Interpret(progress); + this.ProgressPercentage = this.interpreter.Double; + + OnParsedConsoleOutputRecieved(ButterflowOutputType.Progress, progress, consoleOutput); + } + + regex = new Regex(REGEX_PROGRESS_ALT); + foreach (Match match in regex.Matches(consoleOutput)) + { + var progress = match.Groups["Progress"].Value; + + this.interpreter.Interpret(progress); + this.ProgressPercentage = this.interpreter.Double; + + OnParsedConsoleOutputRecieved(ButterflowOutputType.Progress, progress, consoleOutput); + } } /// Executes the parsed console output recieved action. diff --git a/butterflow-ui/Icon/icon.ico b/butterflow-ui/Icon/icon.ico new file mode 100644 index 0000000..47fd522 Binary files /dev/null and b/butterflow-ui/Icon/icon.ico differ diff --git a/butterflow-ui/Icon/icon.png b/butterflow-ui/Icon/icon.png new file mode 100644 index 0000000..08040b1 Binary files /dev/null and b/butterflow-ui/Icon/icon.png differ diff --git a/butterflow-ui/Icon/icon.svg b/butterflow-ui/Icon/icon.svg new file mode 100644 index 0000000..89857c7 --- /dev/null +++ b/butterflow-ui/Icon/icon.svg @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + UI + + diff --git a/butterflow-ui/Icon/icon_plain.svg b/butterflow-ui/Icon/icon_plain.svg new file mode 100644 index 0000000..1d400b3 --- /dev/null +++ b/butterflow-ui/Icon/icon_plain.svg @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + UI + + diff --git a/butterflow-ui/Icons.xaml b/butterflow-ui/Icons.xaml index 830cf78..8e389fe 100644 --- a/butterflow-ui/Icons.xaml +++ b/butterflow-ui/Icons.xaml @@ -157,4 +157,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/butterflow-ui/Localization/Localization.Designer.cs b/butterflow-ui/Localization/Localization.Designer.cs index 4919c59..684a790 100644 --- a/butterflow-ui/Localization/Localization.Designer.cs +++ b/butterflow-ui/Localization/Localization.Designer.cs @@ -159,6 +159,24 @@ namespace butterflow_ui.Localization { } } + /// + /// Looks up a localized string similar to Cancel. + /// + public static string CancelLabel { + get { + return ResourceManager.GetString("CancelLabel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cancel the current butterflow operation.. + /// + public static string CancelTooltip { + get { + return ResourceManager.GetString("CancelTooltip", resourceCulture); + } + } + /// /// Looks up a localized string similar to Clip a subregion in the video.. /// diff --git a/butterflow-ui/Localization/Localization.resx b/butterflow-ui/Localization/Localization.resx index eda7438..02f2572 100644 --- a/butterflow-ui/Localization/Localization.resx +++ b/butterflow-ui/Localization/Localization.resx @@ -234,6 +234,12 @@ 60 fps + + Cancel + + + Cancel the current butterflow operation. + Use Fast Pyramids diff --git a/butterflow-ui/MainWindow.xaml b/butterflow-ui/MainWindow.xaml index fbf169a..ae674e6 100644 --- a/butterflow-ui/MainWindow.xaml +++ b/butterflow-ui/MainWindow.xaml @@ -9,7 +9,8 @@ xmlns:butterflow_ui="clr-namespace:butterflow_ui" mc:Ignorable="d" x:Name="butterflowUIWindow" - Title="{x:Static loc:Localization.Title}" Height="600" Width="800"> + Title="{x:Static loc:Localization.Title}" Height="600" Width="800" + Icon="./Icon/icon.ico"> @@ -103,12 +104,24 @@ - + + + + + + + + @@ -263,9 +276,27 @@ - - - + + + + + + + + + + + + + + diff --git a/butterflow-ui/MainWindow.xaml.cs b/butterflow-ui/MainWindow.xaml.cs index acced8e..ea0a78d 100644 --- a/butterflow-ui/MainWindow.xaml.cs +++ b/butterflow-ui/MainWindow.xaml.cs @@ -94,7 +94,8 @@ namespace butterflow_ui this.OptionsConfiguration.Height = e.Value; break; case ButterflowWrapper.ButterflowOutputType.Progress: - break; + // This case doesn't need to be considered since we're binding the progress bar's value to a property on the butterflow wrapper. + // We may use this in the future, though. default: break; } @@ -112,7 +113,7 @@ namespace butterflow_ui if (result.HasValue && result.Value) { this.OptionsConfiguration.VideoInput = ofd.FileName; - + this.ButterflowWrapper.Probe(ofd.FileName); //Hack to get the first frame to display in the media preview element. diff --git a/butterflow-ui/OptionsConfiguration.cs b/butterflow-ui/OptionsConfiguration.cs index 8e24f89..0ba4d02 100644 --- a/butterflow-ui/OptionsConfiguration.cs +++ b/butterflow-ui/OptionsConfiguration.cs @@ -24,7 +24,7 @@ namespace butterflow_ui private const decimal DEFAULT_SMOOTH_DERIVATIVE_STANDARD_DEVIATION = 1.1m; private const FlowFilterType DEFAULT_FLOW_FILTER_TYPE = FlowFilterType.box; - /// An interpreter used to ensure numeric input is correctly calculated. + /// An input interpreter used for converting string values to numeric values. private InputInterpreter interpreter = new InputInterpreter(); /// The aspect ratio used for calculating heights when the aspect ratio is locked. private decimal aspectRatio = 0; diff --git a/butterflow-ui/butterflow-ui.csproj b/butterflow-ui/butterflow-ui.csproj index 3481b96..bbd4fa7 100644 --- a/butterflow-ui/butterflow-ui.csproj +++ b/butterflow-ui/butterflow-ui.csproj @@ -33,6 +33,9 @@ prompt 4 + + icon.ico + packages\csmic.1.1.4\lib\net40\csmic.dll @@ -173,6 +176,11 @@ + + + + + diff --git a/butterflow-ui/icon.ico b/butterflow-ui/icon.ico new file mode 100644 index 0000000..47fd522 Binary files /dev/null and b/butterflow-ui/icon.ico differ