C++20 Support
This commit is contained in:
parent
cc33ed160f
commit
698e27f6a0
9 changed files with 71 additions and 9 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include "sfizz/MathHelpers.h"
|
||||
#include "sfizz/SfzHelpers.h"
|
||||
#include "sfizz/SIMDHelpers.h"
|
||||
#include "sfizz/utility/U8Strings.h"
|
||||
#include "MidiHelpers.h"
|
||||
#include <st_audiofile_libs.h>
|
||||
#include <cxxopts.hpp>
|
||||
|
|
@ -165,7 +166,7 @@ int main(int argc, char** argv)
|
|||
ERROR_IF(!synth.loadSfzFile(sfzPath), "There was an error loading the SFZ file.");
|
||||
LOG_INFO(synth.getNumRegions() << " regions in the SFZ.");
|
||||
|
||||
fmidi_smf_u midiFile { fmidi_smf_file_read(midiPath.u8string().c_str()) };
|
||||
fmidi_smf_u midiFile { fmidi_smf_file_read(u8EncodedString(midiPath).c_str()) };
|
||||
ERROR_IF(!midiFile, "Can't read " << midiPath);
|
||||
|
||||
const auto* midiInfo = fmidi_smf_get_info(midiFile.get());
|
||||
|
|
|
|||
12
external/threadpool/ThreadPool.h
vendored
12
external/threadpool/ThreadPool.h
vendored
|
|
@ -18,7 +18,11 @@ public:
|
|||
ThreadPool(size_t);
|
||||
template<class F, class... Args>
|
||||
auto enqueue(F&& f, Args&&... args)
|
||||
#if __cplusplus >= 201703L
|
||||
-> std::future<typename std::invoke_result<F, Args...>::type>;
|
||||
#else
|
||||
-> std::future<typename std::result_of<F(Args...)>::type>;
|
||||
#endif
|
||||
~ThreadPool();
|
||||
private:
|
||||
// need to keep track of threads so we can join them
|
||||
|
|
@ -63,9 +67,17 @@ inline ThreadPool::ThreadPool(size_t threads)
|
|||
// add new work item to the pool
|
||||
template<class F, class... Args>
|
||||
auto ThreadPool::enqueue(F&& f, Args&&... args)
|
||||
#if __cplusplus >= 201703L
|
||||
-> std::future<typename std::invoke_result<F, Args...>::type>
|
||||
#else
|
||||
-> std::future<typename std::result_of<F(Args...)>::type>
|
||||
#endif
|
||||
{
|
||||
#if __cplusplus >= 201703L
|
||||
using return_type = typename std::invoke_result<F, Args...>::type;
|
||||
#else
|
||||
using return_type = typename std::result_of<F(Args...)>::type;
|
||||
#endif
|
||||
|
||||
auto task = std::make_shared< std::packaged_task<return_type()> >(
|
||||
std::bind(std::forward<F>(f), std::forward<Args>(args)...)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "Opcode.h"
|
||||
#include "LFODescription.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "utility/StringViewHelpers.h"
|
||||
#include "utility/Debug.h"
|
||||
#include <absl/strings/ascii.h>
|
||||
|
|
@ -271,11 +272,10 @@ absl::optional<uint8_t> readNoteValue(absl::string_view value)
|
|||
///
|
||||
std::pair<absl::string_view, int> flatSharpPrefixes[] = {
|
||||
{ "#", +1 },
|
||||
{ u8"♯", +1 },
|
||||
{ (const char*)u8"♯", +1 },
|
||||
{ "b", -1 },
|
||||
{ u8"♭", -1 },
|
||||
{ (const char*)u8"♭", -1 },
|
||||
};
|
||||
|
||||
for (const auto& prefix : flatSharpPrefixes) {
|
||||
if (absl::StartsWith(value, prefix.first)) {
|
||||
if (prefix.second == +1) {
|
||||
|
|
@ -304,6 +304,13 @@ absl::optional<uint8_t> readNoteValue(absl::string_view value)
|
|||
return static_cast<uint8_t>(noteNumber);
|
||||
}
|
||||
|
||||
#if defined(__cpp_lib_char8_t)
|
||||
absl::optional<uint8_t> readNoteValue(std::u8string_view value)
|
||||
{
|
||||
return readNoteValue(absl::string_view { reinterpret_cast<const char*>(value.data()), value.size() });
|
||||
}
|
||||
#endif
|
||||
|
||||
absl::optional<bool> readBoolean(absl::string_view value)
|
||||
{
|
||||
// Cakewalk-style booleans, case-insensitive
|
||||
|
|
|
|||
|
|
@ -143,6 +143,16 @@ private:
|
|||
*/
|
||||
absl::optional<uint8_t> readNoteValue(absl::string_view value);
|
||||
|
||||
#if defined(__cpp_lib_char8_t)
|
||||
/**
|
||||
* @brief Convert a note in string to its equivalent midi note number
|
||||
*
|
||||
* @param value
|
||||
* @return absl::optional<uint8_t>
|
||||
*/
|
||||
absl::optional<uint8_t> readNoteValue(std::u8string_view value);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Read a boolean value from the sfz file and cast it to the destination parameter.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include "Config.h"
|
||||
#include "utility/Debug.h"
|
||||
#include "utility/Macros.h"
|
||||
#include "utility/U8Strings.h"
|
||||
#include "modulations/ModId.h"
|
||||
#include "modulations/ModKey.h"
|
||||
#include "modulations/ModMatrix.h"
|
||||
|
|
@ -702,7 +703,7 @@ void Synth::Impl::finalizeSfzLoad()
|
|||
filePool.setRootDirectory(rootDirectory);
|
||||
|
||||
// a string representation used for OSC purposes
|
||||
rootPath_ = rootDirectory.u8string();
|
||||
rootPath_ = u8EncodedString(rootDirectory);
|
||||
|
||||
size_t currentRegionIndex = 0;
|
||||
size_t currentRegionCount = layers_.size();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||
|
||||
#include "AudioFile.h"
|
||||
#include "utility/U8Strings.h"
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/string_view.h>
|
||||
#include <absl/memory/memory.h>
|
||||
|
|
@ -31,8 +32,7 @@ const char* AudioFileInstrumentFormat::name() const noexcept
|
|||
|
||||
bool AudioFileInstrumentFormat::matchesFilePath(const fs::path& path) const
|
||||
{
|
||||
const std::string ext = path.extension().u8string();
|
||||
|
||||
const std::string ext = u8EncodedString(path.extension());
|
||||
for (absl::string_view knownExt : kRecognizedAudioExtensions) {
|
||||
if (absl::EqualsIgnoreCase(ext, knownExt))
|
||||
return true;
|
||||
|
|
@ -51,7 +51,7 @@ std::string AudioFileInstrumentImporter::convertToSfz(const fs::path& path) cons
|
|||
{
|
||||
std::ostringstream os;
|
||||
os.imbue(std::locale::classic());
|
||||
os << "<region>sample=" << path.filename().u8string();
|
||||
os << "<region>sample=" << u8EncodedString(path.filename());
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "DecentSampler.h"
|
||||
#include "sfizz/Opcode.h"
|
||||
#include "utility/U8Strings.h"
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/string_view.h>
|
||||
#include <absl/memory/memory.h>
|
||||
|
|
@ -29,7 +30,7 @@ const char* DecentSamplerInstrumentFormat::name() const noexcept
|
|||
|
||||
bool DecentSamplerInstrumentFormat::matchesFilePath(const fs::path& path) const
|
||||
{
|
||||
const std::string ext = path.extension().u8string();
|
||||
const std::string ext = u8EncodedString(path.extension());
|
||||
return absl::EqualsIgnoreCase(ext, ".dspreset");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <type_traits>
|
||||
|
||||
#if !defined(__cpp_lib_ssize)
|
||||
template<class C>
|
||||
constexpr auto ssize(const C& c)
|
||||
-> std::common_type_t<std::ptrdiff_t,
|
||||
|
|
@ -23,3 +24,4 @@ constexpr std::ptrdiff_t ssize(const T (&)[N]) noexcept
|
|||
{
|
||||
return N;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
28
src/sfizz/utility/U8Strings.h
Normal file
28
src/sfizz/utility/U8Strings.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
||||
// license. You should have receive a LICENSE.md file along with the code.
|
||||
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ghc/fs_std.hpp"
|
||||
#include <string>
|
||||
|
||||
inline std::string from_u8string(const std::string &s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::string from_u8string(std::string &&s) {
|
||||
return std::move(s);
|
||||
}
|
||||
|
||||
#if defined(__cpp_lib_char8_t)
|
||||
inline std::string from_u8string(const std::u8string &s) {
|
||||
return std::string(s.begin(), s.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
inline std::string u8EncodedString(const fs::path& path) {
|
||||
return from_u8string(path.u8string());
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue