-
-
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.
[max] Add support for creating attributes in message processors
- Loading branch information
Showing
24 changed files
with
802 additions
and
239 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#pragma once | ||
#include <halp/controls.hpp> | ||
#include <halp/meta.hpp> | ||
#include <iostream> | ||
|
||
namespace examples::helpers | ||
{ | ||
|
||
/** | ||
*/ | ||
struct Attributes | ||
{ | ||
halp_meta(name, "Attributes") | ||
halp_meta(c_name, "avnd_attributes") | ||
halp_meta(author, "Jean-Michaël Celerier") | ||
halp_meta(category, "Devices") | ||
halp_meta(description, "Test class attribute inputs") | ||
halp_meta(uuid, "8a05bbf1-e8a5-44ec-8f37-b5e1d046bed8") | ||
struct | ||
{ | ||
struct : halp::val_port<"Index", int> { | ||
halp_flag(class_attribute); | ||
|
||
void update(Attributes& a) { | ||
std::cerr << "Index: " << value << std::endl; | ||
} | ||
} device_index; | ||
|
||
struct: halp::val_port<"Serial", std::string> { | ||
halp_flag(class_attribute); | ||
void update(Attributes& a) { | ||
std::cerr << "Serial: " << value << std::endl; | ||
} | ||
} device_serial; | ||
|
||
struct: halp::val_port<"Foo", int> { | ||
void update(Attributes& a) { | ||
std::cerr << "Foo: " << value << std::endl; | ||
} | ||
} foo; | ||
|
||
struct: halp::val_port<"Connected", bool> { | ||
halp_flag(class_attribute); | ||
void update(Attributes& a) { | ||
std::cerr << "Connected: " << value << std::endl; | ||
} | ||
} connected; | ||
|
||
struct: halp::val_port<"Bar", int> { | ||
void update(Attributes& a) { | ||
std::cerr << "Bar: " << value << std::endl; | ||
} | ||
} bar; | ||
} inputs; | ||
|
||
struct | ||
{ | ||
} outputs; | ||
|
||
void operator()() | ||
{ | ||
|
||
} | ||
}; | ||
|
||
} |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#include <string> | ||
#include <variant> | ||
#include <vector> | ||
#include <map> | ||
|
||
namespace examples | ||
{ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#pragma once | ||
|
||
#include <avnd/concepts/parameter.hpp> | ||
|
||
#include <ext.h> | ||
#include <string_view> | ||
|
||
namespace max | ||
{ | ||
|
||
template<typename> | ||
inline t_symbol* get_atoms_sym() noexcept | ||
{ | ||
return USESYM(atom); | ||
} | ||
template<std::integral> | ||
inline t_symbol* get_atoms_sym() noexcept | ||
{ | ||
return USESYM(long); | ||
} | ||
template<> | ||
inline t_symbol* get_atoms_sym<bool>() noexcept | ||
{ | ||
return USESYM(long); | ||
} | ||
template<> | ||
inline t_symbol* get_atoms_sym<float>() noexcept | ||
{ | ||
return USESYM(float32); | ||
} | ||
template<> | ||
inline t_symbol* get_atoms_sym<double>() noexcept | ||
{ | ||
return USESYM(float64); | ||
} | ||
template<> | ||
inline t_symbol* get_atoms_sym<char>() noexcept | ||
{ | ||
return USESYM(char); | ||
} | ||
template<> | ||
inline t_symbol* get_atoms_sym<std::string_view>() noexcept | ||
{ | ||
return USESYM(symbol); | ||
} | ||
template<> | ||
inline t_symbol* get_atoms_sym<std::string>() noexcept | ||
{ | ||
return USESYM(symbol); | ||
} | ||
|
||
|
||
template<typename F> | ||
constexpr const char* get_atoms_style() noexcept | ||
{ | ||
using V = decltype(F::value); | ||
if constexpr(std::is_same_v<V, bool>) | ||
return "onoff"; | ||
if constexpr(std::is_enum_v<V>) | ||
return "enumindex"; | ||
if constexpr(std::is_same_v<V, std::string>) | ||
return "text"; | ||
if constexpr(std::is_arithmetic_v<V>) | ||
return ""; | ||
if constexpr(avnd::rgb_value<V>) | ||
return "rgba"; | ||
|
||
// TODO: | ||
// "enum" | ||
// "rect" | ||
// "font" | ||
// "file" | ||
return ""; | ||
} | ||
} |
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,88 @@ | ||
#pragma once | ||
#include <avnd/binding/max/atom_helpers.hpp> | ||
#include <avnd/binding/max/from_atoms.hpp> | ||
#include <avnd/binding/max/to_atoms.hpp> | ||
#include <avnd/introspection/input.hpp> | ||
#include <avnd/introspection/range.hpp> | ||
#include <avnd/concepts/all.hpp> | ||
#include <avnd/concepts/field_names.hpp> | ||
#include <avnd/common/aggregates.hpp> | ||
#include <avnd/common/for_nth.hpp> | ||
#include <avnd/wrappers/metadatas.hpp> | ||
#include <ext.h> | ||
|
||
namespace max | ||
{ | ||
template <typename Processor, typename T> | ||
struct attribute_register | ||
{ | ||
t_class* c{}; | ||
|
||
template<std::size_t I> | ||
static t_max_err getter(Processor* x, void*, long* ac, t_atom** av) | ||
{ | ||
auto& ins = avnd::get_inputs(x->implementation.effect); | ||
auto& field = avnd::input_introspection<T>::template field<I>(ins); | ||
|
||
return to_atoms{ac, av}(field.value); | ||
} | ||
|
||
template<std::size_t I> | ||
static t_max_err setter(Processor *x, void *attr, long ac, t_atom *av) | ||
{ | ||
if (ac && av) { | ||
auto& obj = x->implementation.effect; | ||
auto& ins = avnd::get_inputs(obj); | ||
auto& field = avnd::input_introspection<T>::template field<I>(ins); | ||
|
||
if(from_atoms{ac, av}(field.value)) | ||
{ | ||
if constexpr(requires { field.update(obj); }) | ||
{ | ||
field.update(obj); | ||
} | ||
} | ||
} | ||
return MAX_ERR_NONE; | ||
}; | ||
|
||
template<std::size_t I, typename F> | ||
void operator()(avnd::field_reflection<I, F>) { | ||
using V = decltype(F::value); | ||
static constexpr auto name = avnd::get_name<F>(); | ||
|
||
t_symbol* sym = get_atoms_sym<V>(); | ||
if(sym) | ||
{ | ||
static constexpr auto get = &attribute_register::getter<I>; | ||
static constexpr auto set = &attribute_register::setter<I>; | ||
auto attr = attribute_new(name.data(), sym, 0, (method)get, (method)set); | ||
class_addattr(c, attr); | ||
CLASS_ATTR_LABEL(c, name.data(), 0, name.data()); | ||
|
||
if(static constexpr auto style = get_atoms_style<F>(); strlen(style) > 0) | ||
CLASS_ATTR_STYLE(c, name.data(), 0, style); | ||
|
||
if constexpr(avnd::parameter_with_minmax_range<V>) | ||
{ | ||
static constexpr auto range = avnd::get_range<V>(); | ||
CLASS_ATTR_FILTER_CLIP(c, name.data(), range.min, range.max); | ||
const auto init = std::to_string(range.init); | ||
CLASS_ATTR_DEFAULT(c, name.data(), 0, init.c_str()); | ||
} | ||
|
||
// TODO: | ||
// CLASS_ATTR_SAVE(c, attrname, flags) < saved by the patcher | ||
// CLASS_ATTR_SELFSAVE(c, attrname, flags) < saved in its own way | ||
// CLASS_ATTR_ENUM(c, attrname, flags, parsestr) < parsestr == "v1 v2 v3" | ||
// CLASS_ATTR_ENUMINDEX(c, attrname, flags, parsestr) | ||
// CLASS_ATTR_CATEGORY(c, attrname, flags, parsestr) | ||
// CLASS_ATTR_BASIC(c, attrname, flags) | ||
// CLASS_ATTR_OBSOLETE(c, attrname, flags) | ||
// CLASS_ATTR_INTRODUCED(c, attrname, flags, versionstr) | ||
// CLASS_ATTR_INVISIBLE(c,attrname,flags) | ||
} | ||
} | ||
}; | ||
|
||
} |
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.