Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concepts: play with a visual range concept separate from the mapping … #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion examples/Advanced/Utilities/Gain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ class Gain

struct inputs
{
halp::smooth_knob<"Gain", halp::range{0., 5., 0.}> gain;
struct : halp::smooth_knob<"Gain", halp::range{0., 1., 0.}>
{
struct visual_range
{
double min = 0.;
double max = 5.;
};
} gain;
};
double operator()(double input, const inputs& in) { return input * in.gain; }
};
Expand Down
4 changes: 4 additions & 0 deletions include/avnd/concepts/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ namespace avnd
template <typename C>
concept has_range = requires { C::range(); } || requires { sizeof(C::range); }
|| requires { sizeof(typename C::range); };
template <typename C>
concept has_visual_range = requires { C::visual_range(); } || requires {
sizeof(C::visual_range);
} || requires { sizeof(typename C::visual_range); };
}
26 changes: 26 additions & 0 deletions include/avnd/introspection/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,30 @@ consteval auto get_range(const T&)
{
return get_range<T>();
}

template <avnd::has_visual_range T>
consteval auto get_visual_range()
{
if constexpr(requires { sizeof(typename T::visual_range); })
return typename T::visual_range{};
else if constexpr(requires { T::visual_range(); })
return T::visual_range();
else if constexpr(requires { sizeof(decltype(T::visual_range)); })
return T::visual_range;
else
return get_range<T>();
}

template <avnd::has_range T>
requires(!avnd::has_visual_range<T>)
consteval auto get_visual_range()
{
return get_range<T>();
}

template <typename T>
consteval auto get_visual_range(const T&)
{
return get_visual_range<T>();
}
}
Loading