Skip to content

Commit

Permalink
Added compute device selection
Browse files Browse the repository at this point in the history
Added a call to butterflow to get compute devices, as well as a user setting that lets them set which device they want to use. I only have a single GPU, so I am unable to test this.
  • Loading branch information
wagesj45 committed Sep 13, 2018
1 parent 77d409b commit d454d7a
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 14 deletions.
2 changes: 1 addition & 1 deletion butterflow-ui.setup/Product.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="butterflow-ui" Language="1033" Version="1.0.3" Manufacturer="butterflow-ui @ github" UpgradeCode="bba9d512-377a-467e-920a-cbcf36ffc072">
<Product Id="*" Name="butterflow-ui" Language="1033" Version="1.0.4" Manufacturer="butterflow-ui @ github" UpgradeCode="bba9d512-377a-467e-920a-cbcf36ffc072">
<Package Id="*" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
Expand Down
3 changes: 3 additions & 0 deletions butterflow-ui/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<setting name="Language" serializeAs="String">
<value>en-US</value>
</setting>
<setting name="Device" serializeAs="String">
<value>0</value>
</setting>
</butterflow_ui.Properties.Settings>
</userSettings>
</configuration>
70 changes: 61 additions & 9 deletions butterflow-ui/ButterflowWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ButterflowWrapper : PropertyChangedAlerter
private const string REGEX_PROGRESS = @"To write\:\s*\w*\s*\w*\,*\w*\s*(?<Progress>\d+\.*\d*)%";
/// <summary> An alternative RegEx string for detecting progress made when rendering a video. </summary>
private const string REGEX_PROGRESS_ALT = @"\<Rendering progress\:\s*(?<Progress>\d+\.*\d*)%\>";
/// <summary> The RegEx string for determining available processing devices in butterflow.. </summary>
private const string REGEX_DEVICE = @"\*\s*Device\s*(?<DeviceID>\d+)\s*\:\s*(?<DeviceName>(\w*\s*)*)";

/// <summary> Full pathname of the butterflow executable file. </summary>
private Lazy<string> executablePath = new Lazy<string>(() => Path.Combine(Directory.GetCurrentDirectory(), "ThirdPartyCompiled", "butterflow.exe"));
Expand All @@ -41,6 +43,8 @@ public class ButterflowWrapper : PropertyChangedAlerter
private InputInterpreter interpreter = new InputInterpreter();
/// <summary> Event queue for all listeners interested in ParsedConsoleOutputRecieved events. </summary>
public event EventHandler<ButterflowOutputArgs> ParsedConsoleOutputRecieved;
/// <summary> Event queue for all listeners interested in ButterflowExited events. </summary>
public event EventHandler<ButterflowExitArgs> ButterflowExited;

#endregion

Expand Down Expand Up @@ -91,6 +95,10 @@ private set
}
}

/// <summary> Gets or sets the list of devices available for butterflow processing. </summary>
/// <value> The devices available for butterflow processing. </value>
public Dictionary<int, string> Devices { get; private set; } = new Dictionary<int, string>();

#endregion

#region Methods
Expand All @@ -99,7 +107,7 @@ private set
/// <param name="optionsConfiguration"> The options configuration. </param>
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);
Expand Down Expand Up @@ -139,7 +147,7 @@ public void ProcessQueue()
/// <summary> Kills the running instance of butterflow, cancelling its current operation. </summary>
public void Cancel()
{
if(this.IsRunning && this.runningProcess != null)
if (this.IsRunning && this.runningProcess != null)
{
this.runningProcess.Kill();
}
Expand All @@ -155,6 +163,13 @@ public void Probe(string videoFile)
Run(arguments);
}

/// <summary> Gets the devices available for butterflow processing. </summary>
public void GetDevices()
{
string arguments = "--show-devices";
Run(arguments);
}

/// <summary> Runs butterflow with the given <paramref name="arguments"/> by adding it to the queue. </summary>
/// <param name="arguments"> Options for controlling the operation. </param>
private void Run(string arguments)
Expand All @@ -172,6 +187,8 @@ private void Process_Exited(object sender, EventArgs e)
this.IsRunning = false;
this.runningProcess = null;

OnButterflowExited();

ProcessQueue();
}

Expand Down Expand Up @@ -201,7 +218,7 @@ private void ParseConsoleOutput(string consoleOutput)

// 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;

Expand All @@ -210,7 +227,7 @@ private void ParseConsoleOutput(string consoleOutput)

// 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;

Expand All @@ -230,6 +247,23 @@ private void ParseConsoleOutput(string consoleOutput)

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);
}
}

/// <summary> Executes the parsed console output recieved action. </summary>
Expand All @@ -238,10 +272,13 @@ private void ParseConsoleOutput(string consoleOutput)
/// <param name="consoleOutput"> The console output from butterflow. </param>
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));
}

/// <summary> Executes the butterflow exited action. </summary>
private void OnButterflowExited()
{
this.ButterflowExited?.Invoke(this, new ButterflowExitArgs());
}

