Skip to content

Commit

Permalink
Temp work
Browse files Browse the repository at this point in the history
  • Loading branch information
abique committed Nov 23, 2024
1 parent a8dc8aa commit ac14c26
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
6 changes: 4 additions & 2 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ add_library(
value-types/enumerated-value-type.cc
)
target_compile_definitions(clap-plugins-core PUBLIC _USE_MATH_DEFINES)
target_compile_options(clap-plugins-core PUBLIC -fno-exceptions)
set_target_properties(clap-plugins-core PROPERTIES CXX_STANDARD 20)
set_target_properties(clap-plugins-core PROPERTIES POSITION_INDEPENDENT_CODE TRUE)

Expand All @@ -107,7 +108,8 @@ target_link_libraries(clap-plugins-core PUBLIC clap-helpers)
set(clap_plugins_src clap-entry.cc)

if (CMAKE_SYSTEM_PROCESSOR MATCHES wasm)
add_executable(clap-plugins ${clap_plugins_src})
add_executable(clap-plugins ${clap_plugins_src}) # cxx-except-workaround.cc)
target_link_options(clap-plugins PRIVATE -Wl,--export=clap_entry -Wl,--export-table)
else()
add_library(clap-plugins MODULE ${clap_plugins_src})
endif()
Expand Down Expand Up @@ -159,4 +161,4 @@ if (${CLAP_BUILD_TESTS})
else()
message(STATUS "Catch2 >= 3 isn't found -> disable clap-plugins unit tests")
endif()
endif()
endif()
9 changes: 7 additions & 2 deletions plugins/audio-buffer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdexcept>

#include <clap/clap.h>
#include <clap/helpers/macros.hh>

#include "constants.hh"

Expand All @@ -24,23 +25,27 @@ namespace clap {
: _channelCount(channelCount), _frameCount(frameCount), _sampleRate(sampleRate) {

if (_channelCount > MAX_AUDIO_CHANNELS)
#ifdef __cpp_exceptions
throw std::invalid_argument("too many audio channels");
#else
std::terminate();
#endif

const size_t dataSize = channelCount * frameCount * sizeof(T);
const size_t dataBaseSize = alignment + dataSize;
size_t dataSizeLeft = dataBaseSize;
_dataBase = std::malloc(alignment + dataSize);

if (!_dataBase) [[unlikely]]
throw std::bad_alloc();
CLAP_HELPERS_THROW(std::bad_alloc());

// std::align modifies the input buffer argument if it succeeds which means
// when alloc was unaligned the free in the dtor would fail as mis-aligned.
// So take a copy and keep the _dataBase pointer around.
auto tmp = _dataBase;
_data = static_cast<T*>(std::align(alignment, dataSize, tmp, dataSizeLeft));
if (!_data)
throw std::bad_alloc();
CLAP_HELPERS_THROW(std::bad_alloc());

setConstantValue(0);
}
Expand Down
8 changes: 8 additions & 0 deletions plugins/core-plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,27 @@ namespace clap {
bool CorePlugin::audioPortsSetConfig(clap_id config_id) noexcept { return false; }

bool CorePlugin::stateSave(const clap_ostream *stream) noexcept {
#ifdef __cpp_exceptions
try {
#endif
ClapOStream os(stream);
yas::binary_oarchive ar(os);
ar & _parameters;

std::vector<uint8_t> extra = stateSaveExtra();
ar & extra;
#ifdef __cpp_exceptions
} catch (...) {
return false;
}
#endif
return true;
}

bool CorePlugin::stateLoad(const clap_istream *stream) noexcept {
#ifdef __cpp_exceptions
try {
#endif
#ifdef _MSC_VER
std::string data;
if (!clap::readAll(stream, data))
Expand All @@ -146,9 +152,11 @@ namespace clap {
ar & extra;
if (!stateLoadExtra(extra))
return false;
#ifdef __cpp_exceptions
} catch (...) {
return false;
}
#endif

#ifndef CLAP_PLUGINS_HEADLESS
if (_guiHandle)
Expand Down
1 change: 1 addition & 0 deletions plugins/core-plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <memory>
#include <optional>
#include <iostream>

#include <yas/binary_iarchive.hpp>
#include <yas/binary_oarchive.hpp>
Expand Down
14 changes: 14 additions & 0 deletions plugins/cxx-except-workaround.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <exception>
#include <clap/clap.h>

CLAP_EXPORT
void __cxa_throw()
{
std::terminate();
}

CLAP_EXPORT
void __cxa_allocate_exception()
{
std::terminate();
}
2 changes: 1 addition & 1 deletion plugins/parameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace clap {
auto ptr = p.get();
auto ret = _id2param.insert_or_assign(info.id, p.get());
if (!ret.second)
throw std::logic_error("same parameter id was inserted twice");
CLAP_HELPERS_THROW(std::logic_error("same parameter id was inserted twice"));
_params.emplace_back(std::move(p));
return ptr;
}
Expand Down

0 comments on commit ac14c26

Please sign in to comment.