diff --git a/butterflow-ui.setup/Product.wxs b/butterflow-ui.setup/Product.wxs index bcafd93..67caa36 100644 --- a/butterflow-ui.setup/Product.wxs +++ b/butterflow-ui.setup/Product.wxs @@ -1,6 +1,6 @@ - + diff --git a/butterflow-ui/App.config b/butterflow-ui/App.config index 85a72ea..748bc2f 100644 --- a/butterflow-ui/App.config +++ b/butterflow-ui/App.config @@ -13,6 +13,9 @@ en-US + + 0 + \ No newline at end of file diff --git a/butterflow-ui/ButterflowWrapper.cs b/butterflow-ui/ButterflowWrapper.cs index b200723..9ed8fbf 100644 --- a/butterflow-ui/ButterflowWrapper.cs +++ b/butterflow-ui/ButterflowWrapper.cs @@ -24,6 +24,8 @@ namespace butterflow_ui 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*)%\>"; + /// The RegEx string for determining available processing devices in butterflow.. + private const string REGEX_DEVICE = @"\*\s*Device\s*(?\d+)\s*\:\s*(?(\w*\s*)*)"; /// Full pathname of the butterflow executable file. private Lazy executablePath = new Lazy(() => Path.Combine(Directory.GetCurrentDirectory(), "ThirdPartyCompiled", "butterflow.exe")); @@ -41,6 +43,8 @@ namespace butterflow_ui private InputInterpreter interpreter = new InputInterpreter(); /// Event queue for all listeners interested in ParsedConsoleOutputRecieved events. public event EventHandler ParsedConsoleOutputRecieved; + /// Event queue for all listeners interested in ButterflowExited events. + public event EventHandler ButterflowExited; #endregion @@ -91,6 +95,10 @@ namespace butterflow_ui } } + /// Gets or sets the list of devices available for butterflow processing. + /// The devices available for butterflow processing. + public Dictionary Devices { get; private set; } = new Dictionary(); + #endregion #region Methods @@ -99,7 +107,7 @@ namespace butterflow_ui /// The options configuration. public void Run(OptionsConfiguration optionsConfiguration) { - for(int i = 0; i < optionsConfiguration.VideoInput.Count(); i++) + for (int i = 0; i < optionsConfiguration.VideoInput.Count(); i++) { var arguments = optionsConfiguration.ToButterflowArguments(i); this.runQueue.Enqueue(arguments); @@ -139,7 +147,7 @@ namespace butterflow_ui /// Kills the running instance of butterflow, cancelling its current operation. public void Cancel() { - if(this.IsRunning && this.runningProcess != null) + if (this.IsRunning && this.runningProcess != null) { this.runningProcess.Kill(); } @@ -155,6 +163,13 @@ namespace butterflow_ui Run(arguments); } + /// Gets the devices available for butterflow processing. + public void GetDevices() + { + string arguments = "--show-devices"; + Run(arguments); + } + /// Runs butterflow with the given by adding it to the queue. /// Options for controlling the operation. private void Run(string arguments) @@ -172,6 +187,8 @@ namespace butterflow_ui this.IsRunning = false; this.runningProcess = null; + OnButterflowExited(); + ProcessQueue(); } @@ -201,7 +218,7 @@ namespace butterflow_ui // Test for playback rate regex = new Regex(REGEX_RATE); - foreach(Match match in regex.Matches(consoleOutput)) + foreach (Match match in regex.Matches(consoleOutput)) { var rate = match.Groups["Rate"].Value; @@ -210,7 +227,7 @@ namespace butterflow_ui // Test for progress being made when rendering a video regex = new Regex(REGEX_PROGRESS); - foreach(Match match in regex.Matches(consoleOutput)) + foreach (Match match in regex.Matches(consoleOutput)) { var progress = match.Groups["Progress"].Value; @@ -230,6 +247,23 @@ namespace butterflow_ui OnParsedConsoleOutputRecieved(ButterflowOutputType.Progress, progress, consoleOutput); } + + regex = new Regex(REGEX_DEVICE); + foreach (Match match in regex.Matches(consoleOutput)) + { + var deviceID = match.Groups["DeviceID"].Value; + var deviceName = match.Groups["DeviceName"].Value.Trim(); + + this.interpreter.Interpret(deviceID); + + if (!this.Devices.ContainsKey(this.interpreter.Int)) + { + this.Devices.Add(this.interpreter.Int, deviceName); + OnPropertyChanged("Devices"); + } + + OnParsedConsoleOutputRecieved(ButterflowOutputType.Device, deviceName, consoleOutput); + } } /// Executes the parsed console output recieved action. @@ -238,10 +272,13 @@ namespace butterflow_ui /// The console output from butterflow. private void OnParsedConsoleOutputRecieved(ButterflowOutputType outputType, string value, string consoleOutput) { - if (this.ParsedConsoleOutputRecieved != null) - { - this.ParsedConsoleOutputRecieved(this, new ButterflowOutputArgs(outputType, value, consoleOutput)); - } + this.ParsedConsoleOutputRecieved?.Invoke(this, new ButterflowOutputArgs(outputType, value, consoleOutput)); + } + + /// Executes the butterflow exited action. + private void OnButterflowExited() + { + this.ButterflowExited?.Invoke(this, new ButterflowExitArgs()); } /// Event handler. Called by Process for output data received events. @@ -308,6 +345,19 @@ namespace butterflow_ui #endregion } + /// Arguments for butterflow exiting. + public class ButterflowExitArgs : EventArgs + { + #region Constructors + + public ButterflowExitArgs() + { + // + } + + #endregion + } + /// Values that represent butterflow output types. public enum ButterflowOutputType { @@ -318,7 +368,9 @@ namespace butterflow_ui /// Video playback rate. Rate, /// Video processing progress. - Progress + Progress, + /// An available processing device. + Device } #endregion diff --git a/butterflow-ui/Localization/Localization.Designer.cs b/butterflow-ui/Localization/Localization.Designer.cs index 81a6f9c..333b237 100644 --- a/butterflow-ui/Localization/Localization.Designer.cs +++ b/butterflow-ui/Localization/Localization.Designer.cs @@ -303,6 +303,15 @@ namespace butterflow_ui.Localization { } } + /// + /// Looks up a localized string similar to Computing Device. + /// + public static string DeviceLabel { + get { + return ResourceManager.GetString("DeviceLabel", resourceCulture); + } + } + /// /// Looks up a localized string similar to _Edit. /// diff --git a/butterflow-ui/Localization/Localization.resx b/butterflow-ui/Localization/Localization.resx index 612b2e3..e7bcb12 100644 --- a/butterflow-ui/Localization/Localization.resx +++ b/butterflow-ui/Localization/Localization.resx @@ -390,4 +390,7 @@ A newer version of butterflow-ui is available. + + Computing Device + \ No newline at end of file diff --git a/butterflow-ui/OptionsConfiguration.cs b/butterflow-ui/OptionsConfiguration.cs index 69b9143..b0eea4e 100644 --- a/butterflow-ui/OptionsConfiguration.cs +++ b/butterflow-ui/OptionsConfiguration.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using butterflow_ui.Properties; using csmic; namespace butterflow_ui @@ -531,6 +532,11 @@ namespace butterflow_ui stringBuilder.AppendFormat("-vs {0}:{1} ", this.Width, this.Height); } + if(Settings.Default.Device != 0) + { + stringBuilder.AppendFormat("-device {0} ", Settings.Default.Device); + } + if (!string.IsNullOrWhiteSpace(this.PlaybackRate)) stringBuilder.AppendFormat("-r {0} ", this.PlaybackRate); if (this.KeepAudio) stringBuilder.Append("-audio "); if (this.LosslessQuality) stringBuilder.Append("-l "); diff --git a/butterflow-ui/OptionsWindow.xaml b/butterflow-ui/OptionsWindow.xaml index bf788e2..3f80d03 100644 --- a/butterflow-ui/OptionsWindow.xaml +++ b/butterflow-ui/OptionsWindow.xaml @@ -14,7 +14,11 @@