-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[concepts] First tentative of implementation of dynamic ports
- Loading branch information
Showing
16 changed files
with
348 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
#include <cmath> | ||
#include <halp/controls.hpp> | ||
#include <halp/meta.hpp> | ||
|
||
#include <functional> | ||
#include <vector> | ||
|
||
/* SPDX-License-Identifier: GPL-3.0-or-later */ | ||
|
||
namespace examples | ||
{ | ||
struct SumPorts | ||
{ | ||
halp_meta(name, "Sum") | ||
halp_meta(c_name, "avnd_sumports") | ||
halp_meta(author, "Jean-Michaël Celerier") | ||
halp_meta(category, "Debug") | ||
halp_meta(description, "Example of an object with dynamic number of inputs") | ||
halp_meta(uuid, "48b57b3e-227a-4a55-adce-86c011dcf491") | ||
|
||
struct inputs | ||
{ | ||
struct : halp::spinbox_i32<"Control", halp::range{0, 10, 0}> | ||
{ | ||
static std::function<void(SumPorts&, int)> on_controller_interaction() | ||
{ | ||
return [](SumPorts& object, int value) { | ||
object.inputs.in.request_port_resize(value); | ||
}; | ||
} | ||
} controller; | ||
|
||
struct : halp::knob_f32<"Input {}"> | ||
{ | ||
std::vector<double> ports{}; | ||
std::function<void(int)> request_port_resize; | ||
} in; | ||
} inputs; | ||
|
||
struct | ||
{ | ||
halp::val_port<"Output", float> out; | ||
} outputs; | ||
|
||
void operator()() | ||
{ | ||
outputs.out.value = 0; | ||
int k = 0; | ||
|
||
for(auto val : inputs.in.ports) | ||
outputs.out.value += std::pow(10, k++) * std::floor(10 * val); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#pragma once | ||
|
||
#include <avnd/common/struct_reflection.hpp> | ||
#include <avnd/concepts/dynamic_ports.hpp> | ||
#include <avnd/introspection/input.hpp> | ||
#include <avnd/introspection/output.hpp> | ||
|
||
namespace oscr | ||
{ | ||
template <typename T> | ||
concept has_dynamic_ports = avnd::dynamic_ports_input_introspection<T>::size > 0 | ||
|| avnd::dynamic_ports_output_introspection<T>::size > 0; | ||
|
||
template <typename Field> | ||
struct dynamic_ports_state_type; | ||
|
||
template <avnd::dynamic_ports_port Field> | ||
struct dynamic_ports_state_type<Field> | ||
{ | ||
int count = 0; | ||
}; | ||
|
||
template <typename T> | ||
struct dynamic_ports_storage | ||
{ | ||
template <std::size_t Idx> | ||
int num_in_ports(avnd::field_index<Idx>) const noexcept | ||
{ | ||
return 1; | ||
} | ||
template <std::size_t Idx> | ||
int num_out_ports(avnd::field_index<Idx>) const noexcept | ||
{ | ||
return 1; | ||
} | ||
}; | ||
|
||
template <typename T> | ||
requires( | ||
avnd::dynamic_ports_input_introspection<T>::size > 0 | ||
|| avnd::dynamic_ports_output_introspection<T>::size > 0) | ||
struct dynamic_ports_storage<T> | ||
{ | ||
using in_tuple = avnd::filter_and_apply< | ||
dynamic_ports_state_type, avnd::dynamic_ports_input_introspection, T>; | ||
using out_tuple = avnd::filter_and_apply< | ||
dynamic_ports_state_type, avnd::dynamic_ports_output_introspection, T>; | ||
|
||
[[no_unique_address]] in_tuple in_handles; | ||
[[no_unique_address]] out_tuple out_handles; | ||
|
||
template <std::size_t Idx> | ||
int num_in_ports(avnd::field_index<Idx> f) const noexcept | ||
{ | ||
static constexpr std::size_t pred_idx | ||
= avnd::dynamic_ports_input_introspection<T>::field_index_to_index(f); | ||
return std::get<pred_idx>(in_handles).count; | ||
} | ||
template <std::size_t Idx> | ||
int num_out_ports(avnd::field_index<Idx> f) const noexcept | ||
{ | ||
static constexpr std::size_t pred_idx | ||
= avnd::dynamic_ports_output_introspection<T>::field_index_to_index(f); | ||
return std::get<pred_idx>(out_handles).count; | ||
} | ||
template <std::size_t Idx> | ||
int& num_in_ports(avnd::field_index<Idx> f) noexcept | ||
{ | ||
static constexpr std::size_t pred_idx | ||
= avnd::dynamic_ports_input_introspection<T>::field_index_to_index(f); | ||
return std::get<pred_idx>(in_handles).count; | ||
} | ||
template <std::size_t Idx> | ||
int& num_out_ports(avnd::field_index<Idx> f) noexcept | ||
{ | ||
static constexpr std::size_t pred_idx | ||
= avnd::dynamic_ports_output_introspection<T>::field_index_to_index(f); | ||
return std::get<pred_idx>(out_handles).count; | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.