Skip to content

Commit

Permalink
Version 0.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
bri committed Oct 11, 2023
1 parent fd58591 commit 7e56c5b
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 69 deletions.
167 changes: 105 additions & 62 deletions OmniConverter/Extensions/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,11 @@ private void PerMIDIConv(int MT, CSCore.WaveFormat WF, Panel ThreadsPanel, strin
MSM.Position = 0;

IWaveSource MStream;
AntiClipping BAC;
if (Properties.Settings.Default.LoudMax)
{
Debug.PrintToConsole("ok", "LoudMax enabled.");
AntiClipping BAC = new AntiClipping(MSM, 0.1);
BAC = new AntiClipping(MSM, 0.1);
MStream = BAC.ToWaveSource(32);
}
else MStream = MSM.ToWaveSource(32);
Expand Down Expand Up @@ -373,8 +374,8 @@ private void PerTrackConv(int MT, CSCore.WaveFormat WF, Panel ThreadsPanel, stri
break;
}

String Folder = OPath;
MultiStreamMerger MSM = new MultiStreamMerger(WF);
int t = 0;

MDV.SetTotalTracks(MFile.Tracks);
MDV.ResetCurrentTrack();
Expand All @@ -387,47 +388,55 @@ private void PerTrackConv(int MT, CSCore.WaveFormat WF, Panel ThreadsPanel, stri
CTS = new CancellationTokenSource();
Debug.PrintToConsole("ok", $"PerTrackConv => MaxDegreeOfParallelism = {MT}");

// Check if we need to export each track to a file
if (Properties.Settings.Default.PerTrackCreateFolder)
{
// We do, create folder
Folder += String.Format("\\{0}", Path.GetFileNameWithoutExtension(MFile.Name));

if (Directory.Exists(Folder))
Folder += string.Format(" - {0}", DateTime.Now.ToString("dd-MM-yyyy HHmmsstt"));

Directory.CreateDirectory(Folder);
}

Folder += "\\";

var ParallelThread = Task.Run(() =>
{
try
{
// Parallel.For(0, MFile.Tracks, new ParallelOptions() { MaxDegreeOfParallelism = MT, CancellationToken = CTS.Token }, T =>
ParallelLoopExt.ParallelFor(0, MFile.Tracks, MT, CTS.Token, T =>
{
Task ConvThread;
string SOutputDir = string.Empty;
MultiStreamMerger tMSM;
TaskStatus Trck;

ConvertWorker Worker;
ISampleWriter Writer;

if (StopRequested)
{
Debug.PrintToConsole("ok", "Stop requested. Stopping ParallelFor...");
return;
}

if (MFile.NoteCount >= 0)
if (MFile.MetaEventsCount >= 0)
{
TaskStatus Trck = new TaskStatus($"Track {T}");
tMSM = new MultiStreamMerger(WF);
Trck = new TaskStatus($"Track {T}");
Trck.Dock = DockStyle.Top;
ThreadsPanel.Invoke((MethodInvoker)delegate { ThreadsPanel.Controls.Add(Trck); });

ConvertWorker Worker = new ConvertWorker(MFile.GetSingleTrackTimeBased(T), MFile.TimeLength.TotalSeconds);
ISampleWriter Writer;
WaveWriter SDestination = null;
FileStream SFOpen = null;
Worker = new ConvertWorker(MFile.GetSingleTrackTimeBased(T), MFile.TimeLength.TotalSeconds);
Debug.PrintToConsole("ok", $"ConvertWorker => T{T}, {MFile.TimeLength.TotalSeconds}");

if (Properties.Settings.Default.PerTrackSeparateFiles)
{
// Check if we need to export each track to a file
String Folder = OPath;
if (Properties.Settings.Default.PerTrackSeparateFiles)
{
// We do, create folder
Folder += String.Format("\\{0}\\", Path.GetFileNameWithoutExtension(MFile.Name));

if (!Directory.Exists(Folder))
Directory.CreateDirectory(Folder);
}
else Folder += " ";

{
// Prepare the filename
String SOutputDir = String.Format("{0}Track {1}.{2}",
SOutputDir = String.Format("{0}Track {1}.{2}",
Folder, T, Properties.Settings.Default.Codec);

// Check if file already exists
Expand All @@ -437,13 +446,11 @@ private void PerTrackConv(int MT, CSCore.WaveFormat WF, Panel ThreadsPanel, stri

Debug.PrintToConsole("ok", String.Format("{0} - Output file: {1}", T, SOutputDir));

SFOpen = File.Open(SOutputDir, FileMode.Create);
SDestination = new WaveWriter(SFOpen, WF);
Writer = new WaveSampleWriter(SDestination);
Writer = tMSM.GetWriter();
}
else Writer = MSM.GetWriter();

var ConvThread = Task.Run(() => Worker.Convert(Writer, WF, CTS.Token));
ConvThread = Task.Run(() => Worker.Convert(Writer, WF, CTS.Token));
Debug.PrintToConsole("ok", $"ConvThread started for T{T}");

int ov = 0;
Expand All @@ -463,8 +470,42 @@ private void PerTrackConv(int MT, CSCore.WaveFormat WF, Panel ThreadsPanel, stri
}
}

ConvThread.Wait();
ConvThread.Dispose();
if (ConvThread != null)
{
ConvThread.Wait();
ConvThread.Dispose();
}

if (Properties.Settings.Default.PerTrackSeparateFiles)
{
IWaveSource tMStream;
AntiClipping BAC;
if (Properties.Settings.Default.LoudMax)
{
Debug.PrintToConsole("ok", "LoudMax enabled.");
BAC = new AntiClipping(tMSM, 0.1);
tMStream = BAC.ToWaveSource(32);
}
else tMStream = tMSM.ToWaveSource(32);

// Reset MSM position
tMSM.Position = 0;

FileStream tFOpen = File.Open(SOutputDir, FileMode.Create);
WaveWriter tDestination = new WaveWriter(tFOpen, WF);
Debug.PrintToConsole("ok", "Output file is open.");

Int32 FRead = 0;
byte[] FBuffer = new byte[1024 * 16];

Debug.PrintToConsole("ok", String.Format("Writing data for {0} to disk...", SOutputDir));
while ((FRead = tMStream.Read(FBuffer, 0, FBuffer.Length)) != 0)
tDestination.Write(FBuffer, 0, FRead);
Debug.PrintToConsole("ok", String.Format("Done writing {0}.", SOutputDir));

tDestination.Dispose();
tFOpen.Dispose();
}

if (Writer != null)
{
Expand All @@ -476,9 +517,6 @@ private void PerTrackConv(int MT, CSCore.WaveFormat WF, Panel ThreadsPanel, stri

ThreadsPanel.Invoke((MethodInvoker)delegate { Trck.Dispose(); });

if (SDestination != null) SDestination.Dispose();
if (SFOpen != null) SFOpen.Dispose();

if (!StopRequested) MDV.AddTrack();
}
});
Expand All @@ -500,47 +538,52 @@ private void PerTrackConv(int MT, CSCore.WaveFormat WF, Panel ThreadsPanel, stri
break;
else MDV.AddValidMIDI();

// Time to save the file
String OutputDir = String.Format("{0}\\{1}.{2}",
if (!Properties.Settings.Default.PerTrackSeparateFiles)
{
// Time to save the file
String OutputDir = String.Format("{0}\\{1}.{2}",
OPath, Path.GetFileNameWithoutExtension(MFile.Name), Properties.Settings.Default.Codec);

// Check if file already exists
if (File.Exists(OutputDir))
OutputDir = String.Format("{0}\\{1} - {2}.{3}",
OPath, Path.GetFileNameWithoutExtension(MFile.Name),
DateTime.Now.ToString("yyyyMMdd HHmmsstt"), Properties.Settings.Default.Codec);
// Check if file already exists
if (File.Exists(OutputDir))
OutputDir = String.Format("{0}\\{1} - {2}.{3}",
OPath, Path.GetFileNameWithoutExtension(MFile.Name),
DateTime.Now.ToString("yyyyMMdd HHmmsstt"), Properties.Settings.Default.Codec);

Debug.PrintToConsole("ok", String.Format("Output file: {0}", OutputDir));
Debug.PrintToConsole("ok", String.Format("Output file: {0}", OutputDir));

// Reset MSM position
MSM.Position = 0;
// Reset MSM position
MSM.Position = 0;

// Prepare wave source
IWaveSource MStream;
if (Properties.Settings.Default.LoudMax)
{
Debug.PrintToConsole("ok", "LoudMax enabled.");
AntiClipping BAC = new AntiClipping(MSM, 0.1);
MStream = BAC.ToWaveSource(32);
}
else MStream = MSM.ToWaveSource(32);
// Prepare wave source
IWaveSource MStream;
AntiClipping BAC;
if (Properties.Settings.Default.LoudMax)
{
Debug.PrintToConsole("ok", "LoudMax enabled.");
BAC = new AntiClipping(MSM, 0.1);
MStream = BAC.ToWaveSource(32);
}
else MStream = MSM.ToWaveSource(32);

FileStream FOpen = File.Open(OutputDir, FileMode.Create);
WaveWriter Destination = new WaveWriter(FOpen, WF);
Debug.PrintToConsole("ok", "Output file is open.");
FileStream FOpen = File.Open(OutputDir, FileMode.Create);
WaveWriter Destination = new WaveWriter(FOpen, WF);
Debug.PrintToConsole("ok", "Output file is open.");

Int32 FRead = 0;
byte[] FBuffer = new byte[1024 * 16];
Int32 FRead = 0;
byte[] FBuffer = new byte[1024 * 16];

Status = "aout";
Debug.PrintToConsole("ok", String.Format("Writing data for {0} to disk...", OutputDir));
while ((FRead = MStream.Read(FBuffer, 0, FBuffer.Length)) != 0)
Destination.Write(FBuffer, 0, FRead);
Debug.PrintToConsole("ok", String.Format("Done writing {0}.", OutputDir));
Status = "aout";
Debug.PrintToConsole("ok", String.Format("Writing data for {0} to disk...", OutputDir));
while ((FRead = MStream.Read(FBuffer, 0, FBuffer.Length)) != 0)
Destination.Write(FBuffer, 0, FRead);
Debug.PrintToConsole("ok", String.Format("Done writing {0}.", OutputDir));

Destination.Dispose();
FOpen.Dispose();
}

MSM.Dispose();
Destination.Dispose();
FOpen.Dispose();
}
}

Expand Down
2 changes: 2 additions & 0 deletions OmniConverter/Extensions/MIDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public IEnumerable<MIDIEvent> GetFullMIDITimeBased() =>
public IEnumerable<IEnumerable<MIDIEvent>> GetIterateTracksTimeBased() =>
LoadedFile.IterateTracks().Select(track => track.MergeWith(MetaEvents).MakeTimeBased(LoadedFile.PPQ));

public int MetaEventsCount => MetaEvents.Count();

public long ID { get; private set; }
public string Name { get; private set; }
public string Path { get; private set; }
Expand Down
8 changes: 4 additions & 4 deletions OmniConverter/Forms/InfoWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace OmniConverter
{
public partial class InfoWindow : Form
{
private Version Converter = new Version(0, 0, 10, 0);
private Version Converter = new Version(0, 0, 11, 0);

private ToolTip DynamicToolTip = new ToolTip();
private RegistryKey WVerKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", false);
Expand Down Expand Up @@ -132,17 +132,17 @@ private void VerLabel_Click(object sender, EventArgs e)

private void GitHubPage_Click(object sender, EventArgs e)
{
Process.Start(Properties.Settings.Default.ProjectLink);
Process.Start(new ProcessStartInfo(Properties.Settings.Default.ProjectLink) { UseShellExecute = true });
}

private void DonateKep_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://www.paypal.me/Keppy99");
Process.Start(new ProcessStartInfo("https://www.paypal.me/Keppy99") { UseShellExecute = true });
}

private void DonateArd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://www.paypal.me/arduano");
Process.Start(new ProcessStartInfo("https://www.paypal.me/arduano") { UseShellExecute = true });
}

private void OMLicense_Click(object sender, EventArgs e)
Expand Down
Loading

0 comments on commit 7e56c5b

Please sign in to comment.