diff --git a/clients/sfizz_render.cpp b/clients/sfizz_render.cpp index 1affaf633..1991a7c89 100644 --- a/clients/sfizz_render.cpp +++ b/clients/sfizz_render.cpp @@ -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 #include @@ -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()); diff --git a/external/threadpool/ThreadPool.h b/external/threadpool/ThreadPool.h index 2e030687c..19b519b38 100644 --- a/external/threadpool/ThreadPool.h +++ b/external/threadpool/ThreadPool.h @@ -18,7 +18,11 @@ class ThreadPool { ThreadPool(size_t); template auto enqueue(F&& f, Args&&... args) +#if __cplusplus >= 201703L + -> std::future::type>; +#else -> std::future::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 auto ThreadPool::enqueue(F&& f, Args&&... args) +#if __cplusplus >= 201703L + -> std::future::type> +#else -> std::future::type> +#endif { +#if __cplusplus >= 201703L + using return_type = typename std::invoke_result::type; +#else using return_type = typename std::result_of::type; +#endif auto task = std::make_shared< std::packaged_task >( std::bind(std::forward(f), std::forward(args)...) diff --git a/src/sfizz/Opcode.cpp b/src/sfizz/Opcode.cpp index 5468417e7..b983cba8b 100644 --- a/src/sfizz/Opcode.cpp +++ b/src/sfizz/Opcode.cpp @@ -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 @@ -271,11 +272,10 @@ absl::optional readNoteValue(absl::string_view value) /// std::pair 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 readNoteValue(absl::string_view value) return static_cast(noteNumber); } +#if defined(__cpp_lib_char8_t) +absl::optional readNoteValue(std::u8string_view value) +{ + return readNoteValue(absl::string_view { reinterpret_cast(value.data()), value.size() }); +} +#endif + absl::optional readBoolean(absl::string_view value) { // Cakewalk-style booleans, case-insensitive diff --git a/src/sfizz/Opcode.h b/src/sfizz/Opcode.h index 16557c3f9..d2deea670 100644 --- a/src/sfizz/Opcode.h +++ b/src/sfizz/Opcode.h @@ -143,6 +143,16 @@ struct Opcode { */ absl::optional 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 + */ +absl::optional readNoteValue(std::u8string_view value); +#endif + /** * @brief Read a boolean value from the sfz file and cast it to the destination parameter. */ diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index a06777a7f..c5e2bb3a6 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -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(); diff --git a/src/sfizz/import/foreign_instruments/AudioFile.cpp b/src/sfizz/import/foreign_instruments/AudioFile.cpp index 65457cb1f..d4c4d3045 100644 --- a/src/sfizz/import/foreign_instruments/AudioFile.cpp +++ b/src/sfizz/import/foreign_instruments/AudioFile.cpp @@ -5,6 +5,7 @@ // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz #include "AudioFile.h" +#include "utility/U8Strings.h" #include #include #include @@ -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 << "sample=" << path.filename().u8string(); + os << "sample=" << u8EncodedString(path.filename()); return os.str(); } diff --git a/src/sfizz/import/foreign_instruments/DecentSampler.cpp b/src/sfizz/import/foreign_instruments/DecentSampler.cpp index 149ba86d1..492ea5e56 100644 --- a/src/sfizz/import/foreign_instruments/DecentSampler.cpp +++ b/src/sfizz/import/foreign_instruments/DecentSampler.cpp @@ -6,6 +6,7 @@ #include "DecentSampler.h" #include "sfizz/Opcode.h" +#include "utility/U8Strings.h" #include #include #include @@ -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"); } diff --git a/src/sfizz/utility/Size.h b/src/sfizz/utility/Size.h index f7d5277ca..86b593015 100644 --- a/src/sfizz/utility/Size.h +++ b/src/sfizz/utility/Size.h @@ -8,6 +8,7 @@ #include +#if !defined(__cpp_lib_ssize) template constexpr auto ssize(const C& c) -> std::common_type_t + +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()); +}