diff --git a/.appveyor.yml b/.appveyor.yml index d458d63..56de609 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,136 +1,102 @@ ---- version: "{build}-{branch}" -# stack: ruby 2.7 -before_build: - - git submodule update --init --depth 1 -# test_script: -# - ruby -E UTF-8 tools/coverage.rb +build_script: + - export VCPKG_OVERLAY_TRIPLETS=cmake/vcpkg-triplets + - cmake -B build -DCMAKE_BUILD_TYPE=Release + -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake + -DVCPKG_TARGET_TRIPLET=arch-env -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=$TOOLCHAIN + -DCMAKE_OSX_ARCHITECTURES=$ARCH -DCMAKE_OSX_DEPLOYMENT_TARGET=$DEPLOY_TARGET + - cmake --build build for: - - matrix: { only: [ appveyor_build_worker_image: &linux Ubuntu2004 ] } + - matrix: { only: [ appveyor_build_worker_image: &linux Ubuntu2204 ] } cache: - build/vcpkg_installed -> vcpkg.json, cmake/vcpkg-triplets/arch-env.cmake install: |- - set -e + # set -e + sudo sed -i '/arch=/! s/^deb/deb [arch=amd64,i386]/' /etc/apt/sources.list - awk ' - $3 !~ /ubuntu\.com/ { next } - $1 == "deb" { - $2 = "[arch=armhf,arm64]"; - $3 = "http://ports.ubuntu.com/ubuntu-ports/" - } 1' /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/ports.list > /dev/null + install-deps() { + # sudo add-apt-repository --remove "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" local arch="$1"; shift - local native=("$@") - local target=() + local native=("$@" php-cli qemu-user-binfmt) + sudo dpkg --add-architecture $arch sudo apt-get update -qq - sudo apt-get install -qq aptitude - sudo aptitude install -yR ${native[@]} ${target[@]/%/:$arch} + sudo apt-get install -qq aptitude > /dev/null + sudo aptitude install -yR ${native[@]} > /dev/null } - # sudo update-alternatives --set gcc /usr/bin/gcc-7 + + # sudo update-alternatives --set gcc /usr/bin/gcc-9 + case $ARCH in x86_64) install-deps amd64 - export TOOLCHAIN=~/vcpkg/scripts/buildsystems/vcpkg.cmake ;; i686) install-deps i386 g++-multilib - export TOOLCHAIN_PREFIX=i386-linux-gnu - export TOOLCHAIN=cmake/linux-cross.cmake + export TOOLCHAIN=$(pwd)/cmake/linux-cross.cmake \ + TOOLCHAIN_PREFIX=i386-linux-gnu ;; armv7l) install-deps armhf g++-arm-linux-gnueabihf - export TOOLCHAIN_PREFIX=arm-linux-gnueabihf - export TOOLCHAIN=cmake/linux-cross.cmake + export TOOLCHAIN=$(pwd)/cmake/linux-cross.cmake \ + TOOLCHAIN_PREFIX=arm-linux-gnueabihf ;; aarch64) install-deps arm64 g++-aarch64-linux-gnu - export TOOLCHAIN_PREFIX=aarch64-linux-gnu - export TOOLCHAIN=cmake/linux-cross.cmake + export TOOLCHAIN=$(pwd)/cmake/linux-cross.cmake \ + TOOLCHAIN_PREFIX=aarch64-linux-gnu ;; esac - TRIPLET=arch-env - export VCPKG_OVERLAY_TRIPLETS=cmake/vcpkg-triplets - build_script: - - cmake -B build -DCMAKE_BUILD_TYPE=Release - -DVCPKG_TARGET_TRIPLET=$TRIPLET -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN - - cmake --build build --target reaper_reasolotus - artifacts: - path: build/reaper_*.so - - matrix: { only: [ appveyor_build_worker_image: macos-catalina, appveyor_build_worker_image: macos, appveyor_build_worker_image: macos-mojave ] } + - matrix: { only: [ appveyor_build_worker_image: &macos macos-monterey ] } cache: - build/vcpkg_installed -> vcpkg.json, cmake/vcpkg-triplets/arch-env.cmake install: - - TRIPLET=arch-env TOOLCHAIN=~/vcpkg/scripts/buildsystems/vcpkg.cmake - - export VCPKG_OVERLAY_TRIPLETS=cmake/vcpkg-triplets - - |- - case $ARCH in - arm64) export DEPLOY_TARGET=11.0 XCODE_VERSION=12.3 ;; - x86_64) export DEPLOY_TARGET=10.4 XCODE_VERSION=12.3 ;; - *) export DEPLOY_TARGET=10.9 XCODE_VERSION=9.4.1 ;; - esac - - - sudo xcode-select -s /Applications/Xcode-$XCODE_VERSION.app - - # https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021/ - - sudo curl -k https://curl.se/ca/cacert.pem -o /etc/ssl/cert.pem - build_script: - - cmake -B build -DCMAKE_BUILD_TYPE=Release - -DVCPKG_TARGET_TRIPLET=$TRIPLET -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN - -DCMAKE_OSX_ARCHITECTURES=$ARCH - - cmake --build build --target reaper_reasolotus + echo " " + brew install php artifacts: - path: build/reaper_*.dylib - matrix: { only: [ appveyor_build_worker_image: &windows Visual Studio 2022 ] } + cache: - build\vcpkg_installed -> vcpkg.json install: - if "%ARCH%" == "x64" call "%ProgramFiles%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" - if "%ARCH%" == "x86" call "%ProgramFiles%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat" build_script: - - cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release + - cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DVCPKG_TARGET_TRIPLET=%ARCH%-windows-static -DCMAKE_TOOLCHAIN_FILE=C:\Tools\vcpkg\scripts\buildsystems\vcpkg.cmake - cmake --build build artifacts: - path: build\reaper_*.dll + - path: build\reaper_*.pdb environment: matrix: - - job_name: macOS x86 64-bit - appveyor_build_worker_image: macos-catalina - ARCH: x86_64 - - job_name: macOS ARM 64-bit - appveyor_build_worker_image: macos-catalina - ARCH: arm64 - # - job_name: macOS x86 32-bit - # appveyor_build_worker_image: macos-mojave - # ARCH: i386 - - job_name: Linux x86 64-bit + - job_name: Linux ARM 64-bit appveyor_build_worker_image: *linux - ARCH: x86_64 + ARCH: aarch64 - job_name: Windows 64-bit appveyor_build_worker_image: *windows ARCH: x64 - - job_name: Linux ARM 64-bit + - job_name: macOS ARM 64-bit + appveyor_build_worker_image: *macos + ARCH: arm64 + - job_name: Linux x86 64-bit appveyor_build_worker_image: *linux - ARCH: aarch64 - # - job_name: Linux x86 32-bit - # appveyor_build_worker_image: *linux - # ARCH: i686 - # - job_name: Linux ARM 32-bit - # appveyor_build_worker_image: *linux - # ARCH: armv7l - # - job_name: Windows 32-bit - # appveyor_build_worker_image: *windows - # ARCH: x86 + ARCH: x86_64 + - job_name: macOS x86 64-bit + appveyor_build_worker_image: *macos + ARCH: x86_64 deploy: provider: GitHub @@ -139,6 +105,6 @@ deploy: force_update: true auth_token: secure: Rk8do2Q/etdabjwIABBRdTJu1a4wYVu9Ltz8HJuC0wc3rz+hHUMGa3N7vTlsrd7z - artifact: /.*\.(dll|dylib|so|lua)/ + artifact: /.*\.(dll|dylib|so)/ on: - APPVEYOR_REPO_TAG: true + APPVEYOR_REPO_TAG: true \ No newline at end of file diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 123b097..0000000 --- a/.clang-format +++ /dev/null @@ -1,164 +0,0 @@ ---- -Language: Cpp -# BasedOnStyle: Microsoft -AccessModifierOffset: -2 -AlignAfterOpenBracket: AlwaysBreak -AlignConsecutiveAssignments: None -AlignConsecutiveBitFields: None -AlignConsecutiveDeclarations: None -AlignConsecutiveMacros: None -AlignEscapedNewlines: Left -AlignOperands: Align -AlignTrailingComments: true -AllowAllArgumentsOnNextLine: false -AllowAllConstructorInitializersOnNextLine: false -AllowAllParametersOfDeclarationOnNextLine: false -AllowShortBlocksOnASingleLine: Never -AllowShortCaseLabelsOnASingleLine: false -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortIfStatementsOnASingleLine: Never -AllowShortLambdasOnASingleLine: All -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: true -AlwaysBreakTemplateDeclarations: Yes -AttributeMacros: - - __capability -BinPackArguments: false -BinPackParameters: false -BitFieldColonSpacing: Both -BraceWrapping: - AfterCaseLabel: false - AfterClass: true - AfterControlStatement: Always - AfterEnum: true - AfterFunction: true - AfterNamespace: true - AfterObjCDeclaration: true - AfterStruct: true - AfterUnion: false - AfterExternBlock: true - BeforeCatch: true - BeforeElse: true - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakAfterJavaFieldAnnotations: false -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Stroustrup -BreakBeforeConceptDeclarations: true -BreakBeforeInheritanceComma: false -BreakBeforeTernaryOperators: true -BreakConstructorInitializers: BeforeComma -BreakConstructorInitializersBeforeComma: true -BreakInheritanceList: BeforeColon -BreakStringLiterals: true -ColumnLimit: 80 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DeriveLineEnding: true -DerivePointerAlignment: false -DisableFormat: false -EmptyLineBeforeAccessModifier: LogicalBlock -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -StatementAttributeLikeMacros: - - Q_EMIT -IncludeBlocks: Preserve -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - SortPriority: 0 - CaseSensitive: false - - Regex: '.*' - Priority: 1 - SortPriority: 0 - CaseSensitive: false -IncludeIsMainRegex: '(Test)?$' -IncludeIsMainSourceRegex: '' -IndentCaseBlocks: false -IndentCaseLabels: false -IndentExternBlock: AfterExternBlock -IndentGotoLabels: true -IndentPPDirectives: None -IndentRequires: false -IndentWidth: 4 -IndentWrappedFunctionNames: false -InsertTrailingCommas: None -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: true -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 -ObjCBreakBeforeNestedBlockParam: true -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -PenaltyIndentedWhitespace: 0 -PenaltyReturnTypeOnItsOwnLine: 1000 -PointerAlignment: Left -ReflowComments: true -SortIncludes: true -SortJavaStaticImport: Before -SortUsingDeclarations: true -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: true -SpaceAroundPointerQualifiers: Default -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: true -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatements -SpaceBeforeRangeBasedForLoopColon: true -SpaceBeforeSquareBrackets: false -SpaceInEmptyBlock: false -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: false -SpacesInCStyleCastParentheses: false -SpacesInConditionalStatement: false -SpacesInContainerLiterals: true -SpacesInParentheses: false -SpacesInSquareBrackets: false -Standard: Latest -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION -TabWidth: 4 -UseCRLF: false -UseTab: Never -WhitespaceSensitiveMacros: - - STRINGIZE - - PP_STRINGIZE - - BOOST_PP_STRINGIZE - - NS_SWIFT_NAME - - CF_SWIFT_NAME -... \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d7496b..323ada5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,93 @@ -cmake_minimum_required(VERSION 3.19) -project(reaper_reasolotus LANGUAGES C CXX) +cmake_minimum_required(VERSION 3.22) -include(CheckCompilerFlag) -include(CheckCXXSourceCompiles) -include(CheckIncludeFileCXX) -include(CheckLinkerFlag) -include(FindGit) +include(CheckCXXCompilerFlag) +include(FetchContent) + +project(reasolotus LANGUAGES C CXX) +add_library(${PROJECT_NAME} SHARED) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 23) + +# path for external 3rd party library dependencies +set(PROJECT_LIB_DIR ${PROJECT_SOURCE_DIR}/lib) + +FetchContent_Declare(WDL SYSTEM + GIT_REPOSITORY https://github.com/justinfrankel/WDL + GIT_TAG "origin/main" # or specify a tag or branch here + SOURCE_DIR "${PROJECT_LIB_DIR}/WDL" + ) + +FetchContent_Declare(reaper-sdk SYSTEM + GIT_REPOSITORY https://github.com/justinfrankel/reaper-sdk + GIT_TAG "origin/main" # or specify a tag or branch here + SOURCE_DIR "${PROJECT_LIB_DIR}/reaper-sdk" + ) + +FetchContent_MakeAvailable(WDL reaper-sdk) + +# symlink WDL to reaper-sdk +execute_process( + COMMAND ${CMAKE_COMMAND} -E create_symlink + # source + "${PROJECT_LIB_DIR}/WDL/WDL" + # target + "${PROJECT_LIB_DIR}/reaper-sdk/WDL" +) + +if(WIN32) + add_compile_definitions(NOMINMAX _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE) + + target_compile_options( + ${PROJECT_NAME} + PRIVATE + /W3 /WX) +else() + target_compile_options( + ${PROJECT_NAME} + PRIVATE + -Wall -Wextra -Werror -Wpedantic + ) +endif() + +FILE(GLOB header_paths + ${PROJECT_LIB_DIR}/reaper-sdk/sdk + ) + +target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${header_paths}) + +if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) + set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + CACHE STRING "") +endif() + +if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET) + set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "") +endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +find_package(WDL REQUIRED) + +if(NOT WIN32) + find_package(SWELL REQUIRED) +endif() + +target_link_libraries(${PROJECT_NAME} PRIVATE WDL::WDL) + +if(SWELL_FOUND) + target_link_libraries(${PROJECT_NAME} PRIVATE SWELL::swell) + + # Transpile the Win32 resource file + find_package(PHP REQUIRED) + add_custom_command( + OUTPUT resource.rc_mac_dlg resource.rc_mac_menu + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/resource.rc ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${PHP_EXECUTABLE} ${SWELL_RESGEN} --quiet resource.rc + DEPENDS ${SWELL_RESGEN} + MAIN_DEPENDENCY resource.rc + ) +endif() + if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) if(WIN32) set(USER_CONFIG_DIR "$ENV{APPDATA}") @@ -19,7 +98,7 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) endif() set(CMAKE_INSTALL_PREFIX "${USER_CONFIG_DIR}/REAPER" CACHE PATH - "REAPER resource path where to install reasolotus" FORCE) + "REAPER resource path where to install ReaPack" FORCE) endif() if(CMAKE_OSX_ARCHITECTURES) @@ -32,140 +111,73 @@ endif() STRING(TOLOWER "${ARCH_NAME}" ARCH_NAME) -set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_VISIBILITY_PRESET "hidden") -set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") -set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# set(CMAKE_CXX_EXTENSIONS OFF) +# set(CMAKE_CXX_STANDARD_REQUIRED ON) +# set(CMAKE_CXX_VISIBILITY_PRESET "hidden") +# set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +# set(CMAKE_POSITION_INDEPENDENT_CODE ON) -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON) -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON) +# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON) +# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) +# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON) if(VCPKG_TOOLCHAIN) set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL Release) set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release) endif() -if(NOT EXISTS ${PROJECT_SOURCE_DIR}/external/reaper-sdk/README) - execute_process( - COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive --depth 1 - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - ) -endif() - -if(WIN32) - foreach(arg - CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO - CMAKE_C_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_MINSIZEREL - ) - # Embed debug information in the object files - string(REGEX REPLACE "/Z[iI]" "/Z7" ${arg} "${${arg}}") - - # Allow expansion of function not explicitly marked for no inlining - string(REGEX REPLACE "/Ob1" "/Ob2" ${arg} "${${arg}}") - endforeach() - - add_compile_options( - /utf-8 - # Exception handling model - /EHsc +# if(WIN32) + # foreach(arg + # CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG + # CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE + # CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO + # CMAKE_C_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_MINSIZEREL + # ) + # # Embed debug information in the object files + # string(REGEX REPLACE "/Z[iI]" "/Z7" ${arg} "${${arg}}") + # endforeach() - # Enhance optimized debugging - $<$>:/Zo> +# add_compile_options( +# # Exception handling model +# /EHsc - # Eliminate duplicate strings - $<$>:/GF> +# # Enhance optimized debugging +# $<$>:/Zo> - # Enable function-level linking - $<$>:/Gy> - - # Remove unreferenced COMDAT - $<$>:/Zc:inline> - ) +# # Eliminate duplicate strings +# $<$>:/GF> - add_link_options( - # Remove unreferenced code - $<$>:/OPT:REF> +# # Enable function-level linking +# $<$>:/Gy> - # Remove duplicate sections - $<$>:/OPT:ICF> +# # Remove unreferenced COMDAT +# $<$>:/Zc:inline> +# ) - # Use relative path to the PDB file to avoid exposing the full path - # /PDBALTPATH:%_PDB% - ) -else() - add_compile_options( - -fsigned-char -fstack-protector-strong -fdiagnostics-color - ) +# add_link_options( +# # Remove unreferenced code +# $<$>:/OPT:REF> - if(APPLE) - add_link_options(-Wl,-dead_strip) - endif() +# # Remove duplicate sections +# $<$>:/OPT:ICF> - check_linker_flag(CXX -Wl,--no-undefined HAVE_NO_UNDEFINED) - if(HAVE_NO_UNDEFINED) - add_link_options(-Wl,--no-undefined) - endif() -endif() - -add_library(common INTERFACE) -target_include_directories( - common SYSTEM INTERFACE - ${CMAKE_SOURCE_DIR}/extneral - ${CMAKE_SOURCE_DIR}/external/reaper-sdk/sdk) -if(WIN32) - target_compile_options(common INTERFACE - /W3 - /WX - ) - target_compile_definitions(common INTERFACE NOMINMAX UNICODE) -else() - target_compile_options(common INTERFACE - -Wall -Wextra -Wpedantic -Werror - ) -endif() - -check_include_file_cxx(optional HAS_STD_OPTIONAL) -if(HAS_STD_OPTIONAL) - target_compile_definitions(common INTERFACE HAS_STD_OPTIONAL) -endif() - -check_include_file_cxx(variant HAS_STD_VARIANT) -if(HAS_STD_VARIANT) - target_compile_definitions(common INTERFACE HAS_STD_VARIANT) -endif() - -add_library(${PROJECT_NAME} SHARED) +# # Use relative path to the PDB file to avoid exposing the full path +# /PDBALTPATH:%_PDB% +# ) +# else() +# add_compile_options(-fsigned-char -fstack-protector-strong -fdiagnostics-color) +# endif() set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" # disable the "lib" prefix - OUTPUT_NAME "${PROJECT_NAME}-${ARCH_NAME}" + OUTPUT_NAME "reaper_${PROJECT_NAME}-${ARCH_NAME}" ) -set(REAPER_USER_PLUGINS "UserPlugins") +add_subdirectory(src) + +set(REAPER_USER_PLUGINS "UserPlugins") install(TARGETS ${PROJECT_NAME} - CONFIGURATIONS Debug Release + COMPONENT ${PROJECT_NAME} RUNTIME DESTINATION "${REAPER_USER_PLUGINS}" # Windows .dll LIBRARY DESTINATION "${REAPER_USER_PLUGINS}" # Linux .so/macOS .dylib ) - -if(WIN32) - install(FILES $ DESTINATION "${REAPER_USER_PLUGINS}" OPTIONAL) -endif() - -add_subdirectory(${CMAKE_SOURCE_DIR}/src) -target_link_libraries(reasolotus common) -target_link_libraries(${PROJECT_NAME} reasolotus) - -find_package(WDL REQUIRED) -target_link_libraries(reasolotus WDL::WDL) - -if(NOT WIN32) - find_package(SWELL REQUIRED) - target_link_libraries(reasolotus SWELL::swell) -endif() - diff --git a/cmake/FindPHP.cmake b/cmake/FindPHP.cmake new file mode 100644 index 0000000..fbeb7d8 --- /dev/null +++ b/cmake/FindPHP.cmake @@ -0,0 +1,19 @@ +find_program(PHP_EXECUTABLE php) +mark_as_advanced(PHP_EXECUTABLE) + +execute_process( + COMMAND ${PHP_EXECUTABLE} -v + OUTPUT_VARIABLE PHP_VERSION_OUTPUT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if(PHP_VERSION_OUTPUT MATCHES "PHP ([^ ]+) ") + set(PHP_VERSION "${CMAKE_MATCH_1}") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PHP + REQUIRED_VARS PHP_EXECUTABLE + VERSION_VAR PHP_VERSION +) diff --git a/cmake/FindSWELL.cmake b/cmake/FindSWELL.cmake index a4ba2e3..240b8f7 100644 --- a/cmake/FindSWELL.cmake +++ b/cmake/FindSWELL.cmake @@ -1,4 +1,4 @@ -if(TARGET SWELL::swell) +if(SWELL_FOUND) return() endif() @@ -12,22 +12,20 @@ find_path(SWELL_INCLUDE_DIR mark_as_advanced(SWELL_INCLUDE_DIR) set(SWELL_DIR "${SWELL_INCLUDE_DIR}/swell") -set(SWELL_RESGEN "${SWELL_DIR}/mac_resgen.php") +set(SWELL_RESGEN "${SWELL_DIR}/swell_resgen.php") include(FindPackageHandleStandardArgs) find_package_handle_standard_args(SWELL REQUIRED_VARS SWELL_DIR) -add_library(swell - ${SWELL_DIR}/swell-modstub$,.mm,-generic.cpp>) - -set_property(TARGET swell PROPERTY CXX_STANDARD 98) -target_compile_definitions(swell PUBLIC SWELL_PROVIDED_BY_APP) -target_include_directories(swell INTERFACE ${SWELL_INCLUDE_DIR}) -target_link_libraries(swell PUBLIC WDL::WDL) +add_library(swell ${SWELL_DIR}/swell-modstub$,.mm,-generic.cpp>) if(APPLE) - find_library(APPKIT_LIB AppKit) - target_link_libraries(swell PUBLIC ${APPKIT_LIB}) + find_library(APPKIT AppKit) + mark_as_advanced(APPKIT) + target_link_libraries(swell PUBLIC ${APPKIT}) endif() +target_compile_definitions(swell PUBLIC SWELL_PROVIDED_BY_APP) +target_include_directories(swell INTERFACE ${SWELL_INCLUDE_DIR}) + add_library(SWELL::swell ALIAS swell) diff --git a/cmake/FindWDL.cmake b/cmake/FindWDL.cmake index 4aa1b66..4edeb43 100644 --- a/cmake/FindWDL.cmake +++ b/cmake/FindWDL.cmake @@ -1,10 +1,10 @@ -if(TARGET WDL::WDL) +if(WDL_FOUND) return() endif() find_path(WDL_INCLUDE_DIR NAMES WDL/wdltypes.h - PATHS ${CMAKE_SOURCE_DIR}/external/WDL + PATHS ${CMAKE_SOURCE_DIR}/lib/WDL NO_DEFAULT_PATH ) mark_as_advanced(WDL_INCLUDE_DIR) @@ -19,4 +19,9 @@ add_library(wdl INTERFACE) target_compile_definitions(wdl INTERFACE WDL_NO_DEFINE_MINMAX) target_include_directories(wdl INTERFACE ${WDL_INCLUDE_DIR}) +if(NOT WIN32) + find_package(SWELL REQUIRED) + target_link_libraries(wdl INTERFACE SWELL::swell) +endif() + add_library(WDL::WDL ALIAS wdl) diff --git a/cmake/linux-cross.cmake b/cmake/linux-cross.cmake index 5b34c52..5eb54d1 100644 --- a/cmake/linux-cross.cmake +++ b/cmake/linux-cross.cmake @@ -6,8 +6,8 @@ set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR $ENV{ARCH}) if($ENV{ARCH} STREQUAL "i686") - set(CMAKE_C_FLAGS "-m32 -march=i686") - set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") + set(CMAKE_C_FLAGS -m32) + set(CMAKE_CXX_FLAGS -m32) elseif(NOT DEFINED ENV{TOOLCHAIN_PREFIX}) message(FATAL_ERROR "The TOOLCHAIN_PREFIX environment variable is not set.") else() @@ -19,6 +19,4 @@ if(DEFINED ENV{TOOLCHAIN_PREFIX}) set(CMAKE_FIND_ROOT_PATH /usr/$ENV{TOOLCHAIN_PREFIX}) set(CMAKE_LIBRARY_PATH /usr/lib/$ENV{TOOLCHAIN_PREFIX}) set(CMAKE_INCLUDE_PATH /usr/include/$ENV{TOOLCHAIN_PREFIX}) - set(ENV{PKG_CONFIG_PATH} /usr/lib/$ENV{TOOLCHAIN_PREFIX}/pkgconfig) - include(~/vcpkg/scripts/buildsystems/vcpkg.cmake) endif() \ No newline at end of file diff --git a/cmake/vcpkg-triplets/arch-env.cmake b/cmake/vcpkg-triplets/arch-env.cmake index e4f60d9..94453b9 100644 --- a/cmake/vcpkg-triplets/arch-env.cmake +++ b/cmake/vcpkg-triplets/arch-env.cmake @@ -2,7 +2,6 @@ if(NOT DEFINED ENV{ARCH}) message(FATAL_ERROR "The ARCH environment variable is not set.") endif() - if($ENV{ARCH} STREQUAL "x86_64") set(VCPKG_TARGET_ARCHITECTURE x64) elseif($ENV{ARCH} MATCHES "^i[36]86$") @@ -20,4 +19,4 @@ set(VCPKG_LIBRARY_LINKAGE static) set(VCPKG_CMAKE_SYSTEM_NAME ${CMAKE_HOST_SYSTEM_NAME}) set(VCPKG_OSX_ARCHITECTURES $ENV{ARCH}) -# set(VCPKG_OSX_DEPLOYMENT_TARGET $ENV{DEPLOY_TARGET}) \ No newline at end of file +set(VCPKG_OSX_DEPLOYMENT_TARGET $ENV{DEPLOY_TARGET}) \ No newline at end of file diff --git a/external/WDL b/external/WDL deleted file mode 160000 index 9840de4..0000000 --- a/external/WDL +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9840de4c25c5c7fe955b6ccbf6f6e176bcf2ebf2 diff --git a/external/reaper-sdk b/external/reaper-sdk deleted file mode 160000 index cf38979..0000000 --- a/external/reaper-sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cf3897918283577ff06acdbfc81bea599f00c068 diff --git a/lib/WDL b/lib/WDL new file mode 160000 index 0000000..3a9c63c --- /dev/null +++ b/lib/WDL @@ -0,0 +1 @@ +Subproject commit 3a9c63cb3a245f4b548bd7458265576fffcb4908 diff --git a/lib/reaper-sdk b/lib/reaper-sdk new file mode 160000 index 0000000..02deb81 --- /dev/null +++ b/lib/reaper-sdk @@ -0,0 +1 @@ +Subproject commit 02deb819c4ba0fc1bac001c8dfff7b9dbaf408ad diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cde0b8c..f5e4e27 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,6 @@ -add_library( - reasolotus OBJECT - main.cpp - configvar.cpp +target_sources( + ${PROJECT_NAME} + PRIVATE + main.cpp + configvar.cpp ) diff --git a/src/configvar.cpp b/src/configvar.cpp index 9e75813..6e05255 100644 --- a/src/configvar.cpp +++ b/src/configvar.cpp @@ -25,42 +25,14 @@ furnished to / do so, subject to the following conditions: / ******************************************************************************/ -#include -#include -#include - #include "configvar.h" - -#ifdef _WIN32 -std::wstring widen(const char*, UINT codepage = CP_UTF8); -inline std::wstring widen(const std::string& str, UINT codepage = CP_UTF8) -{ - return widen(str.c_str(), codepage); -} -std::wstring widen(const char* input, const UINT codepage) -{ - const int size = - MultiByteToWideChar(codepage, 0, input, -1, nullptr, 0) - 1; - - std::wstring output(size, 0); - MultiByteToWideChar(codepage, 0, input, -1, &output[0], size); - - return output; -} -#define widen_cstr(cstr) widen(cstr).c_str() -#else -#include -#define widen_cstr(cstr) cstr -#endif +#include +#include template <> void ConfigVar::save() { char buf[12]; snprintf(buf, sizeof(buf), "%d", *m_addr); - WritePrivateProfileString( - widen_cstr("REAPER"), - widen_cstr(m_name), - widen_cstr(buf), - widen_cstr(get_ini_file())); + WritePrivateProfileString("REAPER", m_name, buf, get_ini_file()); } diff --git a/src/configvar.h b/src/configvar.h index b370224..1f1afab 100644 --- a/src/configvar.h +++ b/src/configvar.h @@ -6,10 +6,10 @@ / / Permission is hereby granted, free of charge, to any person obtaining a copy / of this software and associated documentation files (the "Software"), to deal -/ in the Software without restriction, including without limitation the rights to -/ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -/ of the Software, and to permit persons to whom the Software is furnished to -/ do so, subject to the following conditions: +/ in the Software without restriction, including without limitation the rights +to / use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies / of the Software, and to permit persons to whom the Software is +furnished to / do so, subject to the following conditions: / / The above copyright notice and this permission notice shall be included in all / copies or substantial portions of the Software. @@ -26,76 +26,99 @@ ******************************************************************************/ #pragma once +#include -template -class ConfigVar { -public: - ConfigVar(const char *name, ReaProject *project = nullptr) - : m_name{name}, m_addr{} - { - int size = 0; - void *addr; - - if(const int offset = projectconfig_var_getoffs(name, &size)) - addr = projectconfig_var_addr(project, offset); - else - addr = get_config_var(name, &size); - - if(size == sizeof(T)) - m_addr = static_cast(addr); - } - - explicit operator bool() const { return m_addr != nullptr; } - - T &operator*() { return *m_addr; } - const T &operator*() const { return *m_addr; } - T *get() { return m_addr; } - const T *get() const { return m_addr; } - - T value_or(const T fallback) const - { - return m_addr ? *m_addr : fallback; - } - - bool try_set(const T newValue) - { - if(!m_addr) - return false; - - *m_addr = newValue; - return true; - } - - void save(); - -private: - const char *m_name; - T *m_addr; +template +class ConfigVar +{ + public: + explicit ConfigVar(const char* name, ReaProject* project = nullptr) + : m_name {name} + , m_addr {} + { + int size = 0; + void* addr; + + if (const int offset = projectconfig_var_getoffs(name, &size)) + addr = projectconfig_var_addr(project, offset); + else + addr = get_config_var(name, &size); + + if (size == sizeof(T)) + m_addr = static_cast(addr); + } + + explicit operator bool() const + { + return m_addr != nullptr; + } + + T& operator*() + { + return *m_addr; + } + + const T& operator*() const + { + return *m_addr; + } + + T* get() + { + return m_addr; + } + + const T* get() const + { + return m_addr; + } + + T value_or(const T fallback) const + { + return m_addr ? *m_addr : fallback; + } + + bool try_set(const T newValue) + { + if (!m_addr) + return false; + + *m_addr = newValue; + return true; + } + + void save(); + + private: + const char* m_name; + T* m_addr; }; -template -class ConfigVarOverride { -public: - ConfigVarOverride(ConfigVar var, const T tempValue) - : m_var{var} - { - if(m_var) { - m_initialValue = *m_var; - *m_var = tempValue; +template +class ConfigVarOverride +{ + public: + ConfigVarOverride(ConfigVar var, const T tempValue) + : m_var {var} + { + if (m_var) + { + m_initialValue = *m_var; + *m_var = tempValue; + } } - } - void rollback() - { - m_var.try_set(m_initialValue); - } + void rollback() + { + m_var.try_set(m_initialValue); + } - ~ConfigVarOverride() - { - rollback(); - } + ~ConfigVarOverride() + { + rollback(); + } -private: - ConfigVar m_var; - T m_initialValue; + private: + ConfigVar m_var; + T m_initialValue; }; diff --git a/src/main.cpp b/src/main.cpp index e21a94b..e8032ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include "reaper_vararg.hpp" +// #include "reaper_vararg.hpp" #include #include #include @@ -13,8 +13,8 @@ int solotus_command_id {-1}; int solotus_state {0}; -std::mutex m {}; std::atomic_bool atomic_bool_lock {false}; +std::mutex m {}; // from SWS/SNM extension /****************************************************************************** @@ -45,14 +45,21 @@ furnished to / do so, subject to the following conditions: ******************************************************************************/ bool SNM_SetIntConfigVar(const char* varName, const int newValue) { - if (!strcmp(varName, "vzoom2")) // set both vzoom3 and vzoom2 (below) + if (!strcmp(varName, "vzoom2")) + { // set both vzoom3 and vzoom2 (below) ConfigVar("vzoom3").try_set(static_cast(newValue)); + } if (ConfigVar(varName).try_set(newValue)) + { return true; - if (ConfigVar cv {varName}) { + } + if (ConfigVar cv {varName}) + { if (newValue > std::numeric_limits::max() || newValue < std::numeric_limits::min()) + { return false; + } *cv = newValue; return true; @@ -60,21 +67,25 @@ bool SNM_SetIntConfigVar(const char* varName, const int newValue) return false; } + // **************************************************************************** // end SnM_Util.cpp bool HasSend(MediaTrack* src, MediaTrack* dst) { bool res = false; - auto master = GetMasterTrack(0); + auto* master = GetMasterTrack(0); if (dst == master && (bool)GetMediaTrackInfo_Value(src, "B_MAINSEND") && - !GetParentTrack(src)) { + !GetParentTrack(src)) + { return true; } - for (int i = 0; i < GetTrackNumSends(src, 0); i++) { - auto p = (MediaTrack*)(uintptr_t) - GetTrackSendInfo_Value(src, 0, i, "P_DESTTRACK"); - if (p == dst) { + for (int i = 0; i < GetTrackNumSends(src, 0); i++) + { + auto* p = (MediaTrack*)(uintptr_t)GetTrackSendInfo_Value(src, 0, i, + "P_DESTTRACK"); + if (p == dst) + { res = true; break; } @@ -86,12 +97,12 @@ MediaTrack* GetMixbus() { static MediaTrack* res = nullptr; - if (res != nullptr && ValidatePtr2(0, res, "MediaTrack*")) { + if (res != nullptr && ValidatePtr2(0, res, "MediaTrack*")) + { return res; } - else { - res = nullptr; - } + + res = nullptr; char buf[BUFSIZ] {}; GUID* g {}; @@ -99,31 +110,34 @@ MediaTrack* GetMixbus() std::string s = buf; - for (int i = 0; i < GetNumTracks(); i++) { - auto tr = GetTrack(0, i); + for (int i = 0; i < GetNumTracks(); i++) + { + auto* tr = GetTrack(0, i); g = GetTrackGUID(tr); guidToString(g, buf); - if (s.compare(buf) == 0) { + if (s == buf) + { res = tr; } } - if (res == nullptr) { + if (res == nullptr) + { InsertTrackAtIndex(GetNumTracks(), false); res = GetTrack(0, GetNumTracks() - 1); GetSetMediaTrackInfo_String(res, "P_NAME", (char*)"Mix", true); SetMediaTrackInfo_Value(res, "B_MAINSEND", 0); SetMediaTrackInfo_Value(res, "B_SOLO_DEFEAT", 1); + + SetOnlyTrackSelected(res); + ReorderSelectedTracks(0, 0); + SetTrackSelected(res, false); } g = GetTrackGUID(res); guidToString(g, buf); SetProjExtState(0, EXTNAME, "Mix", buf); - SetOnlyTrackSelected(res); - ReorderSelectedTracks(0, 0); - SetTrackSelected(res, false); - return res; } @@ -131,12 +145,12 @@ MediaTrack* GetSolobus() { static MediaTrack* res = nullptr; - if (res != nullptr && ValidatePtr2(0, res, "MediaTrack*")) { + if (res != nullptr && ValidatePtr2(0, res, "MediaTrack*")) + { return res; } - else { - res = nullptr; - } + + res = nullptr; char buf[BUFSIZ] {}; GUID* g {}; @@ -144,71 +158,82 @@ MediaTrack* GetSolobus() std::string s = buf; - for (int i = 0; i < GetNumTracks(); i++) { - auto tr = GetTrack(0, i); + for (int i = 0; i < GetNumTracks(); i++) + { + auto* tr = GetTrack(0, i); g = GetTrackGUID(tr); guidToString(g, buf); - if (s.compare(buf) == 0) { + if (s == buf) + { res = tr; } } - if (res == nullptr) { + if (res == nullptr) + { InsertTrackAtIndex(GetNumTracks(), false); res = GetTrack(0, GetNumTracks() - 1); GetSetMediaTrackInfo_String(res, "P_NAME", (char*)"Solo", true); SetMediaTrackInfo_Value(res, "B_SOLO_DEFEAT", 1); + + SetOnlyTrackSelected(res); + ReorderSelectedTracks(0, 0); + SetTrackSelected(res, false); } g = GetTrackGUID(res); guidToString(g, buf); SetProjExtState(0, EXTNAME, "Solo", buf); - SetOnlyTrackSelected(res); - ReorderSelectedTracks(0, 0); - SetTrackSelected(res, false); - return res; } void Organize() { - auto master = GetMasterTrack(0); - auto mixbus = GetMixbus(); - auto solobus = GetSolobus(); + auto* master = GetMasterTrack(0); + auto* mixbus = GetMixbus(); + auto* solobus = GetSolobus(); auto folderFound {false}; // auto hasSends {false}; - for (auto i = 0; i < GetNumTracks(); i++) { - auto tr = GetTrack(0, i); + for (auto i = 0; i < GetNumTracks(); i++) + { + auto* tr = GetTrack(0, i); - if (GetTrackNumSends(tr, 1) > 0) { + if (GetTrackNumSends(tr, 1) > 0) + { SetMediaTrackInfo_Value(tr, "B_SOLO_DEFEAT", 1); } if (HasSend(tr, master) && tr != mixbus && tr != solobus && - tr != master) { + tr != master) + { CreateTrackSend(tr, mixbus); } - if (!HasSend(tr, solobus) && tr != solobus && tr != master) { + if (!HasSend(tr, solobus) && tr != solobus && tr != master) + { auto j = CreateTrackSend(tr, solobus); SetTrackSendInfo_Value(tr, 0, j, "B_MUTE", (tr == mixbus) ? 0 : 1); SetTrackSendInfo_Value(tr, 0, j, "I_SENDMODE", 3); } - auto parent = GetParentTrack(tr); + auto* parent = GetParentTrack(tr); - if (parent != nullptr) { + if (parent != nullptr) + { folderFound = true; auto hasParentSend = GetMediaTrackInfo_Value(tr, "B_MAINSEND"); - if (!HasSend(tr, parent) && hasParentSend > 0) { + if (!HasSend(tr, parent) && hasParentSend > 0) + { CreateTrackSend(tr, parent); } - for (int j = 0; j < GetTrackNumSends(tr, 0); j++) { - auto dst = (MediaTrack*)(uintptr_t) - GetTrackSendInfo_Value(tr, 0, j, "P_DESTTRACK"); - if (dst == mixbus) { + for (int j = 0; j < GetTrackNumSends(tr, 0); j++) + { + auto* dst = (MediaTrack*)(uintptr_t)GetTrackSendInfo_Value( + tr, 0, j, "P_DESTTRACK"); + if (dst == mixbus) + { RemoveTrackSend(tr, 0, j); } } @@ -220,7 +245,8 @@ void Organize() SetTrackSelected(tr, false); } - if (tr != solobus) { + if (tr != solobus) + { SetMediaTrackInfo_Value(tr, "B_MAINSEND", 0); } @@ -232,13 +258,15 @@ void Organize() SetMediaTrackInfo_Value(mixbus, "B_SOLO_DEFEAT", 1); SetMediaTrackInfo_Value(solobus, "B_SOLO_DEFEAT", 1); - if (folderFound) { + if (folderFound) + { ShowConsoleMsg( "ReaSolotus: Folders not supported. Use sends instead. \n"); } char buf[BUFSIZ]; - if (get_config_var_string("soloip", buf, BUFSIZ) && std::stoi(buf) != 0) { + if (get_config_var_string("soloip", buf, BUFSIZ) && std::stoi(buf) != 0) + { SNM_SetIntConfigVar("soloip", 0); }; } @@ -247,42 +275,53 @@ void DoSolo(std::set& queue) { PreventUIRefresh(1); // Undo_BeginBlock2(0); - if (!queue.empty()) { + if (!queue.empty()) + { Organize(); } - auto solobus = GetSolobus(); - auto mixbus = GetMixbus(); - for (auto&& tr : queue) { - for (int i = 0; i < GetTrackNumSends(tr, 0); i++) { - auto dst = (MediaTrack*)(uintptr_t) - GetTrackSendInfo_Value(tr, 0, i, "P_DESTTRACK"); - if (dst == solobus) { + auto* solobus = GetSolobus(); + auto* mixbus = GetMixbus(); + for (auto&& tr : queue) + { + for (int i = 0; i < GetTrackNumSends(tr, 0); i++) + { + auto dst = (MediaTrack*)(uintptr_t)GetTrackSendInfo_Value( + tr, 0, i, "P_DESTTRACK"); + if (dst == solobus) + { SetTrackSendInfo_Value(tr, 0, i, "B_MUTE", 0); } } } - for (int i = 0; i < GetTrackNumSends(solobus, -1); i++) { - auto src = (MediaTrack*)(uintptr_t) - GetTrackSendInfo_Value(solobus, -1, i, "P_SRCTRACK"); - if (!queue.contains(src) && src != mixbus) { + for (int i = 0; i < GetTrackNumSends(solobus, -1); i++) + { + auto* src = (MediaTrack*)(uintptr_t)GetTrackSendInfo_Value( + solobus, -1, i, "P_SRCTRACK"); + if (!queue.contains(src) && src != mixbus) + { auto isMuted = (bool)GetTrackSendInfo_Value(solobus, -1, i, "B_MUTE"); - if (!isMuted) { + if (!isMuted) + { SetTrackSendInfo_Value(solobus, -1, i, "B_MUTE", 1); } } } - for (int i = 0; i < GetTrackNumSends(mixbus, 0); i++) { - auto dst = (MediaTrack*)(uintptr_t) - GetTrackSendInfo_Value(mixbus, 0, i, "P_DESTTRACK"); - if (dst == solobus) { + for (int i = 0; i < GetTrackNumSends(mixbus, 0); i++) + { + auto* dst = (MediaTrack*)(uintptr_t)GetTrackSendInfo_Value( + mixbus, 0, i, "P_DESTTRACK"); + if (dst == solobus) + { auto isMuted = (bool)GetTrackSendInfo_Value(mixbus, 0, i, "B_MUTE"); - if (isMuted && !AnyTrackSolo(0)) { + if (isMuted && !AnyTrackSolo(0)) + { SetTrackSendInfo_Value(mixbus, 0, i, "B_MUTE", 0); } - else if (!isMuted && AnyTrackSolo(0)) { + else if (!isMuted && AnyTrackSolo(0)) + { SetTrackSendInfo_Value(mixbus, 0, i, "B_MUTE", 1); } } @@ -295,16 +334,20 @@ void DoMute(MediaTrack* tr, bool mute) { PreventUIRefresh(1); (void)GetMixbus(); - auto solobus = GetSolobus(); - for (int i = 0; i < GetTrackNumSends(tr, 0); i++) { - auto dst = (MediaTrack*)(uintptr_t) - GetTrackSendInfo_Value(tr, 0, i, "P_DESTTRACK"); - if (dst != solobus) { + auto* solobus = GetSolobus(); + for (int i = 0; i < GetTrackNumSends(tr, 0); i++) + { + auto* dst = (MediaTrack*)(uintptr_t)GetTrackSendInfo_Value( + tr, 0, i, "P_DESTTRACK"); + if (dst != solobus) + { auto isMuted = (bool)GetTrackSendInfo_Value(tr, 0, i, "B_MUTE"); - if (!isMuted && mute) { + if (!isMuted && mute) + { SetTrackSendInfo_Value(tr, 0, i, "B_MUTE", 1); } - else if (isMuted && !mute) { + else if (isMuted && !mute) + { SetTrackSendInfo_Value(tr, 0, i, "B_MUTE", 0); } } @@ -312,13 +355,8 @@ void DoMute(MediaTrack* tr, bool mute) PreventUIRefresh(-1); } -static bool CommandHook( - KbdSectionInfo* sec, - const int command, - const int val, - const int valhw, - const int relmode, - HWND hwnd) +static bool CommandHook(KbdSectionInfo* sec, const int command, const int val, + const int valhw, const int relmode, HWND hwnd) { std::scoped_lock lock(m); (void)sec; @@ -327,7 +365,8 @@ static bool CommandHook( (void)relmode; (void)hwnd; - if (command == solotus_command_id) { + if (command == solotus_command_id) + { solotus_state = !solotus_state; return true; } @@ -338,7 +377,8 @@ static bool CommandHook( int ToggleActionCallback(int command_id) { std::scoped_lock lock(m); - if (command_id == solotus_command_id) { + if (command_id == solotus_command_id) + { return solotus_state; } @@ -347,11 +387,8 @@ int ToggleActionCallback(int command_id) void Register() { - custom_action_register_t action { - 0, - "AK5K_REASOLOTUS", - "ReaSolotus", - nullptr}; + custom_action_register_t action {0, "AK5K_REASOLOTUS", "ReaSolotus", + nullptr}; solotus_command_id = plugin_register("custom_action", &action); @@ -359,44 +396,54 @@ void Register() plugin_register("toggleaction", (void*)&ToggleActionCallback); } -class ReaSolotus : public IReaperControlSurface { +class ReaSolotus : public IReaperControlSurface +{ public: - const char* GetTypeString() + const char* GetTypeString() override { return "REASOLOTUS"; } - const char* GetDescString() + + const char* GetDescString() override { return "ReaSolotus"; } - const char* GetConfigString() + + const char* GetConfigString() override { return ""; } - void SetSurfaceSolo(MediaTrack* trackid, bool solo) + + void SetSurfaceSolo(MediaTrack* trackid, bool solo) override { // to avoid internal recursion - if (atomic_bool_lock == true) { + if (atomic_bool_lock) + { return; } std::scoped_lock lock(m); - if (solotus_state == 0) { + if (solotus_state == 0) + { return; } - auto master = GetMasterTrack(0); - if (trackid != master) { + auto* master = GetMasterTrack(0); + if (trackid != master) + { return; } atomic_bool_lock = true; std::set queue {}; - if (solo) { - for (int i = 0; i < GetNumTracks(); i++) { - auto tr = GetTrack(0, i); + if (solo) + { + for (int i = 0; i < GetNumTracks(); i++) + { + auto* tr = GetTrack(0, i); int state {}; (void)GetTrackState(tr, &state); - if (state & 16) { + if (state & 16) + { queue.insert(tr); } } @@ -406,19 +453,22 @@ class ReaSolotus : public IReaperControlSurface { atomic_bool_lock = false; } - void SetSurfaceMute(MediaTrack* trackid, bool mute) + void SetSurfaceMute(MediaTrack* trackid, bool mute) override { // to avoid internal recursion - if (atomic_bool_lock == true) { + if (atomic_bool_lock) + { return; } // std::scoped_lock lock(m); - if (solotus_state == 0) { + if (solotus_state == 0) + { return; } - auto master = GetMasterTrack(0); - if (trackid == master) { + auto* master = GetMasterTrack(0); + if (trackid == master) + { return; } @@ -430,20 +480,21 @@ class ReaSolotus : public IReaperControlSurface { ReaSolotus* csurf; -extern "C" { +extern "C" +{ REAPER_PLUGIN_DLL_EXPORT int ReaperPluginEntry( - REAPER_PLUGIN_HINSTANCE hInstance, - reaper_plugin_info_t* rec) + REAPER_PLUGIN_HINSTANCE hInstance, reaper_plugin_info_t* rec) { (void)hInstance; csurf = new ReaSolotus(); - if (!rec) { + if (!rec) + { delete csurf; return 0; } - else if ( - rec->caller_version != REAPER_PLUGIN_VERSION || - REAPERAPI_LoadAPI(rec->GetFunc)) { + if (rec->caller_version != REAPER_PLUGIN_VERSION || + REAPERAPI_LoadAPI(rec->GetFunc)) + { return 0; } Register(); diff --git a/src/reaper_vararg.hpp b/src/reaper_vararg.hpp index 9c649fe..f14d5ae 100644 --- a/src/reaper_vararg.hpp +++ b/src/reaper_vararg.hpp @@ -2,6 +2,7 @@ /* Usage example: static int HelloWorld(int foo, int bar) { return foo * bar; } + extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT( REAPER_PLUGIN_HINSTANCE instance, reaper_plugin_info_t *rec) { @@ -12,25 +13,6 @@ extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT( // ... } */ -/* ReaImGui: ReaScript binding for Dear ImGui - * Copyright (C) 2021 Christian Fillion - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef REAIMGUI_API_VARARG_HPP -#define REAIMGUI_API_VARARG_HPP #include @@ -38,55 +20,51 @@ template struct ReaScriptAPI; template -struct ReaScriptAPI { - static const void* applyVarArg( - R (*fn)(Args...), - void** argv, - const int argc) +struct ReaScriptAPI +{ + static const void *applyVarArg(R (*fn)(Args...), void **argv, const int argc) { if (static_cast(argc) < sizeof...(Args)) return nullptr; - const auto& args {makeTuple(argv, std::index_sequence_for {})}; + const auto &args{makeTuple(argv, std::index_sequence_for{})}; - if constexpr (std::is_void_v) { + if constexpr (std::is_void_v) + { std::apply(fn, args); return nullptr; } - else if constexpr (std::is_floating_point_v) { - const auto value {std::apply(fn, args)}; - void* storage {argv[argc - 1]}; - *static_cast(storage) = value; + else if constexpr (std::is_floating_point_v) + { + const auto value{std::apply(fn, args)}; + void *storage{argv[argc - 1]}; + *static_cast(storage) = value; return storage; } - else { + else + { // cast numbers to have the same size as a pointer to avoid warnings - using IntPtrR = - std::conditional_t, R, uintptr_t>; - const auto value {static_cast(std::apply(fn, args))}; - return reinterpret_cast(value); + using IntPtrR = std::conditional_t, R, uintptr_t>; + const auto value{static_cast(std::apply(fn, args))}; + return reinterpret_cast(value); } } - private: +private: template using NthType = typename std::tuple_element>::type; template - static auto makeTuple(void** argv, std::index_sequence) + static auto makeTuple(void **argv, std::index_sequence) { // C++17 is amazing return std::make_tuple( - std::is_floating_point_v> - ? *reinterpret_cast*>(argv[I]) - : (NthType)reinterpret_cast(argv[I])...); + std::is_floating_point_v> ? *reinterpret_cast *>(argv[I]) : (NthType)reinterpret_cast(argv[I])...); } }; template -const void* InvokeReaScriptAPI(void** argv, int argc) +const void *InvokeReaScriptAPI(void **argv, int argc) { return ReaScriptAPI::applyVarArg(fn, argv, argc); -} - -#endif \ No newline at end of file +} \ No newline at end of file