Skip to content

Commit

Permalink
OMv15: JSON moved to %userprofile%\OmniMIDI\lists\OmniMIDI_A.json, an…
Browse files Browse the repository at this point in the history
…d removed pch.h
  • Loading branch information
bribi5940 committed Jun 30, 2023
1 parent 4b39a52 commit 51f75af
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 91 deletions.
1 change: 0 additions & 1 deletion OmniMIDIv2/ErrSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ This file contains the required code to run the driver under Windows 7 SP1 and l
This file is useful only if you want to compile the driver under Windows, it's not needed for Linux/macOS porting.
*/

#include "pch.h"
#include "ErrSys.h"

#ifdef _WIN32
Expand Down
30 changes: 14 additions & 16 deletions OmniMIDIv2/OmniMIDI.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;OMNIMIDI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
Expand All @@ -108,8 +109,9 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;OMNIMIDI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
Expand All @@ -128,8 +130,9 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;OMNIMIDI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
Expand All @@ -148,8 +151,9 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;OMNIMIDI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
Expand All @@ -164,9 +168,8 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="ErrSys.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="SynthMain.h" />
<ClInclude Include="Utils.h" />
<ClInclude Include="WDMDrv.h" />
</ItemGroup>
<ItemGroup>
Expand All @@ -175,14 +178,9 @@
<ClCompile Include="basswasapi.cpp" />
<ClCompile Include="ErrSys.cpp" />
<ClCompile Include="SynthMain.cpp" />
<ClCompile Include="Utils.cpp" />
<ClCompile Include="WDMDrv.cpp" />
<ClCompile Include="WDMEntry.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="WDMEntry.h" />
Expand Down
15 changes: 6 additions & 9 deletions OmniMIDIv2/OmniMIDI.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,17 @@
<ClInclude Include="ErrSys.h">
<Filter>Header Files\Extensions</Filter>
</ClInclude>
<ClInclude Include="framework.h">
<Filter>Header Files\Mandatory</Filter>
</ClInclude>
<ClInclude Include="pch.h">
<Filter>Header Files\Mandatory</Filter>
</ClInclude>
<ClInclude Include="WDMDrv.h">
<Filter>Header Files\WDM</Filter>
</ClInclude>
<ClInclude Include="SynthMain.h">
<Filter>Header Files\Synthesizer</Filter>
</ClInclude>
<ClInclude Include="Utils.h">
<Filter>Header Files\Extensions</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ErrSys.cpp">
<Filter>Source Files\Extensions</Filter>
</ClCompile>
Expand All @@ -83,6 +77,9 @@
<ClCompile Include="basswasapi.cpp">
<Filter>Source Files\Synthesizer\BASS</Filter>
</ClCompile>
<ClCompile Include="Utils.cpp">
<Filter>Source Files\Extensions</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="WDMEntry.h">
Expand Down
132 changes: 75 additions & 57 deletions OmniMIDIv2/SynthMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ This file contains the required code to run the driver under Windows 7 SP1 and l
This file is useful only if you want to compile the driver under Windows, it's not needed for Linux/macOS porting.
*/

#include "pch.h"
#include "SynthMain.h"

