Skip to content

Commit

Permalink
Make "loop entire file" actually work
Browse files Browse the repository at this point in the history
Disables multithreading for now as well, and moves VGAudio.exe to the Dependencies folder
  • Loading branch information
ShrineFox committed Aug 23, 2024
1 parent 357de2f commit 38786b0
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 13 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions PersonaVCE.Designer.cs

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

62 changes: 52 additions & 10 deletions PersonaVCE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Windows.Forms;
using static System.Windows.Forms.Design.AxImporter;
using System.Diagnostics.Eventing.Reader;
using NAudio.Wave;

namespace PersonaVCE
{
Expand Down Expand Up @@ -119,11 +120,21 @@ private void Encode(string[] inputFiles, string outFormat = "")
// If loops are specified, use loops
if (chk_UseLoopPoints.Checked)
{
args += $" -l {Convert.ToInt32(num_LoopStart.Value)}-{Convert.ToInt32(num_LoopEnd.Value)}";
if (chk_LoopAll.Checked)
args += $" -l 0-{GetSampleCount(file) - 1}";
else
args += $" -l {Convert.ToInt32(num_LoopStart.Value)}-{Convert.ToInt32(num_LoopEnd.Value)}";
}

Output.VerboseLog($"[INFO] Encoding \"{Path.GetFileName(file)}\" to \"{Path.GetFileName(outPath)}\"...");
Exe.Run(".\\VGAudio.exe", args);
string vgAudioPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Dependencies\\VGAudio.exe");
if (!File.Exists(vgAudioPath))
{
Output.VerboseLog($"[INFO] Failed to encode, could not find executable: \"{vgAudioPath}\"", ConsoleColor.DarkRed);
return;
}
Exe.Run(vgAudioPath, args);
using (FileSys.WaitForFile(outPath)) { };
if (File.Exists(outPath))
{
if (outFormat == ".adx" && args.Contains("--keycode"))
Expand Down Expand Up @@ -155,6 +166,33 @@ private void Encode(string[] inputFiles, string outFormat = "")
Output.Log($"[INFO] Done encoding files to \"{comboBox_SoundFormat.SelectedItem}\".", ConsoleColor.Green);
}

private long GetSampleCount(string file)
{
long sampleCount = -1;

if (File.Exists(file))
{
if (Path.GetExtension(file).ToLower() == ".adx")
using (FileStream fs = new FileStream(file, FileMode.Open))
{
using (EndianBinaryReader reader = new EndianBinaryReader(fs, Endianness.LittleEndian))
{
reader.BaseStream.Position = 12;
sampleCount = reader.ReadInt32();
}
}
else if (Path.GetExtension(file).ToLower() == ".wav")
{
using (var waveFile = new WaveFileReader(file))
{
sampleCount = waveFile.SampleCount;
}
}
}

return sampleCount;
}

private void AddTxtLinesToDGV()
{
if (!File.Exists(settings.InputTxtPath))
Expand Down Expand Up @@ -353,7 +391,7 @@ private void ExtractAFS(string afsPath)
string outputDir = FileSys.CreateUniqueDir(afsPath + "_extracted");
Directory.CreateDirectory(outputDir);

new Thread(() =>
//new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;

Expand All @@ -377,7 +415,8 @@ private void ExtractAFS(string afsPath)
}
}
SystemSounds.Exclamation.Play();
}).Start();
}
//).Start();
Output.Log($"[INFO] Done extracting archive contents to: \"{outputDir}\"", ConsoleColor.Green);
}
else
Expand All @@ -390,7 +429,7 @@ private void RepackAFS(string afsDir)

if (Directory.Exists(afsDir))
{
new Thread(() =>
//new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
// Get input files from AFS directory
Expand All @@ -409,7 +448,8 @@ private void RepackAFS(string afsDir)
}

SystemSounds.Exclamation.Play();
}).Start();
}
//).Start();
Output.Log($"[INFO] Done creating AFS archive at: \"{outputFile}\"", ConsoleColor.Green);
}
else
Expand All @@ -420,7 +460,7 @@ private void ExtractACB(string acbPath)
{
if (File.Exists(acbPath))
{
new Thread(() =>
//new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;

Expand All @@ -429,7 +469,8 @@ private void ExtractACB(string acbPath)
Output.Log($"[INFO] Done extracting archive contents from: \"{acbPath}\"", ConsoleColor.Green);

SystemSounds.Exclamation.Play();
}).Start();
}
//).Start();
}
else
Output.Log($"[ERROR] ACB extract failed, input archive doesn't exist: \"{acbPath}\"", ConsoleColor.Red);
Expand All @@ -454,7 +495,7 @@ private void RepackACB(string acbDir)

if (Directory.Exists(acbDir))
{
new Thread(() =>
//new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;

Expand All @@ -463,7 +504,8 @@ private void RepackACB(string acbDir)
AcbEditor.Program.Main(new string[] { acbDir });
Output.Log($"[INFO] Done repacking ACB archive: \"{acbFile}\"", ConsoleColor.Green);
SystemSounds.Exclamation.Play();
}).Start();
}
//).Start();
}
else
Output.Log($"[ERROR] ACB repack failed, extracted archive directory doesn't exist: \"{acbDir}\"", ConsoleColor.Red);
Expand Down
33 changes: 32 additions & 1 deletion PersonaVCE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,42 @@
<Reference Include="MetroSet UI, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\MetroSet_UI.2.0.0\lib\net45\MetroSet UI.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Win32.Registry, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
</Reference>
<Reference Include="NAudio, Version=2.2.1.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.2.2.1\lib\net472\NAudio.dll</HintPath>
</Reference>
<Reference Include="NAudio.Asio, Version=2.2.1.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.Asio.2.2.1\lib\netstandard2.0\NAudio.Asio.dll</HintPath>
</Reference>
<Reference Include="NAudio.Core, Version=2.2.1.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.Core.2.2.1\lib\netstandard2.0\NAudio.Core.dll</HintPath>
</Reference>
<Reference Include="NAudio.Midi, Version=2.2.1.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.Midi.2.2.1\lib\netstandard2.0\NAudio.Midi.dll</HintPath>
</Reference>
<Reference Include="NAudio.Wasapi, Version=2.2.1.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.Wasapi.2.2.1\lib\netstandard2.0\NAudio.Wasapi.dll</HintPath>
</Reference>
<Reference Include="NAudio.WinForms, Version=2.2.1.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.WinForms.2.2.1\lib\net472\NAudio.WinForms.dll</HintPath>
</Reference>
<Reference Include="NAudio.WinMM, Version=2.2.1.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.WinMM.2.2.1\lib\netstandard2.0\NAudio.WinMM.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Design" />
<Reference Include="System.Security.AccessControl, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll</HintPath>
</Reference>
<Reference Include="System.Security.Principal.Windows, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -81,6 +111,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="PersonaVCE.resx">
<DependentUpon>PersonaVCE.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down Expand Up @@ -131,7 +162,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="icon.ico" />
<Content Include="VGAudio.exe">
<Content Include="Dependencies\VGAudio.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MetroSet_UI" version="2.0.0" targetFramework="net48" />
<package id="Microsoft.Win32.Registry" version="4.7.0" targetFramework="net48" />
<package id="NAudio" version="2.2.1" targetFramework="net48" />
<package id="NAudio.Asio" version="2.2.1" targetFramework="net48" />
<package id="NAudio.Core" version="2.2.1" targetFramework="net48" />
<package id="NAudio.Midi" version="2.2.1" targetFramework="net48" />
<package id="NAudio.Wasapi" version="2.2.1" targetFramework="net48" />
<package id="NAudio.WinForms" version="2.2.1" targetFramework="net48" />
<package id="NAudio.WinMM" version="2.2.1" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
<package id="System.Security.AccessControl" version="4.7.0" targetFramework="net48" />
<package id="System.Security.Principal.Windows" version="4.7.0" targetFramework="net48" />
</packages>

0 comments on commit 38786b0

Please sign in to comment.