Commit 698e27f 1 parent cc33ed1 commit 698e27f Copy full SHA for 698e27f
File tree 9 files changed +71
-9
lines changed
import/foreign_instruments
9 files changed +71
-9
lines changed Original file line number Diff line number Diff line change 3
3
#include " sfizz/MathHelpers.h"
4
4
#include " sfizz/SfzHelpers.h"
5
5
#include " sfizz/SIMDHelpers.h"
6
+ #include " sfizz/utility/U8Strings.h"
6
7
#include " MidiHelpers.h"
7
8
#include < st_audiofile_libs.h>
8
9
#include < cxxopts.hpp>
@@ -165,7 +166,7 @@ int main(int argc, char** argv)
165
166
ERROR_IF (!synth.loadSfzFile (sfzPath), " There was an error loading the SFZ file." );
166
167
LOG_INFO (synth.getNumRegions () << " regions in the SFZ." );
167
168
168
- fmidi_smf_u midiFile { fmidi_smf_file_read (midiPath. u8string ( ).c_str ()) };
169
+ fmidi_smf_u midiFile { fmidi_smf_file_read (u8EncodedString (midiPath ).c_str ()) };
169
170
ERROR_IF (!midiFile, " Can't read " << midiPath);
170
171
171
172
const auto * midiInfo = fmidi_smf_get_info (midiFile.get ());
Original file line number Diff line number Diff line change @@ -18,7 +18,11 @@ class ThreadPool {
18
18
ThreadPool (size_t );
19
19
template <class F , class ... Args>
20
20
auto enqueue (F&& f, Args&&... args)
21
+ #if __cplusplus >= 201703L
22
+ -> std::future<typename std::invoke_result<F, Args...>::type>;
23
+ #else
21
24
-> std::future<typename std::result_of<F(Args...)>::type>;
25
+ #endif
22
26
~ThreadPool ();
23
27
private:
24
28
// need to keep track of threads so we can join them
@@ -63,9 +67,17 @@ inline ThreadPool::ThreadPool(size_t threads)
63
67
// add new work item to the pool
64
68
template <class F , class ... Args>
65
69
auto ThreadPool::enqueue (F&& f, Args&&... args)
70
+ #if __cplusplus >= 201703L
71
+ -> std::future<typename std::invoke_result<F, Args...>::type>
72
+ #else
66
73
-> std::future<typename std::result_of<F(Args...)>::type>
74
+ #endif
67
75
{
76
+ #if __cplusplus >= 201703L
77
+ using return_type = typename std::invoke_result<F, Args...>::type;
78
+ #else
68
79
using return_type = typename std::result_of<F (Args...)>::type;
80
+ #endif
69
81
70
82
auto task = std::make_shared< std::packaged_task<return_type ()> >(
71
83
std::bind (std::forward<F>(f), std::forward<Args>(args)...)
Original file line number Diff line number Diff line change 6
6
7
7
#include " Opcode.h"
8
8
#include " LFODescription.h"
9
+ #include " absl/strings/string_view.h"
9
10
#include " utility/StringViewHelpers.h"
10
11
#include " utility/Debug.h"
11
12
#include < absl/strings/ascii.h>
@@ -271,11 +272,10 @@ absl::optional<uint8_t> readNoteValue(absl::string_view value)
271
272
// /
272
273
std::pair<absl::string_view, int > flatSharpPrefixes[] = {
273
274
{ " #" , +1 },
274
- { u8" ♯" , +1 },
275
+ { ( const char *) u8" ♯" , +1 },
275
276
{ " b" , -1 },
276
- { u8" ♭" , -1 },
277
+ { ( const char *) u8" ♭" , -1 },
277
278
};
278
-
279
279
for (const auto & prefix : flatSharpPrefixes) {
280
280
if (absl::StartsWith (value, prefix.first )) {
281
281
if (prefix.second == +1 ) {
@@ -304,6 +304,13 @@ absl::optional<uint8_t> readNoteValue(absl::string_view value)
304
304
return static_cast <uint8_t >(noteNumber);
305
305
}
306
306
307
+ #if defined(__cpp_lib_char8_t)
308
+ absl::optional<uint8_t > readNoteValue (std::u8string_view value)
309
+ {
310
+ return readNoteValue (absl::string_view { reinterpret_cast <const char *>(value.data ()), value.size () });
311
+ }
312
+ #endif
313
+
307
314
absl::optional<bool > readBoolean (absl::string_view value)
308
315
{
309
316
// Cakewalk-style booleans, case-insensitive
Original file line number Diff line number Diff line change @@ -143,6 +143,16 @@ struct Opcode {
143
143
*/
144
144
absl::optional<uint8_t > readNoteValue (absl::string_view value);
145
145
146
+ #if defined(__cpp_lib_char8_t)
147
+ /* *
148
+ * @brief Convert a note in string to its equivalent midi note number
149
+ *
150
+ * @param value
151
+ * @return absl::optional<uint8_t>
152
+ */
153
+ absl::optional<uint8_t > readNoteValue (std::u8string_view value);
154
+ #endif
155
+
146
156
/* *
147
157
* @brief Read a boolean value from the sfz file and cast it to the destination parameter.
148
158
*/
Original file line number Diff line number Diff line change 8
8
#include " Config.h"
9
9
#include " utility/Debug.h"
10
10
#include " utility/Macros.h"
11
+ #include " utility/U8Strings.h"
11
12
#include " modulations/ModId.h"
12
13
#include " modulations/ModKey.h"
13
14
#include " modulations/ModMatrix.h"
@@ -702,7 +703,7 @@ void Synth::Impl::finalizeSfzLoad()
702
703
filePool.setRootDirectory (rootDirectory);
703
704
704
705
// a string representation used for OSC purposes
705
- rootPath_ = rootDirectory. u8string ( );
706
+ rootPath_ = u8EncodedString (rootDirectory );
706
707
707
708
size_t currentRegionIndex = 0 ;
708
709
size_t currentRegionCount = layers_.size ();
Original file line number Diff line number Diff line change 5
5
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
6
6
7
7
#include " AudioFile.h"
8
+ #include " utility/U8Strings.h"
8
9
#include < absl/strings/match.h>
9
10
#include < absl/strings/string_view.h>
10
11
#include < absl/memory/memory.h>
@@ -31,8 +32,7 @@ const char* AudioFileInstrumentFormat::name() const noexcept
31
32
32
33
bool AudioFileInstrumentFormat::matchesFilePath (const fs::path& path) const
33
34
{
34
- const std::string ext = path.extension ().u8string ();
35
-
35
+ const std::string ext = u8EncodedString (path.extension ());
36
36
for (absl::string_view knownExt : kRecognizedAudioExtensions ) {
37
37
if (absl::EqualsIgnoreCase (ext, knownExt))
38
38
return true ;
@@ -51,7 +51,7 @@ std::string AudioFileInstrumentImporter::convertToSfz(const fs::path& path) cons
51
51
{
52
52
std::ostringstream os;
53
53
os.imbue (std::locale::classic ());
54
- os << " <region>sample=" << path.filename (). u8string ( );
54
+ os << " <region>sample=" << u8EncodedString ( path.filename ());
55
55
return os.str ();
56
56
}
57
57
Original file line number Diff line number Diff line change 6
6
7
7
#include " DecentSampler.h"
8
8
#include " sfizz/Opcode.h"
9
+ #include " utility/U8Strings.h"
9
10
#include < absl/strings/match.h>
10
11
#include < absl/strings/string_view.h>
11
12
#include < absl/memory/memory.h>
@@ -29,7 +30,7 @@ const char* DecentSamplerInstrumentFormat::name() const noexcept
29
30
30
31
bool DecentSamplerInstrumentFormat::matchesFilePath (const fs::path& path) const
31
32
{
32
- const std::string ext = path.extension (). u8string ( );
33
+ const std::string ext = u8EncodedString ( path.extension ());
33
34
return absl::EqualsIgnoreCase (ext, " .dspreset" );
34
35
}
35
36
Original file line number Diff line number Diff line change 8
8
9
9
#include < type_traits>
10
10
11
+ #if !defined(__cpp_lib_ssize)
11
12
template <class C >
12
13
constexpr auto ssize (const C& c)
13
14
-> std::common_type_t<std::ptrdiff_t,
@@ -23,3 +24,4 @@ constexpr std::ptrdiff_t ssize(const T (&)[N]) noexcept
23
24
{
24
25
return N;
25
26
}
27
+ #endif
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: BSD-2-Clause
2
+
3
+ // This code is part of the sfizz library and is licensed under a BSD 2-clause
4
+ // license. You should have receive a LICENSE.md file along with the code.
5
+ // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
6
+
7
+ #pragma once
8
+
9
+ #include " ghc/fs_std.hpp"
10
+ #include < string>
11
+
12
+ inline std::string from_u8string (const std::string &s) {
13
+ return s;
14
+ }
15
+
16
+ inline std::string from_u8string (std::string &&s) {
17
+ return std::move (s);
18
+ }
19
+
20
+ #if defined(__cpp_lib_char8_t)
21
+ inline std::string from_u8string (const std::u8string &s) {
22
+ return std::string (s.begin (), s.end ());
23
+ }
24
+ #endif
25
+
26
+ inline std::string u8EncodedString (const fs::path& path) {
27
+ return from_u8string (path.u8string ());
28
+ }
You can’t perform that action at this time.
0 commit comments