gen~ > code export > external

stringtapper's icon

So someone (stkr?) in another thread recently suggested that someone use the code export feature in Gen and create an external. I had to put my noobular foray into external coding on hiatus for a while (working with Eric Lyon's book), but from what I remember Max externals are coded in C and the Gen code export function exports C++.

So how would creating an external from a Gen patch work using code export?

Thanks!

Dave

woyteg's icon

really interesting! is this true about c/c++?
This would be really great, although I'm not sure what the advantages are besides that there is no need to compile the thing on startup.(There are still these issues with having lots of poly~ instances with gen~inside right?)

stringtapper's icon

Well my question indeed was prompted by stkr's comment in a thread about gen~ and poly~.

He makes it sound like making such an external would alleviate such a problem.

Also not sure if there would be any advantages beyond the poly~ issue.

woyteg's icon

Funny, I missed that thread. But indeed, gen export to external sounds great hope somebody will chime in to clear things up and give some hints on how to go about this.

woyteg's icon

https://cycling74.com/wiki/index.php?title=Gen_Code_Export_AU
"Send gen~ the exportcode message in order to export the genpatcher as C++ code."

stringtapper's icon

The crucial question is how to translate the C++ code into C to compile an external.

I'm realizing this might have been better posted in the dev section.

thouldcroft's icon

The Max SDK has an example of an external object built with C++ code, under examples>advanced>collect.

I don't have enough experience with building externals (only did some Max external work a year ago) OR exactly how this external can use C++ code when it was also my understanding that all Max externals needed to be written in C, but this may be a place to start. It would be great to be able to develop MSP~ externals through DSP code created with gen~.

Perhaps someone with a greater amount of experience in external programming could shed some light on this.

do.while's icon

that would be a huge benefit to develop MSP externals through GEN . Setting up the environment for C code compiling is not so straight forward , there are always many problems . now setting editor for max external compiling is just another level .instead i would not mind to be able to create external straight in GEN and save it as external itself . If GEN is compiling itself that should not be a huge work for C'74 guys , or ? ... maybe its a different thing , as for example GEN in poly takes time to load , so it seems like GEN is some sort of addition to MAX itself not a family object code, or it has something to do with JSON as maxpatch interpretation , i dont know . or im totally wrong and that issue is already gone ?
anyway , would be great to know more about it for sure , or shape the idea for the future as a new addition

AudioMatt's icon

Bump! Has anyone created a tutorial to do this? (export msp gen code into an external) It would be much appreciated. Just including exportedcode.cpp into a copy of simplemsp~ yeilds a ton of errors.

AudioMatt's icon

Note:

it would be possible to manually copy the perform routine into a separate c function and have a custom header that only contains the necessary functions. I think the issue is that the included gen_lib doubles some of the stuff in ext.h

Cycling, am I wrong?

Another note:

I actually have only programmed in c (I learned c++ once but forgot) . Would this be a super simple task if I just knew some c++? It seems like the conflicts aren't really about the c++ at all since I tried to rename the external file as a .cpp and call the necessary routines and it still refused to compile.