graham wakefield maxcpp, REGISTER_METHOD issues

julien's icon

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

fedfed12's icon

Hi Julien,

Max Patch
Copy patch and select New From Clipboard in Max.

int and float are types and reserved words.
Replace the

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 ...
https://cycling74.com/forums/jdataview-getcellvalue

Zirafkend's icon

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.

Bertram Dunskus's icon

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.

Graham Wakefield's icon

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()

Bertram Dunskus's icon

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?

Graham Wakefield's icon

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.

dhjdhjdhj's icon

I'm hoping this is the right place for this question. I need to update some old externals and figured I'd try and convert them to use cop but I've run into an issue. There doesn't seem to be a way to register for "anything". I note there is mechanism to support int and float directly but symbols and/or "anything" seem to be missing. I haven't looked at the maxcpp template and perhaps it would be easy to add this but I'm wondering if I missed something.