Skip to content

Commit

Permalink
0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
KaleidonKep99 committed Jun 1, 2021
1 parent ecc94dd commit e68e1e6
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 175 deletions.
25 changes: 17 additions & 8 deletions OmniConverter/App.config
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="OmniConverter.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="OmniConverter.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="OmniConverter.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="OmniConverter.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<runtime>
<gcAllowVeryLargeObjects enabled="true" />
<gcAllowVeryLargeObjects enabled="true"/>
</runtime>
<userSettings>
<OmniConverter.Properties.Settings>
Expand Down Expand Up @@ -85,6 +85,15 @@
<setting name="CFValue" serializeAs="String">
<value>60</value>
</setting>
<setting name="RVOverrideToggle" serializeAs="String">
<value>False</value>
</setting>
<setting name="ReverbValue" serializeAs="String">
<value>0</value>
</setting>
<setting name="ChorusValue" serializeAs="String">
<value>0</value>
</setting>
</OmniConverter.Properties.Settings>
</userSettings>
<applicationSettings>
Expand All @@ -103,4 +112,4 @@
</setting>
</OmniConverter.Properties.Settings>
</applicationSettings>
</configuration>
</configuration>
2 changes: 1 addition & 1 deletion OmniConverter/Controls/TrackThreadStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace OmniConverter
{
public partial class TrackThreadStatus : UserControl
{
public TrackThreadStatus(Int32 Track)
public TrackThreadStatus(Int64 Track)
{
InitializeComponent();

Expand Down
9 changes: 9 additions & 0 deletions OmniConverter/Extensions/BASSMIDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using System.Windows.Forms;
using Un4seen.Bass;
using Un4seen.Bass.AddOn.Vst;
using Un4seen.Bass.AddOn.Midi;

// Written with help from Arduano
Expand Down Expand Up @@ -137,6 +138,14 @@ private void SetSoundFonts()
Debug.PrintToConsole("ok", String.Format("{0} - Loaded {1} SoundFonts.", UniqueID, Program.SFArray.BMFEArray.Count));
}

private void SetVSTs()
{
foreach (VST iVST in Program.VSTArray)
{
//
}
}

public unsafe int Read(float[] buffer, int offset, int count)
{
lock (Lock)
Expand Down
149 changes: 73 additions & 76 deletions OmniConverter/Extensions/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class MIDIsValidity
private UInt64 InvalidMIDIs;
private UInt64 TotalMIDIsCount;

private Int32 Tracks = 0;
private Int32 CurrentTrack = 0;
private Int64 Tracks = 0;
private Int64 CurrentTrack = 0;

public MIDIsValidity()
{
Expand All @@ -43,11 +43,11 @@ public MIDIsValidity()
public UInt64 GetInvalidMIDIsCount() { return InvalidMIDIs; }
public UInt64 GetTotalMIDIsCount() { return TotalMIDIsCount; }

public void SetTotalTracks(Int32 T) { Tracks = T; }
public void SetTotalTracks(Int64 T) { Tracks = T; }
public void AddTrack() { CurrentTrack++; }
public void ResetCurrentTrack() { CurrentTrack = 0; }
public Int32 GetTotalTracks() { return Tracks; }
public Int32 GetCurrentTrack() { return CurrentTrack; }
public Int64 GetTotalTracks() { return Tracks; }
public Int64 GetCurrentTrack() { return CurrentTrack; }
}

class WaveSampleWriter : ISampleWriter, IDisposable
Expand Down Expand Up @@ -105,7 +105,7 @@ public void Convert(ISampleWriter output, WaveFormat format, bool loudmax, Cance
long prevWriteTime = 0;
double time = 0;
int read;
foreach (var e in events)
foreach (MIDIEvent e in events)
{
cancel.ThrowIfCancellationRequested();

Expand Down Expand Up @@ -371,8 +371,6 @@ private void MIDIConversion(Control Form, Panel ThreadsPanel, String OPath)

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

PO.CancellationToken.ThrowIfCancellationRequested();
});
}
catch (OperationCanceledException) { }
Expand Down Expand Up @@ -429,12 +427,10 @@ private void MIDIConversionTbT(Control Form, Panel ThreadsPanel, String OPath)

try
{
Debug.PrintToConsole("ok", "Preparing Parallel.For loop...");
CTS = new CancellationTokenSource();
ParallelOptions PO = new ParallelOptions { MaxDegreeOfParallelism = MT, CancellationToken = CTS.Token };
Debug.PrintToConsole("ok", String.Format("ParallelOptions prepared, MaxDegreeOfParallelism = {0}", MT));
Debug.PrintToConsole("ok", String.Format("Preparing loop... MaxDegreeOfParallelism = {0}", MT));

ParallelFor(0, MFile.Tracks, Environment.ProcessorCount, new CancellationToken(false), T =>
ParallelFor(0, MFile.Tracks, MT, CTS.Token, T =>
{
if (StopRequested)
{
Expand All @@ -443,81 +439,82 @@ private void MIDIConversionTbT(Control Form, Panel ThreadsPanel, String OPath)
return;
}

TrackThreadStatus Trck = new TrackThreadStatus(T);
Trck.Dock = DockStyle.Top;
ThreadsPanel.Invoke((MethodInvoker)delegate
if (MFile.NoteCount > 0)
{
Debug.PrintToConsole("ok", "Added TrackThreadStatus control for MIDI.");
ThreadsPanel.Controls.Add(Trck);
});
TrackThreadStatus Trck = new TrackThreadStatus(T);
Trck.Dock = DockStyle.Top;
ThreadsPanel.Invoke((MethodInvoker)delegate
{
Debug.PrintToConsole("ok", "Added TrackThreadStatus control for MIDI.");
ThreadsPanel.Controls.Add(Trck);
});

ConvertWorker Worker = new ConvertWorker(MFile.GetSingleTrackTimeBased(T), MFile.TimeLength.TotalSeconds);
ISampleWriter Writer;
WaveWriter SDestination = null;
FileStream SFOpen = null;
if (Properties.Settings.Default.PerTrackSeparateFiles)
{
// Check if we need to export each track to a file
String Folder = OPath;
ConvertWorker Worker = new ConvertWorker(MFile.GetSingleTrackTimeBased(T), MFile.TimeLength.TotalSeconds);
ISampleWriter Writer;
WaveWriter SDestination = null;
FileStream SFOpen = null;
if (Properties.Settings.Default.PerTrackSeparateFiles)
{
// We do, create folder
Folder += String.Format("\\{0}\\", Path.GetFileNameWithoutExtension(MFile.Name));

if (!Directory.Exists(Folder))
Directory.CreateDirectory(Folder);
// 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}",
Folder, T, Properties.Settings.Default.Codec);

// Check if file already exists
if (File.Exists(SOutputDir))
SOutputDir = String.Format("{0}Track {1} - {2}.{3}",
Folder, T, DateTime.Now.ToString("dd-MM-yyyy HHmmsstt"), Properties.Settings.Default.Codec);

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);
}
else Folder += " ";
else Writer = MSM.GetWriter();

// Prepare the filename
String SOutputDir = String.Format("{0}Track {1}.{2}",
Folder, T, Properties.Settings.Default.Codec);
Task ConvThread = Task.Run(() =>
{
Worker.Convert(Writer, WF, false, CTS.Token);
});

// Check if file already exists
if (File.Exists(SOutputDir))
SOutputDir = String.Format("{0}Track {1} - {2}.{3}",
Folder, T, DateTime.Now.ToString("dd-MM-yyyy HHmmsstt"), Properties.Settings.Default.Codec);
while (!ConvThread.IsCompleted)
{
if (StopRequested)
break;

Debug.PrintToConsole("ok", String.Format("{0} - Output file: {1}", T, SOutputDir));
Trck.Invoke((MethodInvoker)delegate
{
Trck.UpdatePB(Convert.ToInt32(Math.Round(Worker.Progress * 100)));
});

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

Task ConvThread = Task.Run(() =>
{
Worker.Convert(Writer, WF, false, PO.CancellationToken);
});
ConvThread.Wait();

while (!ConvThread.IsCompleted)
{
if (StopRequested)
break;
if (SDestination != null) SDestination.Dispose();
if (SFOpen != null) SFOpen.Dispose();

Trck.Invoke((MethodInvoker)delegate
ThreadsPanel.Invoke((MethodInvoker)delegate
{
Trck.UpdatePB(Convert.ToInt32(Math.Round(Worker.Progress * 100)));
Debug.PrintToConsole("ok", String.Format("{0} - Removed TrackThreadStatus control for MIDI.", T));
ThreadsPanel.Controls.Remove(Trck);
});

Thread.Sleep(200);
if (!StopRequested) MDV.AddTrack();
}

ConvThread.Wait();

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

ThreadsPanel.Invoke((MethodInvoker)delegate
{
Debug.PrintToConsole("ok", String.Format("{0} - Removed TrackThreadStatus control for MIDI.", T));
ThreadsPanel.Controls.Remove(Trck);
});

if (!StopRequested) MDV.AddTrack();

PO.CancellationToken.ThrowIfCancellationRequested();
});
}
catch (OperationCanceledException) { }
Expand Down Expand Up @@ -587,12 +584,12 @@ private void MIDIConversionTbT(Control Form, Panel ThreadsPanel, String OPath)
Form.Invoke((MethodInvoker)delegate { ((Form)Form).Close(); });
}

static void ParallelFor(int from, int to, int threads, CancellationToken cancel, Action<int> func)
static void ParallelFor(Int64 from, Int64 to, int threads, CancellationToken cancel, Action<Int64> func)
{
Dictionary<int, Task> tasks = new Dictionary<int, Task>();
BlockingCollection<int> completed = new BlockingCollection<int>();
Dictionary<Int64, Task> tasks = new Dictionary<Int64, Task>();
BlockingCollection<Int64> completed = new BlockingCollection<Int64>();

void RunTask(int i)
void RunTask(Int64 i)
{
var t = new Task(() =>
{
Expand All @@ -614,7 +611,7 @@ void TryTake()
tasks.Remove(t);
}

for (int i = from; i < to; i++)
for (Int64 i = from; i < to; i++)
{
RunTask(i);
if (tasks.Count > threads) TryTake();
Expand Down
12 changes: 6 additions & 6 deletions OmniConverter/Extensions/MIDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class MIDI : IDisposable
private MidiFile LoadedFile;
private IEnumerable<MIDIEvent> MetaEvents;

private MIDI(Int64 I, String FN, String FP, MidiFile LF, IEnumerable<MIDIEvent> ME, TimeSpan TL, Int32 T, Int64 NC, UInt64 S)
private MIDI(Int64 I, String FN, String FP, MidiFile LF, IEnumerable<MIDIEvent> ME, TimeSpan TL, Int64 T, Int64 NC, UInt64 S)
{
ID = I;
Name = FN;
Expand All @@ -27,7 +27,7 @@ private MIDI(Int64 I, String FN, String FP, MidiFile LF, IEnumerable<MIDIEvent>
MetaEvents = ME;
}

public IEnumerable<MIDIEvent> GetSingleTrackTimeBased(int track) =>
public IEnumerable<MIDIEvent> GetSingleTrackTimeBased(Int64 track) =>
LoadedFile.GetTrack(track).MergeWith(MetaEvents).MakeTimeBased(LoadedFile.PPQ);

public IEnumerable<MIDIEvent> GetFullMIDITimeBased() =>
Expand All @@ -40,21 +40,21 @@ public IEnumerable<IEnumerable<MIDIEvent>> GetIterateTracksTimeBased() =>
public String Name { get; }
public String Path { get; }
public TimeSpan TimeLength { get; }
public Int32 Tracks { get; }
public Int64 Tracks { get; }
public Int64 NoteCount { get; }
public UInt64 Size { get; }

public static MIDI LoadFromFile(long id, string filepath, string name, Action<int, int> progressCallback)
public static MIDI LoadFromFile(long id, string filepath, string name, Action<Int64, Int64> progressCallback)
{
var file = new MidiFile(filepath);
ulong fileSize = (ulong)new FileInfo(filepath).Length;

double maxTicks = 0;
int noteCount = 0;
Int64 noteCount = 0;
object l = new object();

var midiMetaEvents = new List<IEnumerable<MIDIEvent>>();
int tracksParsed = 0;
Int64 tracksParsed = 0;

// loop over all tracks in parallel
Parallel.ForEach(file.IterateTracks(), ev =>
Expand Down
11 changes: 11 additions & 0 deletions OmniConverter/Extensions/MandatoryClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ public void SetNewValues(Int32 SP, Int32 SB, Int32 DP, Int32 DB, Int32 DBLSB, Bo
public Boolean GetXGMode { get { return XGMode; } }
}

public class VST
{
private string VSTPath;
private Int32 VSTHandle { get; set; }

public VST()
{
VSTPath = null;
}
}

public class SoundFonts
{
public List<SoundFont> List;
Expand Down
2 changes: 1 addition & 1 deletion OmniConverter/Extensions/StreamWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public long Position
get => position;
set
{
if (value > Length || value < 0) throw new Exception("Position out of range");
if (value > Length || value < 0) throw new Exception(String.Format("Position out of range!\n\nValue: {0}\nMaximum value: {1}", value, Length));
position = value;
}
}
Expand Down
4 changes: 2 additions & 2 deletions OmniConverter/Forms/MIDIConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ private void Check_Tick(object sender, EventArgs e)
UInt64 InvalidFiles = Cnv.MDV.GetInvalidMIDIsCount();
UInt64 TotalFiles = Cnv.MDV.GetTotalMIDIsCount();

Int32 Tracks = Cnv.MDV.GetTotalTracks();
Int32 CurrentTrack = Cnv.MDV.GetCurrentTrack();
Int64 Tracks = Cnv.MDV.GetTotalTracks();
Int64 CurrentTrack = Cnv.MDV.GetCurrentTrack();

switch (Cnv.GetStatus())
{
Expand Down
1 change: 1 addition & 0 deletions OmniConverter/OmniConverter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
Expand Down
Loading

0 comments on commit e68e1e6

Please sign in to comment.