Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ak5k committed Jan 7, 2022
1 parent e68b7b7 commit 8d663ff
Show file tree
Hide file tree
Showing 11 changed files with 1,883 additions and 1,887 deletions.
9 changes: 3 additions & 6 deletions .gitmodules
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
66 changes: 33 additions & 33 deletions cmake/FindSWELL.cmake
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)
44 changes: 22 additions & 22 deletions cmake/FindWDL.cmake
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)
1,554 changes: 777 additions & 777 deletions include/reaper_imgui_functions.h

Large diffs are not rendered by default.

144 changes: 72 additions & 72 deletions include/reascript_vararg.hpp
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);
}
Loading

0 comments on commit 8d663ff

Please sign in to comment.