Skip to content

Commit

Permalink
Merge pull request #1 from Kaydax/master
Browse files Browse the repository at this point in the history
Added the ability to override reverb and chorus events like omnimidi, fix loudmax, and make conversion much faster
  • Loading branch information
KaleidonKep99 authored Sep 27, 2020
2 parents a77a0b1 + 81cb740 commit ecc94dd
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 10 deletions.
10 changes: 10 additions & 0 deletions OmniConverter/Extensions/BASSMIDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ public unsafe int Read(float[] buffer, int offset, int count)
}
}

public unsafe bool SendReverbEvent(int channel, int param)
{
return BassMidi.BASS_MIDI_StreamEvent(Handle, channel, BASSMIDIEvent.MIDI_EVENT_REVERB, param);
}

public unsafe bool SendChorusEvent(int channel, int param)
{
return BassMidi.BASS_MIDI_StreamEvent(Handle, channel, BASSMIDIEvent.MIDI_EVENT_CHORUS, param);
}

public unsafe int SendEventRaw(uint data, int channel)
{
var mode = BASSMIDIEventMode.BASS_MIDI_EVENTS_RAW | BASSMIDIEventMode.BASS_MIDI_EVENTS_NORSTATUS;
Expand Down
55 changes: 51 additions & 4 deletions OmniConverter/Extensions/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using MIDIModificationFramework.MIDIEvents;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Threading;
Expand Down Expand Up @@ -97,8 +98,9 @@ public void Convert(ISampleWriter output, WaveFormat format, bool loudmax, Cance
using (var bass = new BASSMIDI(format))
{
ISampleSource bassSource;
if (loudmax) bassSource = new AntiClipping(bass, 0.1);
else bassSource = bass;
/*if (loudmax) bassSource = new AntiClipping(bass, 0.1);
else bassSource = bass;*/
bassSource = bass; //Why the hell was it running loudmax twice lol
float[] buffer = new float[2048 * 16];
long prevWriteTime = 0;
double time = 0;
Expand Down Expand Up @@ -146,6 +148,15 @@ public void Convert(ISampleWriter output, WaveFormat format, bool loudmax, Cance
}
else if (e is ControlChangeEvent)
{
if(Properties.Settings.Default.RVOverrideToggle)
{
for(int i = 0; i <= 15; i++)
{
bass.SendReverbEvent(i, Properties.Settings.Default.ReverbValue);
bass.SendChorusEvent(i, Properties.Settings.Default.ChorusValue);
}
}

var ev = e as ControlChangeEvent;
bass.SendEventRaw((uint)(0xB0 | (ev.Controller << 8) | (ev.Value << 16)), ev.Channel + 1);
}
Expand Down Expand Up @@ -423,12 +434,12 @@ private void MIDIConversionTbT(Control Form, Panel ThreadsPanel, String OPath)
ParallelOptions PO = new ParallelOptions { MaxDegreeOfParallelism = MT, CancellationToken = CTS.Token };
Debug.PrintToConsole("ok", String.Format("ParallelOptions prepared, MaxDegreeOfParallelism = {0}", MT));

Parallel.For(0, MFile.Tracks, PO, (T, LS) =>
ParallelFor(0, MFile.Tracks, Environment.ProcessorCount, new CancellationToken(false), T =>
{
if (StopRequested)
{
Debug.PrintToConsole("ok", "Stop requested. Stopping Parallel.For...");
LS.Stop();
//LS.Stop();
return;
}

Expand Down Expand Up @@ -575,5 +586,41 @@ private void MIDIConversionTbT(Control Form, Panel ThreadsPanel, String OPath)
if (!StopRequested && !IsCrash)
Form.Invoke((MethodInvoker)delegate { ((Form)Form).Close(); });
}

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

void RunTask(int i)
{
var t = new Task(() =>
{
try
{
func(i);
completed.Add(i);
}
catch (Exception e) { }
});
tasks.Add(i, t);
t.Start();
}

void TryTake()
{
var t = completed.Take(cancel);
tasks[t].Wait();
tasks.Remove(t);
}

for (int i = from; i < to; i++)
{
RunTask(i);
if (tasks.Count > threads) TryTake();
}

while (completed.Count > 0 || tasks.Count > 0) TryTake();
}
}
}
2 changes: 1 addition & 1 deletion OmniConverter/Forms/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void RebindList()

MIDIQueue.DataSource = null;
MIDIQueue.DataSource = Program.MIDIList;
MIDIQueue.DisplayMember = "GetName";
MIDIQueue.DisplayMember = "Name";

Debug.PrintToConsole("ok", "MIDIQueue bound successfully.");
}
Expand Down
103 changes: 98 additions & 5 deletions OmniConverter/Forms/Settings.Designer.cs

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

16 changes: 16 additions & 0 deletions OmniConverter/Forms/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ private void Settings_Load(object sender, EventArgs e)
NoteOff1.Checked = Properties.Settings.Default.NoteOff1;
EnableLoudMax.Checked = Properties.Settings.Default.LoudMax;

EnableRCOverride.Checked = Properties.Settings.Default.RVOverrideToggle;
ReverbV.Value = Properties.Settings.Default.ReverbValue;
ChorusV.Value = Properties.Settings.Default.ChorusValue;

MTMode.Checked = Properties.Settings.Default.MultiThreadedMode;
PerTrackMode.Checked = Properties.Settings.Default.PerTrackExport;
PerTrackExportEach.Checked = Properties.Settings.Default.PerTrackSeparateFiles;
Expand Down Expand Up @@ -87,6 +91,14 @@ private void DoActionAfterRender_CheckedChanged(object sender, EventArgs e)
DoActionAfterRenderVal.Enabled = DoActionAfterRender.Checked;
}

private void EnableRCOverride_CheckedChanged(object sender, EventArgs e)
{
ReverbL.Enabled = EnableRCOverride.Checked;
ReverbV.Enabled = EnableRCOverride.Checked;
ChorusL.Enabled = EnableRCOverride.Checked;
ChorusV.Enabled = EnableRCOverride.Checked;
}

private void OkBtn_Click(object sender, EventArgs e)
{
Properties.Settings.Default.VoiceLimit = (Int32)MaxVoices.Value;
Expand All @@ -97,6 +109,10 @@ private void OkBtn_Click(object sender, EventArgs e)
Properties.Settings.Default.NoteOff1 = NoteOff1.Checked;
Properties.Settings.Default.LoudMax = EnableLoudMax.Checked;

Properties.Settings.Default.RVOverrideToggle = EnableRCOverride.Checked;
Properties.Settings.Default.ReverbValue = (Int32)ReverbV.Value;
Properties.Settings.Default.ChorusValue = (Int32)ChorusV.Value;

Properties.Settings.Default.MultiThreadedMode = MTMode.Checked;
Properties.Settings.Default.PerTrackExport = PerTrackMode.Checked;
Properties.Settings.Default.PerTrackSeparateFiles = PerTrackExportEach.Checked;
Expand Down
Loading

0 comments on commit ecc94dd

Please sign in to comment.