bool OmniMIDI::SynthModule::LoadLib(Lib* Target) {
Expand All @@ -28,41 +27,25 @@ bool OmniMIDI::SynthModule::LoadLib(Lib* Target) {
// Otherwise, let's load our own
else {
// Let's get the system path
PWSTR Dir;
LSTATUS Success = SHGetKnownFolderPath(FOLDERID_System, 0, NULL, &Dir);
bool Good = SUCCEEDED(Success);
assert(Good == true);

if (Good)
{
Success = StringCchPrintfW(SysDir, sizeof(SysDir), L"%ws", Dir);
Good = SUCCEEDED(Success);
assert(Good == true);
}

CoTaskMemFree((LPVOID)Dir);

// If we failed to get a system path,
// return false
if (!Good)
return false;

int swp = swprintf_s(DLLPath, MAX_PATH, L"%s.dll\0", Target->Path);
assert(swp != -1);

Target->Library = LoadLibrary(DLLPath);

if (!Target->Library)
{
swp = swprintf_s(DLLPath, MAX_PATH, L"%s\\OmniMIDI\\%s.dll\0", SysDir, Target->Path);
if (Utils.GetFolderPath(FOLDERID_System, SysDir, sizeof(SysDir))) {
int swp = swprintf_s(DLLPath, MAX_PATH, L"%s.dll\0", Target->Path);
assert(swp != -1);

Target->Library = LoadLibrary(DLLPath);
assert(Target->Library != 0);

if (!Target->Library)
return false;
{
swp = swprintf_s(DLLPath, MAX_PATH, L"%s\\OmniMIDI\\%s.dll\0", SysDir, Target->Path);
assert(swp != -1);

Target->Library = LoadLibrary(DLLPath);
assert(Target->Library != 0);

if (!Target->Library)
return false;
}
}
else return false;
}
}

Expand Down Expand Up @@ -238,12 +221,25 @@ bool OmniMIDI::SynthModule::LoadFuncs() {
int limit = sizeof(LibImports) / sizeof(LibImports[0]);

if (!NanoSleep)
NanoSleep = (unsigned int (WINAPI*)(unsigned char, signed long long*))GetProcAddress(GetModuleHandle(L"ntdll"), "NtDelayExecution");
{
auto mod = GetModuleHandleA("ntdll");
assert(mod != 0);

if (!mod)
{
FNERROR(SynErr, L"Could not load NTDLL from memory!!! What's happening???");
return false;
}

assert(NanoSleep != 0);
NanoSleep = (unsigned int (WINAPI*)(unsigned char, signed long long*))GetProcAddress(mod, "NtDelayExecution");
assert(NanoSleep != 0);

if (!NanoSleep)
FNERROR(SynErr, L"Where's NtDelayExecution... Is this Windows 95?");
if (!NanoSleep)
{
FNERROR(SynErr, L"Where's NtDelayExecution... Is this Windows 95?");
return false;
}
}

void* ptr = nullptr;

Expand Down Expand Up @@ -335,8 +331,13 @@ bool OmniMIDI::SynthModule::UnloadSynthModule() {
}

bool OmniMIDI::SynthModule::StartSynthModule() {
// SF path
wchar_t OMPath[MAX_PATH] = { 0 };

// BASS stream flags
unsigned int StreamFlags = BASS_SAMPLE_FLOAT | BASS_MIDI_ASYNC;

// If the audio stream is not 0, then stream is allocated already
if (AudioStream)
return true;

Expand Down Expand Up @@ -386,6 +387,7 @@ bool OmniMIDI::SynthModule::StartSynthModule() {
return false;
}

#pragma warning(suppress: 4312)
if (!BASS_WASAPI_Init(-1, 0, 0, BASS_WASAPI_ASYNC | BASS_WASAPI_EVENT | BASS_WASAPI_SAMPLES, 32.0f, 0, WASAPIPROC_BASS, (void*)AudioStream)) {
NERROR(SynErr, L"BASS_WASAPI_Init failed.", false);
return false;
Expand All @@ -404,38 +406,54 @@ bool OmniMIDI::SynthModule::StartSynthModule() {
return false;
}

std::fstream sfs;
sfs.open(L"E:\\GitHub\\OmniMIDI\\OmniMIDIv2\\x64\\Release\\paolo.json");
if (Utils.GetFolderPath(FOLDERID_Profile, OMPath, sizeof(OMPath))) {
swprintf_s(OMPath, L"%s\\OmniMIDI\\lists\\OmniMIDI_A.json\0", OMPath);

std::fstream sfs;
sfs.open(OMPath);

if (sfs.is_open()) {
// Read the JSON data from there
auto json = nlohmann::json::parse(sfs, nullptr, false, true);

if (json != nullptr) {
auto JsonData = json["SoundFonts"];

if (sfs.is_open()) {
JsonData = nlohmann::json::parse(sfs, nullptr, false, true);
if (!(JsonData == nullptr || JsonData.size() < 1)) {
for (int i = 0; i < JsonData.size(); i++) {
BASS_MIDI_FONTEX sf;
nlohmann::json subitem = JsonData[i];

for (int i = 0; i < JsonData["SoundFonts"].size(); i++) {
BASS_MIDI_FONTEX sf;
// Is item valid?
if (subitem != nullptr) {
std::string sfpath = subitem["path"];

nlohmann::json subitem = JsonData["SoundFonts"][i];
sf.font = BASS_MIDI_FontInit(sfpath.c_str(), BASS_MIDI_FONT_NOLIMITS | BASS_MIDI_FONT_MMAP);
sf.spreset = subitem["spreset"];
sf.sbank = subitem["sbank"];
sf.dpreset = subitem["dpreset"];
sf.dbank = subitem["dbank"];
sf.dbanklsb = subitem["dbanklsb"];

if (subitem != nullptr) {
std::string path = subitem["path"];
// Check if the soundfont loads, if it does then it's valid
if (BASS_MIDI_FontLoad(sf.font, sf.spreset, sf.sbank))
SoundFonts.push_back(sf);
}

sf.font = BASS_MIDI_FontInit(path.c_str(), BASS_MIDI_FONT_NOLIMITS | BASS_MIDI_FONT_MMAP);
sf.spreset = subitem["spreset"]; // all presets
sf.sbank = subitem["sbank"]; // all banks
sf.dpreset = subitem["dpreset"]; // all presets
sf.dbank = subitem["dbank"]; // default banks
sf.dbanklsb = subitem["dbanklsb"]; // destination bank LSB 0
BASS_MIDI_FontLoad(sf.font, sf.spreset, sf.sbank);
// If it's not, then let's loop until the end of the JSON struct
}

SoundFonts.push_back(sf);
std::reverse(SoundFonts.begin(), SoundFonts.end());
BASS_MIDI_StreamSetFonts(AudioStream, &SoundFonts[0], (unsigned int)SoundFonts.size() | BASS_MIDI_FONT_EX);
}
else NERROR(SynErr, L"SoundFonts JSON does exist, but it does not contain the required items.", false);
}
else NERROR(SynErr, L"Imvalid JSON structure!", false);

sfs.close();
}
else NERROR(SynErr, L"SoundFonts JSON does not exist.", false);
}
else LOG(SynErr, L"JsonData for SoundFonts does not exist!");

sfs.close();

std::reverse(SoundFonts.begin(), SoundFonts.end());
BASS_MIDI_StreamSetFonts(AudioStream, &SoundFonts[0], (unsigned int)SoundFonts.size() | BASS_MIDI_FONT_EX);

BASS_ChannelSetAttribute(AudioStream, BASS_ATTRIB_BUFFER, 1);
BASS_ChannelSetAttribute(AudioStream, BASS_ATTRIB_MIDI_VOICES, 1000);
Expand Down
6 changes: 3 additions & 3 deletions OmniMIDIv2/SynthMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ typedef unsigned int SynthResult;
#define EvBuf EvBuf_t

#include <Windows.h>
#include <ShlObj_core.h>
#include <strsafe.h>
#include <bass.h>
#include <basswasapi.h>
Expand All @@ -73,8 +72,9 @@ typedef unsigned int SynthResult;
#include <vector>
#include <codecvt>
#include <locale>
#include <nlohmann\json.hpp>
#include "ErrSys.h"
#include "Utils.h"
#include <nlohmann\json.hpp>

namespace {
struct LibImport
Expand Down Expand Up @@ -261,7 +261,7 @@ namespace OmniMIDI {
std::thread _EvtThread;
EvBuf* Events;

nlohmann::json JsonData;
WinUtils::SysPath Utils;
signed long long onenano = -1;
unsigned int (WINAPI* NanoSleep)(unsigned char, signed long long*);
unsigned int AudioStream;
Expand Down
16 changes: 16 additions & 0 deletions OmniMIDIv2/Utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "Utils.h"

bool WinUtils::SysPath::GetFolderPath(const GUID FolderID, wchar_t* P, size_t PS) {
PWSTR Dir;
HRESULT SGKFP = SHGetKnownFolderPath(FolderID, 0, NULL, &Dir);
bool Success = SUCCEEDED(SGKFP);

if (Success)
StringCchPrintfW(P, PS, L"%ws", Dir);

CoTaskMemFree((LPVOID)Dir);

return Success;
}
18 changes: 18 additions & 0 deletions OmniMIDIv2/Utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _UTILS_H
#define _UTILS_H

#pragma once

#include <Windows.h>
#include <guiddef.h>
#include <ShlObj_core.h>
#include <strsafe.h>

namespace WinUtils {
class SysPath {
public:
bool GetFolderPath(const GUID FolderID, wchar_t* String, size_t StringLen);
};
}

#endif
1 change: 0 additions & 1 deletion OmniMIDIv2/WDMDrv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

#include "pch.h"
#include "WDMDrv.h"

#ifdef _WIN32
Expand Down
1 change: 0 additions & 1 deletion OmniMIDIv2/WDMEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ This file contains the required code to run the driver under Windows 7 SP1 and l
This file is useful only if you want to compile the driver under Windows, it's not needed for Linux/macOS porting.
*/

#include "pch.h"
#include "WDMEntry.h"

static ErrorSystem::WinErr WDMErr;
Expand Down
Loading

0 comments on commit 51f75af

Please sign in to comment.