Skip to content

Commit

Permalink
[avnd] Move type_if into libossia, allow UI updates before execution
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Aug 7, 2024
1 parent 1e93659 commit eb6b74d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 59 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/libossia
54 changes: 3 additions & 51 deletions src/plugins/score-plugin-avnd/Crousti/Executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include <score/tools/ThreadPool.hpp>

#include <ossia/detail/type_if.hpp>

#include <QTimer>

#include <avnd/binding/ossia/data_node.hpp>
Expand Down Expand Up @@ -598,56 +600,6 @@ struct ExecutorGuiUpdate
}
};

template <typename T, bool Predicate>
struct type_if;
template <typename T>
struct type_if<T, false>
{
type_if() = default;
type_if(const type_if&) = default;
type_if(type_if&&) = default;
type_if& operator=(const type_if&) = default;
type_if& operator=(type_if&&) = default;

template <typename U>
type_if(U&&)
{
}
template <typename U>
T& operator=(U&& u) noexcept
{
return *this;
}
};

template <typename T>
struct type_if<T, true>
{
[[no_unique_address]] T value;

type_if() = default;
type_if(const type_if&) = default;
type_if(type_if&&) = default;
type_if& operator=(const type_if&) = default;
type_if& operator=(type_if&&) = default;

template <typename U>
type_if(U&& other)
: value{std::forward<U>(other)}
{
}

operator const T&() const noexcept { return value; }
operator T&() noexcept { return value; }
operator T&&() && noexcept { return std::move(value); }

template <typename U>
T& operator=(U&& u) noexcept
{
return value = std::forward<U>(u);
}
};

template <typename Node>
class CustomNodeProcess : public ossia::node_process
{
Expand Down Expand Up @@ -683,7 +635,7 @@ class Executor final
return static_key() == other || Execution::ProcessComponent::base_key_match(other);
}

[[no_unique_address]] type_if<int, is_gpu<Node>> node_id = -1;
[[no_unique_address]] ossia::type_if<int, is_gpu<Node>> node_id = -1;

Executor(ProcessModel<Node>& element, const ::Execution::Context& ctx, QObject* p)
: Execution::ProcessComponent_T<ProcessModel<Node>, ossia::node_process>{
Expand Down
31 changes: 24 additions & 7 deletions src/plugins/score-plugin-avnd/Crousti/ProcessModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

#include <Crousti/Attributes.hpp>
#include <Crousti/Concepts.hpp>
#include <Crousti/MessageBus.hpp>
#include <Crousti/Metadata.hpp>
#include <Crousti/Metadatas.hpp>
#include <Crousti/ProcessModelPortInit.hpp>
#include <Dataflow/Commands/CableHelpers.hpp>

#include <ossia/detail/type_if.hpp>
#include <ossia/detail/typelist.hpp>

#include <boost/pfr.hpp>
Expand Down Expand Up @@ -78,8 +80,8 @@ class ProcessModel final
[[no_unique_address]]
oscr::dynamic_ports_storage<Info> dynamic_ports;

std::conditional_t<oscr::has_dynamic_ports<Info>, Info, char>
object_storage_for_ports_callbacks;
[[no_unique_address]]
ossia::type_if<Info, oscr::has_dynamic_ports<Info>> object_storage_for_ports_callbacks;

ProcessModel(
const TimeVal& duration, const Id<Process::ProcessModel>& id, QObject* parent)
Expand Down Expand Up @@ -180,10 +182,10 @@ class ProcessModel final
|| avnd::dynamic_ports_output_introspection<Info>::size > 0)
{
avnd::control_input_introspection<Info>::for_all_n2(
avnd::get_inputs<Info>(this->object_storage_for_ports_callbacks),
avnd::get_inputs<Info>((Info&)this->object_storage_for_ports_callbacks),
[this]<std::size_t Idx, typename F>(
F& field, auto pred_index, avnd::field_index<Idx>) {
auto& obj = this->object_storage_for_ports_callbacks;
Info& obj = this->object_storage_for_ports_callbacks;
if constexpr(requires { F::on_controller_setup(); })
{
auto controller_inlets = avnd_input_idx_to_model_ports(Idx);
Expand All @@ -205,7 +207,7 @@ class ProcessModel final
connect(
inlet, &Process::ControlInlet::valueChanged,
[this, &field](const ossia::value& val) {
auto& obj = this->object_storage_for_ports_callbacks;
Info& obj = this->object_storage_for_ports_callbacks;
oscr::from_ossia_value(val, field.value);

if_possible(field.update(obj));
Expand All @@ -214,6 +216,21 @@ class ProcessModel final
});
}
});

if constexpr(avnd::has_gui_to_processor_bus<Info>)
{
// FIXME needs to be a list of callbacks?
}

if constexpr(avnd::has_processor_to_gui_bus<Info>)
{
Info& obj = this->object_storage_for_ports_callbacks;

obj.send_message = [this]<typename T>(T&& b) mutable {
if(this->to_ui)
MessageBusSender{this->to_ui}(std::move(b));
};
}
}
}

Expand Down Expand Up @@ -255,7 +272,7 @@ class ProcessModel final

if constexpr(avnd::dynamic_ports_input_introspection<Info>::size > 0)
{
auto& obj = object_storage_for_ports_callbacks;
Info& obj = object_storage_for_ports_callbacks;
avnd::dynamic_ports_input_introspection<Info>::for_all_n2(
avnd::get_inputs(obj),
[&]<std::size_t N>(auto& port, auto pred_idx, avnd::field_index<N> field_idx) {
Expand All @@ -274,7 +291,7 @@ class ProcessModel final

if constexpr(avnd::dynamic_ports_output_introspection<Info>::size > 0)
{
auto& obj = object_storage_for_ports_callbacks;
Info& obj = object_storage_for_ports_callbacks;
avnd::dynamic_ports_output_introspection<Info>::for_all_n2(
avnd::get_outputs(obj),
[&]<std::size_t N>(auto& port, auto pred_idx, avnd::field_index<N> field_idx) {
Expand Down

0 comments on commit eb6b74d

Please sign in to comment.