Skip to content
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
48 changes: 24 additions & 24 deletions include/c74_min_attribute_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace c74::min {

template<typename T, threadsafe threadsafety, template<typename> class limit_type, allow_repetitions repetitions>
template<typename... ARGS>
attribute<T, threadsafety, limit_type, repetitions>::attribute(object_base* an_owner, const std::string a_name, const T a_default_value, ARGS... args)
inline attribute<T, threadsafety, limit_type, repetitions>::attribute(object_base* an_owner, const std::string a_name, const T a_default_value, ARGS... args)
: attribute_base{ *an_owner, a_name } {
m_owner.attributes()[a_name] = this;

Expand Down Expand Up @@ -57,7 +57,7 @@ namespace c74::min {

template<>
template<typename... ARGS>
attribute<time_value>::attribute(object_base* an_owner, const std::string a_name, const time_value a_default_value, ARGS... args)
inline attribute<time_value>::attribute(object_base* an_owner, const std::string a_name, const time_value a_default_value, ARGS... args)
: attribute_base{ *an_owner, a_name }
, m_value{ an_owner, a_name, static_cast<double>(a_default_value) } {
m_owner.attributes()[a_name] = this;
Expand All @@ -76,7 +76,7 @@ namespace c74::min {


template<typename T, threadsafe threadsafety, template<typename> class limit_type, allow_repetitions repetitions>
void attribute<T, threadsafety, limit_type, repetitions>::create(max::t_class* c, const max::method getter, const max::method setter, const bool isjitclass) {
inline void attribute<T, threadsafety, limit_type, repetitions>::create(max::t_class* c, const max::method getter, const max::method setter, const bool isjitclass) {
long attr_flags {};
if (visible() == visibility::hide)
attr_flags |= max::ATTR_SET_OPAQUE_USER;
Expand All @@ -102,7 +102,7 @@ namespace c74::min {


template<>
void attribute<numbers>::create(max::t_class* c, const max::method getter, const max::method setter, bool const isjitclass) {
inline void attribute<numbers>::create(max::t_class* c, const max::method getter, const max::method setter, bool const isjitclass) {
long attr_flags {};
if (visible() == visibility::hide)
attr_flags |= max::ATTR_SET_OPAQUE_USER;
Expand All @@ -126,7 +126,7 @@ namespace c74::min {


template<>
void attribute<ints>::create(max::t_class* c, const max::method getter, const max::method setter, bool const isjitclass) {
inline void attribute<ints>::create(max::t_class* c, const max::method getter, const max::method setter, bool const isjitclass) {
long attr_flags {};
if (visible() == visibility::hide)
attr_flags |= max::ATTR_SET_OPAQUE_USER;
Expand All @@ -151,7 +151,7 @@ namespace c74::min {

// enum classes cannot be converted implicitly to the underlying type, so we do that explicitly here.
template<typename T, threadsafe threadsafety, template<typename> class limit_type, allow_repetitions repetitions, typename enable_if<std::is_enum<T>::value, int>::type = 0>
std::string range_string_item(const attribute<T, threadsafety, limit_type, repetitions>* attr, const T& item) {
inline std::string range_string_item(const attribute<T, threadsafety, limit_type, repetitions>* attr, const T& item) {
const auto i = static_cast<int>(item);

if (attr->get_enum_map().empty())
Expand All @@ -162,7 +162,7 @@ namespace c74::min {

// vectors cannot be passed directly to stringstream
template<typename T, threadsafe threadsafety, template<typename> class limit_type, allow_repetitions repetitions, typename enable_if<std::is_same<T, std::vector<number>>::value, int>::type = 0>
std::string range_string_item(const attribute<T, threadsafety, limit_type, repetitions>* attr, const T& item) {
inline std::string range_string_item(const attribute<T, threadsafety, limit_type, repetitions>* attr, const T& item) {
string str;
for (const auto& i : item) {
str += std::to_string(i);
Expand All @@ -172,7 +172,7 @@ namespace c74::min {

// vectors cannot be passed directly to stringstream
template<typename T, threadsafe threadsafety, template<typename> class limit_type, allow_repetitions repetitions, typename enable_if<std::is_same<T, std::vector<int>>::value, int>::type = 0>
std::string range_string_item(const attribute<T, threadsafety, limit_type, repetitions>* attr, const T& item) {
inline std::string range_string_item(const attribute<T, threadsafety, limit_type, repetitions>* attr, const T& item) {
string str;
for (const auto& i : item) {
str += std::to_string(i);
Expand All @@ -189,13 +189,13 @@ namespace c74::min {
int
>::type = 0
>
T range_string_item(const attribute<T, threadsafety, limit_type, repetitions>* attr, const T& item) {
inline T range_string_item(const attribute<T, threadsafety, limit_type, repetitions>* attr, const T& item) {
return item;
}


template<typename T, threadsafe threadsafety, template<typename> class limit_type, allow_repetitions repetitions>
std::string attribute<T, threadsafety, limit_type, repetitions>::range_string() const {
inline std::string attribute<T, threadsafety, limit_type, repetitions>::range_string() const {
std::stringstream ss;
for (const auto& val : m_range)
ss << "\"" << range_string_item<T, threadsafety, limit_type, repetitions>(this, val) << "\" ";
Expand All @@ -204,7 +204,7 @@ namespace c74::min {


template<>
std::string attribute<numbers>::range_string() const {
inline std::string attribute<numbers>::range_string() const {
if (m_range.empty())
return "";

Expand All @@ -218,7 +218,7 @@ namespace c74::min {


template<>
std::string attribute<ints>::range_string() const {
inline std::string attribute<ints>::range_string() const {
if (m_range.empty())
return "";

Expand All @@ -233,33 +233,33 @@ namespace c74::min {

// enum attrs use the special enum map for range
template<typename T, threadsafe threadsafety, template<typename> class limit_type, allow_repetitions repetitions, typename enable_if<is_enum<T>::value, int>::type = 0>
void range_copy_helper(attribute<T, threadsafety, limit_type, repetitions>* attr) {
inline void range_copy_helper(attribute<T, threadsafety, limit_type, repetitions>* attr) {
for (auto i = 0; i < attr->get_enum_map().size(); ++i)
attr->range_ref().push_back(static_cast<T>(i));
}


// color attrs don't use range
template<typename T, threadsafe threadsafety, template<typename> class limit_type, allow_repetitions repetitions, typename enable_if<is_color<T>::value, int>::type = 0>
void range_copy_helper(attribute<T, threadsafety, limit_type, repetitions>* attr) {}
inline void range_copy_helper(attribute<T, threadsafety, limit_type, repetitions>* attr) {}


// most attrs can just copy range normally
template<typename T, threadsafe threadsafety, template<typename> class limit_type, allow_repetitions repetitions, typename enable_if<!is_enum<T>::value && !is_color<T>::value, int>::type = 0>
void range_copy_helper(attribute<T, threadsafety, limit_type, repetitions>* attr) {
inline void range_copy_helper(attribute<T, threadsafety, limit_type, repetitions>* attr) {
for (const auto& a : attr->get_range_args())
attr->range_ref().push_back(a);
}


template<typename T, threadsafe threadsafety, template<typename> class limit_type, allow_repetitions repetitions>
void attribute<T, threadsafety, limit_type, repetitions>::copy_range() {
inline void attribute<T, threadsafety, limit_type, repetitions>::copy_range() {
range_copy_helper<T, threadsafety, limit_type, repetitions>(this);
};


template<>
void attribute<numbers>::copy_range() {
inline void attribute<numbers>::copy_range() {
if (!m_range.empty()) {
// the range for this type is a low-bound and high-bound applied to all elements in the vector
assert(m_range_args.size() == 2);
Expand All @@ -272,7 +272,7 @@ namespace c74::min {


template<>
void attribute<ints>::copy_range() {
inline void attribute<ints>::copy_range() {
if (!m_range.empty()) {
// the range for this type is a low-bound and high-bound applied to all elements in the vector
assert(m_range_args.size() == 2);
Expand All @@ -285,22 +285,22 @@ namespace c74::min {


template<typename T, threadsafe threadsafety, template<typename> class limit_type, allow_repetitions repetitions>
bool attribute<T, threadsafety, limit_type, repetitions>::compare_to_current_value(const atoms& args) const {
inline bool attribute<T, threadsafety, limit_type, repetitions>::compare_to_current_value(const atoms& args) const {
return (args[0] == m_value);
}

template<>
bool attribute<number>::compare_to_current_value(const atoms& args) const {
inline bool attribute<number>::compare_to_current_value(const atoms& args) const {
return equivalent<number>(args[0], m_value);
}

template<>
bool attribute<symbol>::compare_to_current_value(const atoms& args) const {
inline bool attribute<symbol>::compare_to_current_value(const atoms& args) const {
return (args[0] == m_value);
}

template<>
bool attribute<numbers>::compare_to_current_value(const atoms& args) const {
inline bool attribute<numbers>::compare_to_current_value(const atoms& args) const {
if (args.size() == m_value.size()) {
for (auto i=0; i<m_value.size(); ++i) {
if (!equivalent<double>(args[i], m_value[i]))
Expand All @@ -312,7 +312,7 @@ namespace c74::min {
}

template<>
bool attribute<ints>::compare_to_current_value(const atoms& args) const {
inline bool attribute<ints>::compare_to_current_value(const atoms& args) const {
if (args.size() == m_value.size()) {
for (auto i=0; i<m_value.size(); ++i) {
if (!equivalent<int>(args[i], m_value[i]))
Expand All @@ -324,7 +324,7 @@ namespace c74::min {
}

template<>
bool attribute<ui::color>::compare_to_current_value(const atoms& args) const {
inline bool attribute<ui::color>::compare_to_current_value(const atoms& args) const {
return equivalent<double>(args[0], m_value.red())
&& equivalent<double>(args[1], m_value.green())
&& equivalent<double>(args[2], m_value.blue())
Expand Down
8 changes: 4 additions & 4 deletions include/c74_min_buffer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ namespace c74::min {


template<>
buffer_lock<true>::buffer_lock(buffer_reference& a_buffer_ref)
inline buffer_lock<true>::buffer_lock(buffer_reference& a_buffer_ref)
: m_buffer_ref { a_buffer_ref } {
m_buffer_obj = buffer_ref_getobject(m_buffer_ref.m_instance);
m_tab = buffer_locksamples(m_buffer_obj);
// TODO: handle case where tab is null -- can't throw an exception in audio code...
}

template<>
buffer_lock<false>::buffer_lock(buffer_reference& a_buffer_ref)
inline buffer_lock<false>::buffer_lock(buffer_reference& a_buffer_ref)
: m_buffer_ref { a_buffer_ref } {
max::t_buffer_info info;

Expand All @@ -31,13 +31,13 @@ namespace c74::min {


template<>
buffer_lock<true>::~buffer_lock() {
inline buffer_lock<true>::~buffer_lock() {
if (m_tab)
buffer_unlocksamples(m_buffer_obj);
}

template<>
buffer_lock<false>::~buffer_lock() {
inline buffer_lock<false>::~buffer_lock() {
buffer_edit_end(m_buffer_obj, true);
}

Expand Down
Loading