Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions Kiva-MIDI/BASSMIDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,38 @@ public class BASSMIDI : ISampleSource

static object sfLock = new object();

public static bool IsPreRender()
{
Settings s = new Settings();

if (s.General.SelectedAudioEngine != AudioEngine.PreRender)
return false;

return true;
}

public static void InitBASS(WaveFormat format)
{
WaveFormatStatic = format;
Bass.BASS_Free();

if (!IsPreRender())
return;

if (!Bass.BASS_Init(0, WaveFormatStatic.SampleRate, BASSInit.BASS_DEVICE_NOSPEAKER, IntPtr.Zero))
throw new Exception();
}

public static void DisposeBASS()
public static void CloseBASS()
{
Bass.BASS_Free();
if (!Bass.BASS_Free())
throw new Exception();
}

public BASSMIDI(int voices, bool nofx = true)
{
if (!IsPreRender())
return;

Handle = BassMidi.BASS_MIDI_StreamCreate(16,
BASSFlag.BASS_SAMPLE_FLOAT |
BASSFlag.BASS_STREAM_DECODE |
Expand Down Expand Up @@ -79,6 +96,9 @@ public static void FreeSoundfonts()

public static void LoadSoundfonts(SoundfontData[] soundfonts)
{
if (!IsPreRender())
return;

lock (sfLock)
{
FreeSoundfonts();
Expand Down
6 changes: 1 addition & 5 deletions Kiva-MIDI/MIDIAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ public int SkippingVelocity
AudioBufferStream audioStream;
ISoundOut soundOut;

public static void Init()
{
BASSMIDI.InitBASS(format);
}

private ISoundOut GetSoundOut()
{
if (WasapiOut.IsSupportedOnCurrentPlatform)
Expand All @@ -140,6 +135,7 @@ private ISoundOut GetSoundOut()

public MIDIAudio(int bufferLength)
{
BASSMIDI.InitBASS(format);
AudioBuffer = new float[bufferLength * 2];
audioStream = new AudioBufferStream(this);
soundOut = GetSoundOut();
Expand Down
1 change: 1 addition & 0 deletions Kiva-MIDI/MIDIPreRenderPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public void Dispose()
{
ma.Dispose();
BASSMIDI.FreeSoundfonts();
BASSMIDI.CloseBASS();
disposed = true;
syncThread.GetAwaiter().GetResult();
settings.Soundfonts.SoundfontsUpdated -= OnSoundfontsChanged;
Expand Down
2 changes: 0 additions & 2 deletions Kiva-MIDI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ static void Main(string[] args)
#endif
Directory.SetCurrentDirectory(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName));

MIDIAudio.Init();

var s = new Settings();
s.InitSoundfontListner();
if (s.EnableUpdates)
Expand Down
4 changes: 4 additions & 0 deletions Kiva-MIDI/Settings/WinMMAudioSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public WinMMAudioSettings()
MIDIOUTCAPS device;
WinMM.midiOutGetDevCaps(i, out device, (uint)Marshal.SizeOf(typeof(MIDIOUTCAPS)));
name = device.szPname;

if (name == "OmniMIDI")
continue;

var item = new Grid()
{
Tag = new DeviceData() { id = i, name = name },
Expand Down