Skip to content

Commit

Permalink
OMv15: OMLIST is dead, long live JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
bribi5940 committed Jun 30, 2023
1 parent f37fc98 commit 4b39a52
Show file tree
Hide file tree
Showing 46 changed files with 24,489 additions and 15 deletions.
42 changes: 32 additions & 10 deletions OmniMIDIv2/SynthMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ bool OmniMIDI::SynthModule::UnloadFuncs() {
bool OmniMIDI::SynthModule::LoadSynthModule() {
// LOG(SynErr, L"LoadSynthModule called.");
if (LoadFuncs()) {
SoundFonts = new BASS_MIDI_FONTEX[1];
Events = new EvBuf(32768);
_EvtThread = std::thread(&SynthModule::EventsThread, this);
// LOG(SynErr, L"LoadFuncs succeeded.");
Expand All @@ -327,7 +326,7 @@ bool OmniMIDI::SynthModule::UnloadSynthModule() {
Events->GetStats();
delete Events;

delete[] SoundFonts;
SoundFonts.clear();
return true;
}

Expand Down Expand Up @@ -405,15 +404,38 @@ bool OmniMIDI::SynthModule::StartSynthModule() {
return false;
}

SoundFonts[0].font = BASS_MIDI_FontInit(L"E:\\Archive\\MIDIs\\SoundFonts\\piano korg triton.sf2", BASS_UNICODE | BASS_MIDI_FONT_NOLIMITS | BASS_MIDI_FONT_MMAP);
SoundFonts[0].spreset = -1; // all presets
SoundFonts[0].sbank = -1; // all banks
SoundFonts[0].dpreset = -1; // all presets
SoundFonts[0].dbank = 0; // default banks
SoundFonts[0].dbanklsb = 0; // destination bank LSB 0
std::fstream sfs;
sfs.open(L"E:\\GitHub\\OmniMIDI\\OmniMIDIv2\\x64\\Release\\paolo.json");

BASS_MIDI_FontLoad(SoundFonts[0].font, SoundFonts[0].spreset, SoundFonts[0].sbank);
BASS_MIDI_StreamSetFonts(AudioStream, SoundFonts, 1 | BASS_MIDI_FONT_EX);
if (sfs.is_open()) {
JsonData = nlohmann::json::parse(sfs, nullptr, false, true);

for (int i = 0; i < JsonData["SoundFonts"].size(); i++) {
BASS_MIDI_FONTEX sf;

nlohmann::json subitem = JsonData["SoundFonts"][i];

if (subitem != nullptr) {
std::string path = subitem["path"];

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);

SoundFonts.push_back(sf);
}
}
}
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
15 changes: 10 additions & 5 deletions OmniMIDIv2/SynthMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,21 @@ typedef unsigned int SynthResult;
#define EvBuf EvBuf_t

#include <Windows.h>
#include <ShlObj_core.h>
#include <strsafe.h>
#include <bass.h>
#include <basswasapi.h>
#include <bassmidi.h>
#include <thread>
#include <atomic>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <ShlObj_core.h>
#include <strsafe.h>
#include <codecvt>
#include <locale>
#include <nlohmann\json.hpp>
#include "ErrSys.h"

namespace {
Expand Down Expand Up @@ -256,10 +261,11 @@ namespace OmniMIDI {
std::thread _EvtThread;
EvBuf* Events;

nlohmann::json JsonData;
signed long long onenano = -1;
unsigned int (WINAPI* NanoSleep)(unsigned char, signed long long*);
unsigned int AudioStream;
BASS_MIDI_FONTEX* SoundFonts;
std::vector<BASS_MIDI_FONTEX> SoundFonts;

int AudioEngine = WASAPI;
char LastRunningStatus = 0x0;
Expand All @@ -269,18 +275,17 @@ namespace OmniMIDI {
bool LoadFuncs();
bool UnloadFuncs();

unsigned int WASAPIProc(void* buffer, unsigned int length, void* user);
void AudioThread();
void EventsThread();
bool ProcessEvBuf();

public:
bool IsSynthInitialized() { return (AudioStream != 0); }
bool LoadSynthModule();
bool UnloadSynthModule();
bool StartSynthModule();
bool StopSynthModule();
bool ChangeSetting(unsigned int setting, void* var, size_t size);
bool IsSynthInitialized() { return (AudioStream != 0); }

// Event handling system
SynthResult PlayShortEvent(unsigned int ev);
Expand Down
55 changes: 55 additions & 0 deletions OmniMIDIv2/inc/nlohmann/adl_serializer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT

#pragma once

#include <utility>

#include <nlohmann/detail/abi_macros.hpp>
#include <nlohmann/detail/conversions/from_json.hpp>
#include <nlohmann/detail/conversions/to_json.hpp>
#include <nlohmann/detail/meta/identity_tag.hpp>

NLOHMANN_JSON_NAMESPACE_BEGIN

/// @sa https://json.nlohmann.me/api/adl_serializer/
template<typename ValueType, typename>
struct adl_serializer
{
/// @brief convert a JSON value to any value type
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
{
::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
}

/// @brief convert a JSON value to any value type
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
{
return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
}

/// @brief convert any value type to a JSON value
/// @sa https://json.nlohmann.me/api/adl_serializer/to_json/
template<typename BasicJsonType, typename TargetType = ValueType>
static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
{
::nlohmann::to_json(j, std::forward<TargetType>(val));
}
};

NLOHMANN_JSON_NAMESPACE_END
103 changes: 103 additions & 0 deletions OmniMIDIv2/inc/nlohmann/byte_container_with_subtype.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT

#pragma once

#include <cstdint> // uint8_t, uint64_t
#include <tuple> // tie
#include <utility> // move

#include <nlohmann/detail/abi_macros.hpp>

NLOHMANN_JSON_NAMESPACE_BEGIN

/// @brief an internal type for a backed binary type
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/
template<typename BinaryType>
class byte_container_with_subtype : public BinaryType
{
public:
using container_type = BinaryType;
using subtype_type = std::uint64_t;

/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype() noexcept(noexcept(container_type()))
: container_type()
{}

/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b)))
: container_type(b)
{}

/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
: container_type(std::move(b))
{}

/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
: container_type(b)
, m_subtype(subtype_)
, m_has_subtype(true)
{}

/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
: container_type(std::move(b))
, m_subtype(subtype_)
, m_has_subtype(true)
{}

bool operator==(const byte_container_with_subtype& rhs) const
{
return std::tie(static_cast<const BinaryType&>(*this), m_subtype, m_has_subtype) ==
std::tie(static_cast<const BinaryType&>(rhs), rhs.m_subtype, rhs.m_has_subtype);
}

bool operator!=(const byte_container_with_subtype& rhs) const
{
return !(rhs == *this);
}

/// @brief sets the binary subtype
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/set_subtype/
void set_subtype(subtype_type subtype_) noexcept
{
m_subtype = subtype_;
m_has_subtype = true;
}

/// @brief return the binary subtype
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/subtype/
constexpr subtype_type subtype() const noexcept
{
return m_has_subtype ? m_subtype : static_cast<subtype_type>(-1);
}

/// @brief return whether the value has a subtype
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/has_subtype/
constexpr bool has_subtype() const noexcept
{
return m_has_subtype;
}

/// @brief clears the binary subtype
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/clear_subtype/
void clear_subtype() noexcept
{
m_subtype = 0;
m_has_subtype = false;
}

private:
subtype_type m_subtype = 0;
bool m_has_subtype = false;
};

NLOHMANN_JSON_NAMESPACE_END
100 changes: 100 additions & 0 deletions OmniMIDIv2/inc/nlohmann/detail/abi_macros.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT

#pragma once

// This file contains all macro definitions affecting or depending on the ABI

#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
#if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)
#if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 2
#warning "Already included a different version of the library!"
#endif
#endif
#endif

#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum)
#define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum)
#define NLOHMANN_JSON_VERSION_PATCH 2 // NOLINT(modernize-macro-to-enum)

#ifndef JSON_DIAGNOSTICS
#define JSON_DIAGNOSTICS 0
#endif

#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
#define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0
#endif

#if JSON_DIAGNOSTICS
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag
#else
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS
#endif

#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp
#else
#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON
#endif

#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
#endif

// Construct the namespace ABI tags component
#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b
#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \
NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b)

#define NLOHMANN_JSON_ABI_TAGS \
NLOHMANN_JSON_ABI_TAGS_CONCAT( \
NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON)

// Construct the namespace version component
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
_v ## major ## _ ## minor ## _ ## patch
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)

#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
#define NLOHMANN_JSON_NAMESPACE_VERSION
#else
#define NLOHMANN_JSON_NAMESPACE_VERSION \
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \
NLOHMANN_JSON_VERSION_MINOR, \
NLOHMANN_JSON_VERSION_PATCH)
#endif

// Combine namespace components
#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b
#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \
NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)

#ifndef NLOHMANN_JSON_NAMESPACE
#define NLOHMANN_JSON_NAMESPACE \
nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \
NLOHMANN_JSON_ABI_TAGS, \
NLOHMANN_JSON_NAMESPACE_VERSION)
#endif

#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
#define NLOHMANN_JSON_NAMESPACE_BEGIN \
namespace nlohmann \
{ \
inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
NLOHMANN_JSON_ABI_TAGS, \
NLOHMANN_JSON_NAMESPACE_VERSION) \
{
#endif

#ifndef NLOHMANN_JSON_NAMESPACE_END
#define NLOHMANN_JSON_NAMESPACE_END \
} /* namespace (inline namespace) NOLINT(readability/namespace) */ \
} // namespace nlohmann
#endif
Loading

0 comments on commit 4b39a52

Please sign in to comment.