Skip to content

Commit

Permalink
Initial Work - AUv2 (#178)
Browse files Browse the repository at this point in the history
the first pass at a working AUv2 which in many cases provides audio, ui, midi and more in a variety of hosts. Also associated cleanup and refactoring and sharing across the formats.
  • Loading branch information
defiantnerd authored Oct 21, 2023
1 parent 2e7a785 commit 3074ce0
Show file tree
Hide file tree
Showing 27 changed files with 1,769 additions and 250 deletions.
3 changes: 0 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
UseTab: Never
---
Language: Cpp
AlignAfterOpenBracket: BAS_Align
ConstructorInitializerIndentWidth: 2
SpaceBeforeParens: ControlStatements
ColumnLimit: 105
BasedOnStyle: Google
IndentWidth: 2
AlignAfterOpenBracket: Align
Expand All @@ -20,7 +18,6 @@ AllowShortFunctionsOnASingleLine: None
---
Language: ObjC
BasedOnStyle: Google
AlignAfterOpenBracket: BAS_Align
ConstructorInitializerIndentWidth: 2
SpaceBeforeParens: ControlStatements
IndentWidth: 2
Expand Down
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ foreach(dir ${CLANG_FORMAT_DIRS})
list(APPEND CLANG_FORMAT_GLOBS "':(glob)${dir}/**/*.${ext}'")
endforeach()
endforeach()
add_custom_command(TARGET clap-wrapper-code-checks
POST_BUILD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E echo About to check clang-format using ${CLANG_FORMAT_EXE}
COMMAND git ls-files -- ${CLANG_FORMAT_GLOBS} | xargs ${CLANG_FORMAT_EXE} --dry-run --Werror
)
# }}}
#add_custom_command(TARGET clap-wrapper-code-checks
# POST_BUILD
# WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
# COMMAND ${CMAKE_COMMAND} -E echo About to check clang-format using ${CLANG_FORMAT_EXE}
# COMMAND git ls-files -- ${CLANG_FORMAT_GLOBS} | xargs ${CLANG_FORMAT_EXE} --dry-run --Werror
# )
# }}}
10 changes: 9 additions & 1 deletion cmake/wrap_auv2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ function(target_add_auv2_wrapper)

message(STATUS "clap-wrapper: Adding AUV2 Wrapper to target ${AUV2_TARGET} generating '${AUV2_OUTPUT_NAME}.component'")

target_sources(${AUV2_TARGET} PRIVATE ${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/os/macos.mm)

# This is a placeholder dummy until we actually write the AUv2
# Similarly the subordinate library being an interface below
# is a placeholder. When we write it we will follow a similar
Expand All @@ -139,7 +141,12 @@ function(target_add_auv2_wrapper)
${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/wrapasauv2.cpp
${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/auv2/auv2_shared.h
${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/auv2/auv2_base_classes.h
${bhtgoutdir}/generated_entrypoints.hxx)
${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/auv2/process.h
${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/auv2/process.cpp
${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/auv2/wrappedview.h
${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/auv2/wrappedview.mm

${bhtgoutdir}/generated_entrypoints.hxx)
target_compile_options(${AUV2_TARGET} PRIVATE -fno-char8_t)

if (NOT TARGET ${AUV2_TARGET}-clap-wrapper-auv2-lib)
Expand All @@ -163,6 +170,7 @@ function(target_add_auv2_wrapper)
target_link_libraries(${AUV2_TARGET} PUBLIC
"-framework Foundation"
"-framework CoreFoundation"
"-framework AppKit"
"-framework AudioToolbox")

set_target_properties(${AUV2_TARGET} PROPERTIES
Expand Down
10 changes: 5 additions & 5 deletions cmake/wrap_vst3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ function(private_add_vst3_wrapper_sources)

set(tg ${PV3_TARGET})
set(sd ${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR})

target_compile_definitions(${tg} PUBLIC CLAP_WRAPPER_BUILD_FOR_VST3=1)
if(WIN32)
target_sources(${tg} PRIVATE ${sd}/src/detail/vst3/os/windows.cpp)
target_sources(${tg} PRIVATE ${sd}/src/detail/os/windows.cpp)
elseif (APPLE)
target_sources(${tg} PRIVATE ${sd}/src/detail/vst3/os/macos.mm)
target_sources(${tg} PRIVATE ${sd}/src/detail/os/macos.mm)
elseif(UNIX)
target_sources(${tg} PRIVATE ${sd}/src/detail/vst3/os/linux.cpp)
target_sources(${tg} PRIVATE ${sd}/src/detail/os/linux.cpp)
endif()

target_sources(${tg} PRIVATE
Expand Down Expand Up @@ -165,4 +165,4 @@ function(target_add_vst3_wrapper)
if (${CLAP_WRAPPER_COPY_AFTER_BUILD})
target_copy_after_build(TARGET ${V3_TARGET} FLAVOR vst3)
endif()
endfunction(target_add_vst3_wrapper)
endfunction(target_add_vst3_wrapper)
16 changes: 8 additions & 8 deletions include/clapwrapper/auv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ static const CLAP_CONSTEXPR char CLAP_PLUGIN_FACTORY_INFO_AUV2[] =

typedef struct clap_plugin_info_as_auv2
{
char au_type[5]; // the au_type. If empty (best choice) use the features[0] to aumu aufx aumi
char au_subt[5]; // the subtype. If empty (worst choice) we try a bad 32 bit hash of the id
char au_type[5]; // the au_type. If empty (best choice) use the features[0] to aumu aufx aumi
char au_subt[5]; // the subtype. If empty (worst choice) we try a bad 32 bit hash of the id
} clap_plugin_info_as_auv2_t;

typedef struct clap_plugin_factory_as_auv2
{
// optional values for the Steinberg::PFactoryInfo structure
const char *manufacturer_code; // your 'manu' field
const char *manufacturer_name; // your manufacturer display name
// optional values for the Steinberg::PFactoryInfo structure
const char *manufacturer_code; // your 'manu' field
const char *manufacturer_name; // your manufacturer display name

// populate information about this particular auv2. Return false if we cannot.
bool(CLAP_ABI *get_auv2_info)(const clap_plugin_factory_as_auv2 *factory, uint32_t index,
clap_plugin_info_as_auv2_t *info);
// populate information about this particular auv2. Return false if we cannot.
bool(CLAP_ABI *get_auv2_info)(const clap_plugin_factory_as_auv2 *factory, uint32_t index,
clap_plugin_info_as_auv2_t *info);
} clap_plugin_factory_as_auv2_t;
27 changes: 16 additions & 11 deletions include/clapwrapper/vst3.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
#endif

// the factory extension
static const CLAP_CONSTEXPR char CLAP_PLUGIN_FACTORY_INFO_VST3[] = "clap.plugin-factory-info-as-vst3.draft0";
static const CLAP_CONSTEXPR char CLAP_PLUGIN_FACTORY_INFO_VST3[] =
"clap.plugin-factory-info-as-vst3.draft0";

// the plugin extension
static const CLAP_CONSTEXPR char CLAP_PLUGIN_AS_VST3[] = "clap.plugin-info-as-vst3.draft0";

typedef uint8_t array_of_16_bytes[16];


// clang-format off
// VST3GUID allows you to provide the 4 uint32_t parts of the GUID and transforms them to the 16 byte array
#if WIN
#define VST3GUID(g1, g2, g3, g4) \
Expand All @@ -45,6 +46,7 @@ typedef uint8_t array_of_16_bytes[16];
(uint8_t)((g4 & 0x0000FF00) >> 8), \
(uint8_t)((g4 & 0x000000FF) ), \
}

#else
#define VST3GUID(g1, g2, g3, g4) \
{ \
Expand All @@ -68,6 +70,8 @@ typedef uint8_t array_of_16_bytes[16];

#endif

// clang-format on

/*
clap_plugin_as_vst3
Expand All @@ -77,9 +81,9 @@ typedef uint8_t array_of_16_bytes[16];

typedef struct clap_plugin_info_as_vst3
{
const char* vendor; // vendor
const array_of_16_bytes* componentId; // compatibility GUID
const char* features; // feature string for SubCategories
const char* vendor; // vendor
const array_of_16_bytes* componentId; // compatibility GUID
const char* features; // feature string for SubCategories
} clap_plugin_info_as_vst3_t;

/*
Expand All @@ -94,13 +98,14 @@ typedef struct clap_plugin_info_as_vst3
typedef struct clap_plugin_factory_as_vst3
{
// optional values for the Steinberg::PFactoryInfo structure
const char* vendor; // if not nullptr, the vendor string in the
const char* vendor; // if not nullptr, the vendor string in the
const char* vendor_url;
const char* email_contact;

// retrieve additional information for the Steinberg::PClassInfo2 struct by pointer to clap_plugin_as_vst3
// returns nullptr if no additional information is provided or can be a nullptr itself
const clap_plugin_info_as_vst3_t* (CLAP_ABI* get_vst3_info)(const clap_plugin_factory_as_vst3* factory, uint32_t index);
const clap_plugin_info_as_vst3_t*(CLAP_ABI* get_vst3_info)(const clap_plugin_factory_as_vst3* factory,
uint32_t index);
} clap_plugin_factory_as_vst3_t;

enum clap_supported_note_expressions
Expand All @@ -113,7 +118,7 @@ enum clap_supported_note_expressions
AS_VST3_NOTE_EXPRESSION_BRIGHTNESS = 1 << 5,
AS_VST3_NOTE_EXPRESSION_PRESSURE = 1 << 6,

AS_VST3_NOTE_EXPRESSION_ALL = (1<<7)-1 // just the and of the above
AS_VST3_NOTE_EXPRESSION_ALL = (1 << 7) - 1 // just the and of the above

};

Expand All @@ -123,7 +128,7 @@ enum clap_supported_note_expressions
*/
typedef struct clap_plugin_as_vst3
{
uint32_t(CLAP_ABI* getNumMIDIChannels) (const clap_plugin* plugin, uint32_t note_port); // return 1-16
uint32_t(CLAP_ABI* supportedNoteExpressions) (const clap_plugin* plugin); // returns a bitmap of clap_supported_note_expressions
uint32_t(CLAP_ABI* getNumMIDIChannels)(const clap_plugin* plugin, uint32_t note_port); // return 1-16
uint32_t(CLAP_ABI* supportedNoteExpressions)(
const clap_plugin* plugin); // returns a bitmap of clap_supported_note_expressions
} clap_plugin_as_vst3_t;

11 changes: 10 additions & 1 deletion src/clap_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ void Plugin::log(clap_log_severity severity, const char* msg)

bool Plugin::is_main_thread() const
{
if (this->_main_thread_override > 0)
{
return true;
}
return _main_thread_id == std::this_thread::get_id();
}

Expand All @@ -394,14 +398,19 @@ bool Plugin::is_audio_thread() const
{
return true;
}
return !is_main_thread();
return !(_main_thread_id == std::this_thread::get_id());
}

CLAP_NODISCARD Raise Plugin::AlwaysAudioThread()
{
return Raise(this->_audio_thread_override);
}

CLAP_NODISCARD Raise Plugin::AlwaysMainThread()
{
return Raise(this->_main_thread_override);
}

void Plugin::param_rescan(clap_param_rescan_flags flags)
{
_parentHost->param_rescan(flags);
Expand Down
10 changes: 6 additions & 4 deletions src/clap_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class IHost
virtual void param_clear(clap_id param, clap_param_clear_flags flags) = 0;
virtual void param_request_flush() = 0;

virtual void latency_changed() = 0;
virtual void tail_changed() = 0;

virtual bool gui_can_resize() = 0;
virtual bool gui_request_resize(uint32_t width, uint32_t height) = 0;
virtual bool gui_request_show() = 0;
Expand All @@ -69,10 +72,6 @@ class IHost
virtual bool modify_fd(int fd, clap_posix_fd_flags_t flags) = 0;
virtual bool unregister_fd(int fd) = 0;
#endif

virtual void latency_changed() = 0;

virtual void tail_changed() = 0;
};

struct ClapPluginExtensions;
Expand Down Expand Up @@ -215,6 +214,7 @@ class Plugin

#endif
CLAP_NODISCARD Raise AlwaysAudioThread();
CLAP_NODISCARD Raise AlwaysMainThread();

private:
static const void* clapExtension(const clap_host* host, const char* extension);
Expand All @@ -229,6 +229,8 @@ class Plugin
IHost* _parentHost = nullptr;
const std::thread::id _main_thread_id = std::this_thread::get_id();
std::atomic<uint32_t> _audio_thread_override = 0;
std::atomic<uint32_t> _main_thread_override = 0;

AudioSetup _audioSetup;
};
} // namespace Clap
Loading

0 comments on commit 3074ce0

Please sign in to comment.