From 7e56c5b9bed066f5d93293af1d1dacc5593ec016 Mon Sep 17 00:00:00 2001 From: bri Date: Wed, 11 Oct 2023 12:15:06 +0200 Subject: [PATCH] Version 0.0.11 --- OmniConverter/Extensions/Converter.cs | 167 +++++++++++++-------- OmniConverter/Extensions/MIDI.cs | 2 + OmniConverter/Forms/InfoWindow.cs | 8 +- OmniConverter/Forms/MainWindow.Designer.cs | 16 +- OmniConverter/Forms/MainWindow.cs | 6 + OmniConverter/Forms/Settings.resx | 62 +++++++- OmniConverter/OmniConverter.csproj | 1 - 7 files changed, 193 insertions(+), 69 deletions(-) diff --git a/OmniConverter/Extensions/Converter.cs b/OmniConverter/Extensions/Converter.cs index 697fbab..b368660 100644 --- a/OmniConverter/Extensions/Converter.cs +++ b/OmniConverter/Extensions/Converter.cs @@ -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); @@ -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(); @@ -387,6 +388,20 @@ 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 @@ -394,40 +409,34 @@ private void PerTrackConv(int MT, CSCore.WaveFormat WF, Panel ThreadsPanel, stri // 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 @@ -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; @@ -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) { @@ -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(); } }); @@ -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(); } } diff --git a/OmniConverter/Extensions/MIDI.cs b/OmniConverter/Extensions/MIDI.cs index 8c74784..0c8aa08 100644 --- a/OmniConverter/Extensions/MIDI.cs +++ b/OmniConverter/Extensions/MIDI.cs @@ -38,6 +38,8 @@ public IEnumerable GetFullMIDITimeBased() => public IEnumerable> 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; } diff --git a/OmniConverter/Forms/InfoWindow.cs b/OmniConverter/Forms/InfoWindow.cs index ca553af..b076e06 100644 --- a/OmniConverter/Forms/InfoWindow.cs +++ b/OmniConverter/Forms/InfoWindow.cs @@ -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); @@ -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) diff --git a/OmniConverter/Forms/MainWindow.Designer.cs b/OmniConverter/Forms/MainWindow.Designer.cs index 394da5f..07c774a 100644 --- a/OmniConverter/Forms/MainWindow.Designer.cs +++ b/OmniConverter/Forms/MainWindow.Designer.cs @@ -79,6 +79,7 @@ private void InitializeComponent() OCMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { Files, Help }); OCMenu.Location = new System.Drawing.Point(0, 0); OCMenu.Name = "OCMenu"; + OCMenu.RenderMode = System.Windows.Forms.ToolStripRenderMode.System; OCMenu.Size = new System.Drawing.Size(784, 24); OCMenu.TabIndex = 1; // @@ -91,6 +92,7 @@ private void InitializeComponent() // // AddMIDIsToQueue // + AddMIDIsToQueue.Image = Properties.Resources.Add; AddMIDIsToQueue.Name = "AddMIDIsToQueue"; AddMIDIsToQueue.Size = new System.Drawing.Size(235, 22); AddMIDIsToQueue.Text = "Add MIDIs to the queue"; @@ -98,6 +100,7 @@ private void InitializeComponent() // // RemoveMIDIsFromQueue // + RemoveMIDIsFromQueue.Image = Properties.Resources.Remove; RemoveMIDIsFromQueue.Name = "RemoveMIDIsFromQueue"; RemoveMIDIsFromQueue.Size = new System.Drawing.Size(235, 22); RemoveMIDIsFromQueue.Text = "Remove MIDIs from the queue"; @@ -105,6 +108,7 @@ private void InitializeComponent() // // ClearQueue // + ClearQueue.Image = Properties.Resources.Clear; ClearQueue.Name = "ClearQueue"; ClearQueue.Size = new System.Drawing.Size(235, 22); ClearQueue.Text = "Clear queue"; @@ -117,6 +121,7 @@ private void InitializeComponent() // // ExitFromConverter // + ExitFromConverter.Image = Properties.Resources.Sleep; ExitFromConverter.Name = "ExitFromConverter"; ExitFromConverter.Size = new System.Drawing.Size(235, 22); ExitFromConverter.Text = "Exit"; @@ -131,6 +136,7 @@ private void InitializeComponent() // // InfoAboutConverter // + InfoAboutConverter.Image = Properties.Resources.Info; InfoAboutConverter.Name = "InfoAboutConverter"; InfoAboutConverter.Size = new System.Drawing.Size(276, 22); InfoAboutConverter.Text = "Information about the converter"; @@ -143,12 +149,14 @@ private void InitializeComponent() // // CreateIssueGitHub // + CreateIssueGitHub.Image = Properties.Resources.Octocat; CreateIssueGitHub.Name = "CreateIssueGitHub"; CreateIssueGitHub.Size = new System.Drawing.Size(276, 22); CreateIssueGitHub.Text = "Create an issue on GitHub"; // // CheckForUpdates // + CheckForUpdates.Image = Properties.Resources.Download; CheckForUpdates.Name = "CheckForUpdates"; CheckForUpdates.Size = new System.Drawing.Size(276, 22); CheckForUpdates.Text = "Check for updates"; @@ -161,9 +169,11 @@ private void InitializeComponent() // // DownloadConvSrc // + DownloadConvSrc.Image = Properties.Resources.Octocat; DownloadConvSrc.Name = "DownloadConvSrc"; DownloadConvSrc.Size = new System.Drawing.Size(276, 22); DownloadConvSrc.Text = "Download the converter's source code"; + DownloadConvSrc.Click += DownloadConvSrc_Click; // // InfoBox // @@ -398,10 +408,12 @@ private void InitializeComponent() // OCContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { AddMIDIsToQueueRC, RemoveMIDIsFromQueueRC, ClearQueueRC }); OCContextMenu.Name = "OCContextMenu"; - OCContextMenu.Size = new System.Drawing.Size(236, 70); + OCContextMenu.RenderMode = System.Windows.Forms.ToolStripRenderMode.System; + OCContextMenu.Size = new System.Drawing.Size(236, 92); // // AddMIDIsToQueueRC // + AddMIDIsToQueueRC.Image = Properties.Resources.Add; AddMIDIsToQueueRC.Name = "AddMIDIsToQueueRC"; AddMIDIsToQueueRC.Size = new System.Drawing.Size(235, 22); AddMIDIsToQueueRC.Text = "Add MIDIs to the queue"; @@ -409,6 +421,7 @@ private void InitializeComponent() // // RemoveMIDIsFromQueueRC // + RemoveMIDIsFromQueueRC.Image = Properties.Resources.Remove; RemoveMIDIsFromQueueRC.Name = "RemoveMIDIsFromQueueRC"; RemoveMIDIsFromQueueRC.Size = new System.Drawing.Size(235, 22); RemoveMIDIsFromQueueRC.Text = "Remove MIDIs from the queue"; @@ -416,6 +429,7 @@ private void InitializeComponent() // // ClearQueueRC // + ClearQueueRC.Image = Properties.Resources.Clear; ClearQueueRC.Name = "ClearQueueRC"; ClearQueueRC.Size = new System.Drawing.Size(235, 22); ClearQueueRC.Text = "Clear queue"; diff --git a/OmniConverter/Forms/MainWindow.cs b/OmniConverter/Forms/MainWindow.cs index 2ef0210..469ee4d 100644 --- a/OmniConverter/Forms/MainWindow.cs +++ b/OmniConverter/Forms/MainWindow.cs @@ -2,6 +2,7 @@ using Octokit; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.IO; using System.Windows.Forms; @@ -315,5 +316,10 @@ private void CheckForUpdates_Click(object sender, EventArgs e) { UpdateSystem.CheckForUpdates((Control.ModifierKeys == Keys.Shift), false, false); } + + private void DownloadConvSrc_Click(object sender, EventArgs e) + { + Process.Start(new ProcessStartInfo("https://github.com/KaleidonKep99/OmniConverter") { UseShellExecute = true }); + } } } diff --git a/OmniConverter/Forms/Settings.resx b/OmniConverter/Forms/Settings.resx index f298a7b..a395bff 100644 --- a/OmniConverter/Forms/Settings.resx +++ b/OmniConverter/Forms/Settings.resx @@ -1,4 +1,64 @@ - + + + diff --git a/OmniConverter/OmniConverter.csproj b/OmniConverter/OmniConverter.csproj index ab5c197..996a8b0 100644 --- a/OmniConverter/OmniConverter.csproj +++ b/OmniConverter/OmniConverter.csproj @@ -92,7 +92,6 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive