From d61f8282691f01f271f1a1943fa36861fe668efc Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 4 Aug 2019 16:07:09 +0200 Subject: [PATCH] Windows changes --- CMakeLists.txt | 50 ++++++++++++++++++++++++++++++++-------------- sources/FilePool.h | 3 ++- sources/Globals.h | 4 ++++ sources/Main.cpp | 4 +++- sources/Region.cpp | 3 +++ sources/Synth.h | 4 +++- 6 files changed, 50 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6cfee17..09a68ed6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,6 @@ project(sfizz VERSION 1.0.0 LANGUAGES CXX) # Set the highest possible standard set(CMAKE_CXX_STANDARD 17) - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT ANDROID) add_compile_options(-stdlib=libc++) # Presumably need the above for linking too, maybe other options missing as well @@ -19,7 +18,16 @@ if (UNIX) # add_compile_options(-fno-exceptions) add_compile_options(-ffast-math) add_compile_options(-fno-rtti) - add_compile_options(-fno-omit-frame-pointer) + # add_compile_options(-fno-omit-frame-pointer) +endif() + +if (WIN32) + # TODO: Remove when abseil updates (deprecation warning from c++17 onwards) + add_compile_options(/wd4996) + # add_compile_options(/W3) + # add_compile_options(/GR-) + # add_compile_options(/permissive-) + # add_compile_options(/fp:fast) endif() message("Cmake flags: ${CMAKE_CXX_FLAGS}") @@ -27,16 +35,16 @@ message("Cmake flags: ${CMAKE_CXX_FLAGS}") # Check SIMD files include(CheckIncludeFiles) CHECK_INCLUDE_FILES(x86intrin.h HAVE_X86INTRIN_H) +CHECK_INCLUDE_FILES(intrin.h HAVE_INTRIN_H) CHECK_INCLUDE_FILES(arm_neon.h HAVE_ARM_NEON_H) -if (HAVE_X86INTRIN_H) - if(UNIX) - add_compile_options(-DHAVE_X86INTRIN_H) - endif() +if (HAVE_X86INTRIN_H AND UNIX) + add_compile_options(-DHAVE_X86INTRIN_H) endif() -if (HAVE_ARM_NEON_H) - if(UNIX) - add_compile_options(-DHAVE_ARM_NEON_H) - endif() +if (HAVE_INTRIN_H AND WIN32) + add_compile_options(/DHAVE_INTRIN_H) +endif() +if (HAVE_ARM_NEON_H AND UNIX) + add_compile_options(-DHAVE_ARM_NEON_H) endif() # Build options and includes @@ -49,10 +57,23 @@ add_subdirectory(external/Catch2) add_subdirectory(external/cxxopts) add_subdirectory(external/benchmark) +# Download libsndfile +if (WIN32) + # file(DOWNLOAD https://github.com/bastibe/libsndfile-binaries/raw/master/libsndfile32bit.dll external/libsndfile-win/libsndfile32bit.dll) + # file(DOWNLOAD https://github.com/bastibe/libsndfile-binaries/raw/master/libsndfile64bit.dll external/libsndfile-win/libsndfile64bit.dll) + # message(STATUS "Downloading libsndfile") + # # find_library(sndfile libsndfile-1.lib HINTS ${WIN_SNDFILE_PATH}/lib) + set(WIN_SNDFILE_PATH "C:/Program Files/Mega-Nerd/libsndfile") + add_library(sndfile STATIC IMPORTED) + set_target_properties(sndfile PROPERTIES IMPORTED_LOCATION "${WIN_SNDFILE_PATH}/lib/libsndfile-1.lib") + set_target_properties(sndfile PROPERTIES LINKER_LANGUAGE CXX) + file(COPY "${WIN_SNDFILE_PATH}/bin/libsndfile-1.dll" DESTINATION ${CMAKE_BINARY_DIR}) + target_include_directories(sndfile INTERFACE "${WIN_SNDFILE_PATH}/include") +endif() + # Export the compile_commands.json file set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - set(COMMON_SOURCES sources/Opcode.cpp sources/Synth.cpp @@ -74,9 +95,8 @@ set(TEST_SOURCES tests/MainT.cpp ) - ############################### -add_executable(sfzprint sources/ParserMain.cpp ${COMMON_SOURCES}) +add_executable(sfzprint sources/ParserMain.cpp sources/Opcode.cpp sources/Parser.cpp) # Per OS properties if(UNIX) target_link_libraries(sfzprint stdc++fs) @@ -91,7 +111,7 @@ add_executable(sfizz sources/Main.cpp ${COMMON_SOURCES}) if(UNIX) target_link_libraries(sfizz stdc++fs) endif(UNIX) -target_link_libraries(sfizz absl::stlrings cxxopts sndfile absl::flat_hash_map) +target_link_libraries(sfizz absl::strings cxxopts sndfile absl::flat_hash_map) ############################### # Test application @@ -118,4 +138,4 @@ add_executable(bench_read benchmarks/Stereo_Read_Interleaved.cpp ${COMMON_SOURCE if(UNIX) target_link_libraries(bench_read stdc++fs) endif(UNIX) -target_link_libraries(bench_read absl::strings benchmark) \ No newline at end of file +target_link_libraries(bench_read absl::strings benchmark) diff --git a/sources/FilePool.h b/sources/FilePool.h index 12ad76b4..b9c86e26 100644 --- a/sources/FilePool.h +++ b/sources/FilePool.h @@ -33,7 +33,7 @@ public: if (!std::filesystem::exists(file)) return {}; - SndfileHandle sndFile { file.c_str() }; + SndfileHandle sndFile ( reinterpret_cast(file.c_str()) ); FileInformation returnedValue; returnedValue.end = static_cast(sndFile.frames()); SF_INSTRUMENT instrumentInfo; @@ -53,6 +53,7 @@ public: // DBG(buffer); return returnedValue; } + size_t getNumPreloadedSamples() { return preloadedData.size(); } private: std::filesystem::path rootDirectory; Buffer tempReadBuffer { config::preloadSize * 2 }; diff --git a/sources/Globals.h b/sources/Globals.h index 2eed9933..51d8c59d 100644 --- a/sources/Globals.h +++ b/sources/Globals.h @@ -29,4 +29,8 @@ namespace config #if HAVE_X86INTRIN_H #include +#endif + +#if HAVE_INTRIN_H +#include #endif \ No newline at end of file diff --git a/sources/Main.cpp b/sources/Main.cpp index 1d66c9ec..3fe7a72e 100644 --- a/sources/Main.cpp +++ b/sources/Main.cpp @@ -25,10 +25,11 @@ int main(int argc, char** argv) std::cout << "\tGroups: " << synth.getNumGroups() << '\n'; std::cout << "\tRegions: " << synth.getNumRegions() << '\n'; std::cout << "\tCurves: " << synth.getNumCurves() << '\n'; + std::cout << "\tPreloadedSamples: " << synth.getNumPreloadedSamples() << '\n'; std::cout << "==========" << '\n'; std::cout << "Included files:" << '\n'; for (auto& file: synth.getIncludedFiles()) - std::cout << '\t' << file.c_str() << '\n'; + std::cout << '\t' << file.string() << '\n'; std::cout << "==========" << '\n'; std::cout << "Defines:" << '\n'; for (auto& define: synth.getDefines()) @@ -38,5 +39,6 @@ int main(int argc, char** argv) for (auto& opcode: synth.getUnknownOpcodes()) std::cout << opcode << ','; std::cout << '\n'; + system("pause"); return 0; } \ No newline at end of file diff --git a/sources/Region.cpp b/sources/Region.cpp index 1eaf8482..f7c7532d 100644 --- a/sources/Region.cpp +++ b/sources/Region.cpp @@ -245,6 +245,9 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) bool sfz::Region::prepare() { + if (isGenerator()) + return true; + auto fileInformation = filePool.getFileInformation(sample); if (!fileInformation) return false; diff --git a/sources/Synth.h b/sources/Synth.h index 9605bf2d..9e1b5598 100644 --- a/sources/Synth.h +++ b/sources/Synth.h @@ -15,12 +15,14 @@ class Synth: public Parser { public: bool loadSfzFile(const std::filesystem::path& file) final; - int getNumRegions() const noexcept { return regions.size(); } + int getNumRegions() const noexcept { return static_cast(regions.size()); } int getNumGroups() const noexcept { return numGroups; } int getNumMasters() const noexcept { return numMasters; } int getNumCurves() const noexcept { return numCurves; } const Region* getRegionView(int idx) const noexcept { return (size_t)idx < regions.size() ? regions[idx].get() : nullptr; } auto getUnknownOpcodes() { return unknownOpcodes; } + size_t getNumPreloadedSamples() { return filePool.getNumPreloadedSamples(); } + protected: void callback(std::string_view header, std::vector members) final; private: