Skip to content
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
1 change: 1 addition & 0 deletions FlexASIOGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="PortAudioSharp2" Version="1.0.4" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />
<PackageReference Include="Tomlyn" Version="0.16.1" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Form1.Designer.cs

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

57 changes: 27 additions & 30 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public partial class Form1 : Form
private bool InitDone = false;
private string TOMLPath;
private FlexGUIConfig flexGUIConfig;
private Encoding legacyEncoding;
private readonly string flexasioGuiVersion = "0.35";
private readonly string flexasioVersion = "1.9";
private readonly string tomlName = "FlexASIO.toml";
Expand All @@ -34,23 +33,19 @@ public partial class Form1 : Form
public Form1()
{
InitializeComponent();

this.Text = $"FlexASIO GUI v{flexasioGuiVersion}";

System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
customCulture.NumberFormat.NumberDecimalSeparator = ".";
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

// get the value of the "Language for non-Unicode programs" setting (1252 for English)
// note: in Win11 this could be UTF-8 already, since it's natively supported
legacyEncoding = Encoding.GetEncoding((int)GetACP());

System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
CultureInfo.DefaultThreadCurrentCulture = customCulture;
CultureInfo.DefaultThreadCurrentUICulture = customCulture;

TOMLPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\{tomlName}";

tomlModelOptions.ConvertPropertyName = (string name) => name;
this.LoadFlexASIOConfig(TOMLPath);

Expand All @@ -65,7 +60,15 @@ private FlexGUIConfig LoadFlexASIOConfig(string tomlPath)
if (File.Exists(tomlPath))
{
var tomlPathAsText = File.ReadAllText(tomlPath);
flexGUIConfig = Toml.ToModel<FlexGUIConfig>(tomlPathAsText, options: tomlModelOptions);
try
{
flexGUIConfig = Toml.ToModel<FlexGUIConfig>(tomlPathAsText, options: tomlModelOptions);
}
catch (Exception)
{
MessageBox.Show($"Error loading config, the config file is reset.");
File.Delete(tomlPath);
}
}

numericBufferSize.Maximum = 8192;
Expand Down Expand Up @@ -121,14 +124,6 @@ private FlexGUIConfig LoadFlexASIOConfig(string tomlPath)
return flexGUIConfig;
}

private string DescrambleUTF8(string s)
{
// portaudio incorrectly returns UTF-8 strings as if they were ANSI (CP1252 for most Latin systems, CP1251 for Cyrillic, etc...)
// this line fixes the issue by reading the input as CP* and parsing it as UTF-8
var bytes = legacyEncoding.GetBytes(s);
return Encoding.UTF8.GetString(bytes);
}

private TreeNode[] GetDevicesForBackend(string Backend, bool Input)
{
List<TreeNode> treeNodes = new List<TreeNode>();
Expand All @@ -138,22 +133,22 @@ private TreeNode[] GetDevicesForBackend(string Backend, bool Input)
var deviceInfo = Configuration.GetDeviceInfo(i);

var apiInfo = Configuration.GetHostApiInfo(deviceInfo.hostApi);
if (apiInfo.name != Backend)

if (apiInfo.name != Backend)
continue;

if (Input == true)
{
if (deviceInfo.maxInputChannels > 0)
{
treeNodes.Add(new TreeNode(DescrambleUTF8(deviceInfo.name)));
treeNodes.Add(new TreeNode(deviceInfo.name));
}
}
else
{
if (deviceInfo.maxOutputChannels > 0)
{
treeNodes.Add(new TreeNode(DescrambleUTF8(deviceInfo.name)));
treeNodes.Add(new TreeNode(deviceInfo.name));
}
}
}
Expand All @@ -162,15 +157,15 @@ private TreeNode[] GetDevicesForBackend(string Backend, bool Input)

private void Form1_Load(object sender, EventArgs e)
{

}

private void comboBackend_SelectedIndexChanged(object sender, EventArgs e)
{
var o = sender as ComboBox;
if (o != null)
{
var selectedBackend = o.SelectedItem as string;
var selectedBackend = o.SelectedItem as String;
RefreshDevices(selectedBackend);
if (selectedBackend == "(None)") selectedBackend = "";
flexGUIConfig.backend = selectedBackend;
Expand Down Expand Up @@ -262,7 +257,7 @@ private void btSaveAs_Click(object sender, EventArgs e)
SetStatusMessage($"Configuration written to {saveFileDialog.FileName}");
}

private void treeDevicesInput_AfterSelect(object sender, TreeViewEventArgs e)
private void treeDevicesInput_AfterSelect(object sender, TreeViewEventArgs e)
{
if (sender == null) return;
else
Expand Down Expand Up @@ -402,7 +397,7 @@ private void numericBufferSize_ValueChanged(object sender, EventArgs e)
GenerateOutput();
}


private void checkBoxSetInputLatency_CheckedChanged(object sender, EventArgs e)
{
var o = sender as CheckBox;
Expand All @@ -424,7 +419,8 @@ private void checkBoxSetOutputLatency_CheckedChanged(object sender, EventArgs e)
var o = sender as CheckBox;
if (o == null) return;
numericLatencyOutput.Enabled = o.Checked;
if (o.Checked == false) {
if (o.Checked == false)
{
flexGUIConfig.output.suggestedLatencySeconds = null;
}
else
Expand All @@ -433,15 +429,16 @@ private void checkBoxSetOutputLatency_CheckedChanged(object sender, EventArgs e)
}
GenerateOutput();
}


private void checkBoxSetBufferSize_CheckedChanged(object sender, EventArgs e)
{
var o = sender as CheckBox;
if (o == null) return;
numericBufferSize.Enabled = o.Checked;
if (o.Checked == false) {
flexGUIConfig.bufferSizeSamples = null;
if (o.Checked == false)
{
flexGUIConfig.bufferSizeSamples = null;
}
else
{
Expand Down Expand Up @@ -504,7 +501,7 @@ private void linkLabelDocs_LinkClicked(object sender, LinkLabelLinkClickedEventA
private void btLoadFrom_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();

openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
openFileDialog.FileName = tomlName;
openFileDialog.Filter = "FlexASIO Config (*.toml)|*.toml";
Expand All @@ -522,7 +519,7 @@ private void btLoadFrom_Click(object sender, EventArgs e)
this.LoadFlexASIOConfig(TOMLPath);
return;
}

}
SetStatusMessage($"Configuration loaded from {openFileDialog.FileName}");
}
Expand Down
Binary file modified lib/Debug/portaudio-sharp.dll
Binary file not shown.
Binary file modified lib/Debug/portaudio-sharp.pdb
Binary file not shown.
Binary file modified lib/Release/portaudio-sharp.dll
Binary file not shown.
Binary file modified lib/Release/portaudio-sharp.pdb
Binary file not shown.
Binary file added lib/portaudio.dll
Binary file not shown.
Binary file added lib/portaudio.pdb
Binary file not shown.
Binary file removed lib/portaudio_x64.dll
Binary file not shown.
Binary file removed lib/portaudio_x64.pdb
Binary file not shown.