[ann] Max C++ templates updated for Max 5

Jun 3, 2009 at 5:28am

[ann] Max C++ templates updated for Max 5

I’ve just uploaded updates to the MaxC++ templates, now working with the Max 5 SDK (sorry for the delay)

The Max 5 SDK was much easier to write for, and the templates are now quite a bit smaller, which is nice.
Though I may have broken backwards compatibility (again, sorry), and definitely so for the text editor example, as I removed it entirely (I think doesn’t really belong in the template C++ utility anyway)
And there isn’t a visual studio project either (sorry once more)

Same link:

http://www.mat.ucsb.edu/~wakefield/maxcpp.htm

Any ideas, fixes, breakages, etc welcome

#44223
Sep 4, 2009 at 11:29am

Hi,
I’m writing follow this post because I’m trying to compile my own C++ code through XCode (3.1.2) finding an error.

Now trying with the example code I’ve found in this very useful page I found a similar error. I’m not able to understand where is the problem. I’ve not big problem with C++ programming but is the first time for me programming for an External Object, so maybe the solution is very easy. I’m just blind.

Can we try to understand why I’m not able to compile the example code:

The errors are in a snapshot attached in tiff format.

Hope we can understand where is the problem.

#158974
Sep 4, 2009 at 3:43pm

The path to macho-prefix.pch is wrong. You should be able to set this in your target settings somewhere.

Cheers

#158975
Sep 4, 2009 at 5:03pm

Hi,

Those MaxMSP C++ templates should be dropped into the MaxSDK folder, then all the patchs should match up. That is, the ‘maxcpp5′ folder should be at the same level as the ‘c74support’ folder.

If you put them anywhere else, you’ll need to adjust the various include and framework paths etc.

Best

#158976
Sep 7, 2009 at 10:13am

Thank you all. Now is compiling with no errors.

The problem I have now is that also after compiling I can’t find the .mxo. It is not in the build directory (I can see just a link) and is red in XCode project.

Why it happens?

Maybe I need another topic?

Anna

ps. screenshot in attach

#158977
Sep 7, 2009 at 3:36pm

Yes, you should have started a new topic, since this is completely tangential to the original post. But I’m replying to the same thread anyway.

For reasons which I don’t recall at the moment, the XCode template for .mxo’s puts Debug builds into …/xcodebuild/UninstalledProducts/ (relative to the Project directory), rather than …/xcodebuild/Development (where it deposits an Alias to your .mxo).

You have a couple of choices: you can add the UninstalledProducts/ directory to your Max search path (in Max use the File Preferences… dialog from the Options menu); you could move the UninstalledProducts/ directory to inside your existing Max search path (and update all of your .xcodeprojects, obviously a pain to do); or you can double-click on your .mxo (which is equivalent to using the Install… command from Max/MSP’s File menu).

There is another sensible and convenient alternative that Max/MSP unfortunately refuses to support: from Max 2.x up to Max 4.x it was possible to put an Alias to the UninstalledProducts/ directory into the Max search path, and the UninstalledProducts/ directory itself would be included in the search path. No go since Max 5.0. Cycling ’74 has responded inflexibly about this since I lodged one of the first bug reports on the subject 18 months ago. But it couldn’t hurt if more people complained.-

#158978
Sep 7, 2009 at 4:15pm

Hi,

If you’re using the C++ templates, then they are putting the mxo’s two folders up in the directory, and into a folder called sdk-build/. The assumption being that the maxcpp5 folder was placed in the MaxSDK folder at the same level as c74support, examples, etc., thus the products will be in the same place as all the other examples put their products.

If you right-click on the alias which is in the build folder, and select ‘Show Original’, it will show you where it was installed.

As Peter says, it can be a good idea to add this output folder to your Max search path; in this case, the path to /sdk-build folder in the MaxSDK folder (wherever you put that).

But if your products are showing up red in Xcode, it looks they didn’t build…? Wait; it looks on your tiff that the products have a locked symbol on them – is this a permissions issue? Is your SDK in a place where you don’t have permissions to copy?

#158979
Sep 7, 2009 at 4:43pm

Thanks all (and sorry for the outoftopic, but now is long to post everything in another new topic…it will never happen again. I promise).

I’ve found the object in the /sdk-build folder. Seems to be a fake object. And yes, they are RED in Xcode.

I’ve changed directory of the project putting everything in my home (to be sure there are not problem with permissions), but is always the same. It happens using the example maxcpp5. The mxo remains locked.

Thanks for your precious help.

Anna

#158980
Sep 8, 2009 at 2:56am

Yeah… I don’t know how to help you on this. I just checked to be sure there aren’t any hard-coded paths etc. in the projects, but they’re all fine as far as I can tell.

Here’s what I would recommend:

Download the SDK, put it in your user Documents folder.

E.g. Macintosh HD/Users/yourname/Documents/MaxSDK-5.0.6

Download the templates, and put them in the MaxSDK-5.0.6 folder.

So the Xcode project should now be at

Macintosh HD/Users/yourname/Documents/MaxSDK-5.0.6/maxcpp5/src/maxcpp.xcodeproj

The built product should be at

Macintosh HD/Users/yourname/Documents/MaxSDK-5.0.6/sdk-build/example.mxo

That works for me; OS 10.5.8, Xcode 3.1.2.

If you still have locked files, maybe it’s time to do a repair permissions on your disk? Dunno…, sorry

#158981
Sep 10, 2009 at 8:36pm

Graham-

The templates are great, but I can’t figure out setup methods for incoming floats and ints. I’ve tried everything I can think of from C external programming, and none of those are working. A really simple int method would be awesome, if you get a chance. I have a feeling that it will be embarrassingly simple, so I apologize in advance.

Also, once that’s set up, I assume it’s best to determine inlet in the function?

Thanks for your help,
Keith

#158982
Feb 14, 2010 at 5:29pm

keithmanlove said:

The templates are great, but I can’t figure out setup methods for incoming floats and ints.

My C++ skills aren’t great. Could someone confirm that Mr. Wakefield’s templates only support A_NOTHING and A_GIMME methods? No support for A_INT and A_FLOAT, correct?

Thnx, Charles

#158983
Feb 15, 2010 at 8:42pm

Hi

Yes, in the templates only A_NOTHING and A_GIMME methods are supported. You can use A_GIMME to grab int and float values of course!

But, if you really want to use A_FLOAT or A_INT, you would need to add macros to maxcpp.h:

// for A_FLOAT methods (double v):
#define REGISTER_METHOD_FLOAT(CLASS, METHOD)	class_addmethod(	
	(t_class *)CLASS::m_class,								
	(method)CLASS::MaxMethodFloat< &CLASS::METHOD>::call,	
	#METHOD,												
	A_FLOAT,												
	0);	

// for A_INT methods (long v):
#define REGISTER_METHOD_LONG(CLASS, METHOD)	class_addmethod(	
	(t_class *)CLASS::m_class,								
	(method)CLASS::MaxMethodLong< &CLASS::METHOD>::call,	
	#METHOD,												
	A_LONG,												
	0);

And add to the MaxCpp class:

typedef void (T::*maxmethodlong)(long inlet, long v);
	template
	struct MaxMethodLong {
		static void call(T * x, long v) { ((x)->*F)(proxy_getinlet((t_object *)x), v); }
	};

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

Then in your own class, you can add methods like this:

void testfloat(long inlet, double v) {
		outlet_float(m_outlet[0], v);
	}
	void testint(long inlet, long v) {
		outlet_int(m_outlet[0], v);
	}

And register them in main() like this:

REGISTER_METHOD_FLOAT(Example, testfloat);
	REGISTER_METHOD_LONG(Example, testint);

I’ll add this to the next version of the templates – will update it soon.

#158984
Feb 15, 2010 at 11:04pm

Hi Graham-

Thanks so much for this! Your template is really nice, just a thin layer. Took me all of an hour and a half to port a VST to a msp external.

Studying Stroustrup now, and hope to understand templates real soon.

Best wishes, Charles

#158985

You must be logged in to reply to this topic.