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
      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 ...
    • Apr 07 2014 | 5:07 pm
      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 02 2016 | 6:19 am
      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 | 2:33 pm
      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).
    • May 02 2016 | 3:18 pm
      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 | 3:20 pm
      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.
    • Aug 17 2017 | 1:14 am
      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.