Skip to content

Commit

Permalink
max: pd: fix that both message and audio processor factories were ins…
Browse files Browse the repository at this point in the history
…tantiated when only one is needed

This caused build errors due to some objects being rightfully incompatible with
either backend.
To solve this, we defer instantation of the type inside a templated lambda, so that
the `if constexpr` branch actually behaves with the expected template semantics,
with the unused branch not being seen by template instantiation, unlike the previous case
in a non-template function causing all branches to be instantiated even if optimized-out afterwards.
  • Loading branch information
jcelerier committed Dec 23, 2024
1 parent c36a2a7 commit bf4c802
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
23 changes: 13 additions & 10 deletions include/avnd/binding/max/prototype.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ extern "C" AVND_EXPORTED_SYMBOL void ext_main(void* r)
common_symbols_init();

using type = decltype(avnd::configure<max::config, @AVND_MAIN_CLASS@>())::type;
if constexpr(avnd::monophonic_audio_processor<type> || avnd::polyphonic_audio_processor<type>)
{
// If we're an audio effect, make a type with the whole DSP stuff
static const max::audio_processor_metaclass< type > instance{};
}
else
{
// Simpler case which just processes messages
static const max::message_processor_metaclass< type > instance{};
}
[]<typename T = type> {
if constexpr(
avnd::monophonic_audio_processor<T> || avnd::polyphonic_audio_processor<T>)
{
// If we're an audio effect, make a type with the whole DSP stuff
static const max::audio_processor_metaclass<T> instance{};
}
else
{
// Simpler case which just processes messages
static const max::message_processor_metaclass<T> instance{};
}
}();
}

23 changes: 13 additions & 10 deletions include/avnd/binding/pd/prototype.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
extern "C" AVND_EXPORTED_SYMBOL void @AVND_C_NAME@_setup()
{
using type = decltype(avnd::configure<pd::config, @AVND_MAIN_CLASS@>())::type;
if constexpr(avnd::monophonic_audio_processor<type> || avnd::polyphonic_audio_processor<type>)
{
// If we're an audio effect, make a type with the whole DSP stuff
static const pd::audio_processor_metaclass< type > instance{};
}
else
{
// Simpler case which just processes messages
static const pd::message_processor_metaclass< type > instance{};
}
[]<typename T = type> {
if constexpr(
avnd::monophonic_audio_processor<T> || avnd::polyphonic_audio_processor<T>)
{
// If we're an audio effect, make a type with the whole DSP stuff
static const pd::audio_processor_metaclass<T> instance{};
}
else
{
// Simpler case which just processes messages
static const pd::message_processor_metaclass<T> instance{};
}
}();
}

0 comments on commit bf4c802

Please sign in to comment.