Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for #38 #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
43 changes: 21 additions & 22 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 Down Expand Up @@ -123,12 +118,14 @@ private FlexGUIConfig LoadFlexASIOConfig(string tomlPath)

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);
// now portaudio is use Unicode string, not ANSI string
// So we need to convert Unicode to utf-8
byte[] stringBuffer = Encoding.Unicode.GetBytes(s);
s = Encoding.UTF8.GetString(stringBuffer);
return s;
}


private TreeNode[] GetDevicesForBackend(string Backend, bool Input)
{
List<TreeNode> treeNodes = new List<TreeNode>();
Expand All @@ -138,8 +135,8 @@ 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)
Expand All @@ -162,7 +159,7 @@ private TreeNode[] GetDevicesForBackend(string Backend, bool Input)

private void Form1_Load(object sender, EventArgs e)
{

}

private void comboBackend_SelectedIndexChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -262,7 +259,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 +399,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 +421,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 +431,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 +503,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 +521,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.