/// <summary> Event handler. Called by Process for output data received events. </summary>
Expand Down Expand Up @@ -308,6 +345,19 @@ public ButterflowConsoleOutputArgs(string consoleOutput)
#endregion
}

/// <summary> Arguments for butterflow exiting. </summary>
public class ButterflowExitArgs : EventArgs
{
#region Constructors

public ButterflowExitArgs()
{
//
}

#endregion
}

/// <summary> Values that represent butterflow output types. </summary>
public enum ButterflowOutputType
{
Expand All @@ -318,7 +368,9 @@ public enum ButterflowOutputType
/// <summary> Video playback rate. </summary>
Rate,
/// <summary> Video processing progress. </summary>
Progress
Progress,
/// <summary> An available processing device. </summary>
Device
}

#endregion
Expand Down
9 changes: 9 additions & 0 deletions butterflow-ui/Localization/Localization.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions butterflow-ui/Localization/Localization.resx
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,7 @@
<data name="UpdateAvailableLabel" xml:space="preserve">
<value>A newer version of butterflow-ui is available.</value>
</data>
<data name="DeviceLabel" xml:space="preserve">
<value>Computing Device</value>
</data>
</root>
6 changes: 6 additions & 0 deletions butterflow-ui/OptionsConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using butterflow_ui.Properties;
using csmic;

namespace butterflow_ui
Expand Down Expand Up @@ -531,6 +532,11 @@ public string ToButterflowArguments(int videoInputIndex = 0)
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 ");
Expand Down
6 changes: 5 additions & 1 deletion butterflow-ui/OptionsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
<Label Content="{x:Static loc:Localization.LanguageLabel}" />
<ComboBox DisplayMemberPath="DisplayName" ItemsSource="{Binding SupportedLanguages, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:OptionsWindow}}, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding Source={x:Static settings:Settings.Default}, Path=Language}" />
</WrapPanel>
<TextBlock Text="{x:Static loc:Localization.OptionsWindowLanguageChangeNotice}" />
<TextBlock Text="{x:Static loc:Localization.OptionsWindowLanguageChangeNotice}" Foreground="Gray" />
<WrapPanel>
<Label Content="{x:Static loc:Localization.DeviceLabel}" />
<ComboBox Name="comboDeviceList" DisplayMemberPath="Value" ItemsSource="{Binding ButterflowWrapper.Devices, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:OptionsWindow}}, UpdateSourceTrigger=PropertyChanged}" SelectedIndex="{Binding Source={x:Static settings:Settings.Default}, Path=Device}" />
</WrapPanel>
<Separator Margin="0,10" />
<Button Name="btnSave" MaxWidth="45" Content="{x:Static loc:Localization.SaveLabel}" Click="btnSave_Click" />
</StackPanel>
Expand Down
23 changes: 22 additions & 1 deletion butterflow-ui/OptionsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using butterflow_ui.Properties;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand All @@ -21,6 +22,9 @@ public partial class OptionsWindow : Window
{
#region Properties

/// <summary> The butterflow wrapper used to call butterflow. </summary>
public ButterflowWrapper ButterflowWrapper { get; set; } = new ButterflowWrapper();

/// <summary> Gets or sets the supported languages. </summary>
/// <value> The supported languages. </value>
public List<CultureInfo> SupportedLanguages { get; set; } = new List<CultureInfo>(new[]
Expand All @@ -40,6 +44,8 @@ public partial class OptionsWindow : Window
/// <summary> Default constructor. </summary>
public OptionsWindow()
{
this.ButterflowWrapper.GetDevices();
this.ButterflowWrapper.ButterflowExited += ButterflowWrapper_ButterflowExited;
InitializeComponent();
}

Expand All @@ -57,6 +63,21 @@ private void btnSave_Click(object sender, RoutedEventArgs e)
this.Close();
}

/// <summary> Butterflow wrapper butterflow exited. </summary>
/// <param name="sender"> Source of the event. </param>
/// <param name="e"> The ButterflowExitArgs to process. </param>
private void ButterflowWrapper_ButterflowExited(object sender, ButterflowWrapper.ButterflowExitArgs e)
{
if (Settings.Default.Device >= 0)
{
this.comboDeviceList.Dispatcher.Invoke(() => this.comboDeviceList.SelectedIndex = Settings.Default.Device);
}
else
{
this.comboDeviceList.Dispatcher.Invoke(() => this.comboDeviceList.SelectedIndex = 0);
}
}

#endregion
}
}
2 changes: 1 addition & 1 deletion butterflow-ui/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.3.*")]
[assembly: AssemblyVersion("1.0.4.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]
14 changes: 13 additions & 1 deletion butterflow-ui/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions butterflow-ui/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<Setting Name="Language" Type="System.Globalization.CultureInfo" Scope="User">
<Value Profile="(Default)">en-US</Value>
</Setting>
<Setting Name="Device" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit d454d7a

Please sign in to comment.