-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,883 additions
and
1,887 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
[submodule "vendor/reaper-sdk"] | ||
path = vendor/reaper-sdk | ||
url = https://github.com/justinfrankel/reaper-sdk | ||
[submodule "vendor/WDL"] | ||
path = vendor/WDL | ||
url = https://github.com/justinfrankel/WDL | ||
[submodule "vendor/WDL"] | ||
path = vendor/WDL | ||
url = https://github.com/justinfrankel/WDL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
if(TARGET SWELL::swell) | ||
return() | ||
endif() | ||
|
||
find_package(WDL REQUIRED) | ||
|
||
find_path(SWELL_INCLUDE_DIR | ||
NAMES swell/swell.h | ||
PATHS ${WDL_DIR} | ||
NO_DEFAULT_PATH | ||
) | ||
mark_as_advanced(SWELL_INCLUDE_DIR) | ||
|
||
set(SWELL_DIR "${SWELL_INCLUDE_DIR}/swell") | ||
set(SWELL_RESGEN "${SWELL_DIR}/mac_resgen.php") | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(SWELL REQUIRED_VARS SWELL_DIR) | ||
|
||
add_library(swell | ||
${SWELL_DIR}/swell-modstub$<IF:$<BOOL:${APPLE}>,.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) | ||
|
||
if(APPLE) | ||
find_library(APPKIT_LIB AppKit) | ||
target_link_libraries(swell PUBLIC ${APPKIT_LIB}) | ||
endif() | ||
|
||
add_library(SWELL::swell ALIAS swell) | ||
if(TARGET SWELL::swell) | ||
return() | ||
endif() | ||
|
||
find_package(WDL REQUIRED) | ||
|
||
find_path(SWELL_INCLUDE_DIR | ||
NAMES swell/swell.h | ||
PATHS ${WDL_DIR} | ||
NO_DEFAULT_PATH | ||
) | ||
mark_as_advanced(SWELL_INCLUDE_DIR) | ||
|
||
set(SWELL_DIR "${SWELL_INCLUDE_DIR}/swell") | ||
set(SWELL_RESGEN "${SWELL_DIR}/mac_resgen.php") | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(SWELL REQUIRED_VARS SWELL_DIR) | ||
|
||
add_library(swell | ||
${SWELL_DIR}/swell-modstub$<IF:$<BOOL:${APPLE}>,.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) | ||
|
||
if(APPLE) | ||
find_library(APPKIT_LIB AppKit) | ||
target_link_libraries(swell PUBLIC ${APPKIT_LIB}) | ||
endif() | ||
|
||
add_library(SWELL::swell ALIAS swell) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
if(TARGET WDL::WDL) | ||
return() | ||
endif() | ||
|
||
find_path(WDL_INCLUDE_DIR | ||
NAMES WDL/wdltypes.h | ||
PATHS ${CMAKE_SOURCE_DIR}/vendor/WDL | ||
NO_DEFAULT_PATH | ||
) | ||
mark_as_advanced(WDL_INCLUDE_DIR) | ||
|
||
set(WDL_DIR "${WDL_INCLUDE_DIR}/WDL") | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(WDL REQUIRED_VARS WDL_DIR WDL_INCLUDE_DIR) | ||
|
||
add_library(wdl INTERFACE) | ||
|
||
target_compile_definitions(wdl INTERFACE WDL_NO_DEFINE_MINMAX) | ||
target_include_directories(wdl INTERFACE ${WDL_INCLUDE_DIR}) | ||
|
||
add_library(WDL::WDL ALIAS wdl) | ||
if(TARGET WDL::WDL) | ||
return() | ||
endif() | ||
|
||
find_path(WDL_INCLUDE_DIR | ||
NAMES WDL/wdltypes.h | ||
PATHS ${CMAKE_SOURCE_DIR}/vendor/WDL | ||
NO_DEFAULT_PATH | ||
) | ||
mark_as_advanced(WDL_INCLUDE_DIR) | ||
|
||
set(WDL_DIR "${WDL_INCLUDE_DIR}/WDL") | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(WDL REQUIRED_VARS WDL_DIR WDL_INCLUDE_DIR) | ||
|
||
add_library(wdl INTERFACE) | ||
|
||
target_compile_definitions(wdl INTERFACE WDL_NO_DEFINE_MINMAX) | ||
target_include_directories(wdl INTERFACE ${WDL_INCLUDE_DIR}) | ||
|
||
add_library(WDL::WDL ALIAS wdl) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
// Extracted from ReaPack's and ReaImGui's source code (LGPL v3) | ||
|
||
/* 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) | ||
{ | ||
// ... | ||
// API_HelloWorld and APIdef_HelloWorld must also be registered as usual | ||
plugin_register("APIvararg_HelloWorld", | ||
reinterpret_cast<void *>(&InvokeReaScriptAPI<&HelloWorld>)); | ||
// ... | ||
} | ||
*/ | ||
|
||
#include <tuple> | ||
|
||
template<typename T> | ||
struct ReaScriptAPI; | ||
|
||
template<typename R, typename... Args> | ||
struct ReaScriptAPI<R(*)(Args...)> | ||
{ | ||
static const void *applyVarArg(R(*fn)(Args...), void **argv, const int argc) | ||
{ | ||
if(static_cast<size_t>(argc) < sizeof...(Args)) | ||
return nullptr; | ||
|
||
const auto &args { makeTuple(argv, std::index_sequence_for<Args...>{}) }; | ||
|
||
if constexpr (std::is_void_v<R>) { | ||
std::apply(fn, args); | ||
return nullptr; | ||
} | ||
else if constexpr (std::is_floating_point_v<R>) { | ||
const auto value { std::apply(fn, args) }; | ||
void *storage { argv[argc - 1] }; | ||
*static_cast<double *>(storage) = value; | ||
return storage; | ||
} | ||
else { | ||
// cast numbers to have the same size as a pointer to avoid warnings | ||
using IntPtrR = std::conditional_t<std::is_pointer_v<R>, R, uintptr_t>; | ||
const auto value { static_cast<IntPtrR>(std::apply(fn, args)) }; | ||
return reinterpret_cast<const void *>(value); | ||
} | ||
} | ||
|
||
private: | ||
template<size_t I> | ||
using NthType = typename std::tuple_element<I, std::tuple<Args...>>::type; | ||
|
||
template<size_t... I> | ||
static auto makeTuple(void **argv, std::index_sequence<I...>) | ||
{ | ||
// C++17 is amazing | ||
return std::make_tuple( | ||
std::is_floating_point_v<NthType<I>> ? | ||
*reinterpret_cast<NthType<I>*>(argv[I]) : | ||
(NthType<I>)reinterpret_cast<uintptr_t>(argv[I]) | ||
... | ||
); | ||
} | ||
|
||
}; | ||
|
||
template<auto fn> | ||
const void *InvokeReaScriptAPI(void **argv, int argc) | ||
{ | ||
return ReaScriptAPI<decltype(fn)>::applyVarArg(fn, argv, argc); | ||
} | ||
// Extracted from ReaPack's and ReaImGui's source code (LGPL v3) | ||
|
||
/* 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) | ||
{ | ||
// ... | ||
// API_HelloWorld and APIdef_HelloWorld must also be registered as usual | ||
plugin_register("APIvararg_HelloWorld", | ||
reinterpret_cast<void *>(&InvokeReaScriptAPI<&HelloWorld>)); | ||
// ... | ||
} | ||
*/ | ||
|
||
#include <tuple> | ||
|
||
template<typename T> | ||
struct ReaScriptAPI; | ||
|
||
template<typename R, typename... Args> | ||
struct ReaScriptAPI<R(*)(Args...)> | ||
{ | ||
static const void *applyVarArg(R(*fn)(Args...), void **argv, const int argc) | ||
{ | ||
if(static_cast<size_t>(argc) < sizeof...(Args)) | ||
return nullptr; | ||
|
||
const auto &args { makeTuple(argv, std::index_sequence_for<Args...>{}) }; | ||
|
||
if constexpr (std::is_void_v<R>) { | ||
std::apply(fn, args); | ||
return nullptr; | ||
} | ||
else if constexpr (std::is_floating_point_v<R>) { | ||
const auto value { std::apply(fn, args) }; | ||
void *storage { argv[argc - 1] }; | ||
*static_cast<double *>(storage) = value; | ||
return storage; | ||
} | ||
else { | ||
// cast numbers to have the same size as a pointer to avoid warnings | ||
using IntPtrR = std::conditional_t<std::is_pointer_v<R>, R, uintptr_t>; | ||
const auto value { static_cast<IntPtrR>(std::apply(fn, args)) }; | ||
return reinterpret_cast<const void *>(value); | ||
} | ||
} | ||
|
||
private: | ||
template<size_t I> | ||
using NthType = typename std::tuple_element<I, std::tuple<Args...>>::type; | ||
|
||
template<size_t... I> | ||
static auto makeTuple(void **argv, std::index_sequence<I...>) | ||
{ | ||
// C++17 is amazing | ||
return std::make_tuple( | ||
std::is_floating_point_v<NthType<I>> ? | ||
*reinterpret_cast<NthType<I>*>(argv[I]) : | ||
(NthType<I>)reinterpret_cast<uintptr_t>(argv[I]) | ||
... | ||
); | ||
} | ||
|
||
}; | ||
|
||
template<auto fn> | ||
const void *InvokeReaScriptAPI(void **argv, int argc) | ||
{ | ||
return ReaScriptAPI<decltype(fn)>::applyVarArg(fn, argv, argc); | ||
} |
Oops, something went wrong.