Forums > Dev

graham wakefield maxcpp, REGISTER_METHOD issues


Dec 24 2011 | 2:59 pm

Hello,
I’m trying to use the c++ wrapper maxcpp and i have some problem with register methods.
With example.cpp and example~.cpp the only working register method is REGISTER_METHOD(Example, bang);

The other ones (REGISTER_METHOD_FLOAT, REGISTER_METHOD_INT) , don’t do anything at runtime.

In my patch two strange things occurs.
I can’t plug a float or an int on the leftmost inlet.
When i plug a float on the second inlet and change the value i have the following message:
Example~doesn’t understand "float"
(same problem with int and every other messages other than bang)

Any ideas ?

Configuration:
OSX 10.6.7
XCode 3.2.6
MAX/MSP SDK 5.1.7
Last version of maxcpp

Thx
Julien

Apr 02 2012 | 11:09 am

Hi Julien,

int and float are types and reserved words.
Replace the #METHOD in both macros like here below

#define INLET_LONG(CLASS, METHOD) class_addmethod(
(t_class *)CLASS::m_class,
(method)CLASS::InletLong< &CLASS::METHOD>::call,
"int",
A_LONG,
0);
#define INLET_FLOAT(CLASS, METHOD) class_addmethod(
(t_class *)CLASS::m_class,
(method)CLASS::InletFloat< &CLASS::METHOD>::call,
"float",
A_FLOAT,
0);

Functor in maxCppBase are defined like this

typedef void (T::*inletlong)(long inlet, long v);
template struct InletLong {
static void call(T * x, long v) { ((x)->*F)(proxy_getinlet((t_object *)x), v); }
};
typedef void (T::*inletfloat)(long inlet, double v);
template struct InletFloat {
static void call(T * x, double v) { ((x)->*F)(proxy_getinlet((t_object*)x), v); }
};

In your (derived) object, declare your method like in "main":
INLET_FLOAT(fdscales, float_inlet); // float is c++ reserved so REGISTER_METHOD_FLOAT is typed with "float"
INLET_LONG(fdscales, int_inlet); // int is c++ reserved so REGISTER_METHOD_LONG is typed with "int"

Your object method will look like :
void int_inlet(long inlet, long v) {
switch (inlet) {
case 0:
post("inlet 0 %ld",v);
break;
case 1:
break;
post("inlet 1 : %ld",v);
default:
break;
}

}

void float_inlet(long inlet, double v) {
/*
your code
*/
}

The int and float boxes will then be accepted by your object.

I have a ticket open on jdataview, if you can help …
http://cycling74.com/forums/topic.php?id=39039

Apr 07 2014 | 10:07 am

Hi,
I’ve the same problem as Julien. I’m not an expert in C++ template. I think there are Macros to update in the Maxcpp6.h .

Could you update your code to have more explanation ???

I try to archive this.
void testfloatplus2(long inlet, double v) {
outlet_float(m_outlet[0], v+2);
}
should have N+2 as output in the max environment.

May 01 2016 | 11:19 pm

I’ve just spent about a whole day trying to understand and fix the problem. I know this post is originally almost 4 years old, but the problem seems to persist throughout the MaxCpp code in it’s current form as hosted on GitHub. Also, the code that Julien posted above uses slightly different names than the code that I see in MaxCpp6. Is that from a newer version?

Anyway, after reading it for the n-th time, I finally understood the simple changes that I needed to make:

In MaxCpp6.h:
Find the definitions of REGISTER_METHOD_FLOAT and REGISTER_METHOD_LONG
In each definition, replace the word #METHOD with "float" and "long" respectively
Recompile, done.

I now understand what Julien meant, but I couldn’t understand it for a few days.

I will update the code in my GitHub repository and request and pull.

May 02 2016 | 7:33 am

I’ve just checked in a fix for this, which adds the two following macros to support objects receiving plain ints and floats. It’s a little simpler than what fedfed12 posted above (there was no need for separate InletFloat etc. definitions).

REGISTER_INLET_FLOAT()
REGISTER_INLET_LONG()

May 02 2016 | 8:18 am

Graham, thank you for the check-in, I just looked at your updates. It seems to me though that the new #defines are correct, yet they duplicate the changes that were made to the old #defines (e.g. replacing #METHOD with "float"), only the names of the macros are different? Would we need both of them? Am I missing something?

May 02 2016 | 8:20 am

Just that the old ones required additional changes to the headers (struct InletFloat etc.) that didn’t seem necessary. I chose different #define names so that they wouldn’t clash for anyone who already added those.

Viewing 7 posts - 1 through 7 (of 7 total)

Forums > Dev