Code Exported C++ Referencing Max Objects, How To Replace in Code?
Hey All,
If you export some C++ from Gen~, and the Gen referenced an object in your main patch, a Buffer in my case, is it possible to then create code that C++ will be able to recognise as a replacement of this reference? I'd pick apart the Buffer object but it's an executable, and I'd try to include that executable but I thik copyright wouldn't allow this.
Cheers,
Adam
I would like to know this too, but unfortunately the only documents that are updated in gen are those that concern license issues.
You would need to provide your own implementations for the genlib_buffer_* methods, according to what is needed by your application. They are all marked "// to be implemented" in the genlib.cpp file -- that's where you'd create your own implementation.
Alternatively, to avoid touching C++, you might be able to replace the [buffer] objects in your genpatcher with [data] objects. For the most part, if you have e.g. a [buffer foo] that refers to an external [buffer~ foo 500 2], you could replace it with a [data foo 0.5*samplerate 2] with no other changes needed in the genpatcher. If you needed to fill the buffer with specific data, like a wavetable, a common pattern is to use a codebox that runs once, like this:
History init(1);
if (init) {
init = 0; // make sure this only happens once
// for each frame of tbe data:
for (i=0; i<dim(foo); i+=1) {
// compute phase (0..1)
phase = i/dim(foo);
// convert to sine function:
value = sin(phase*twopi);
// channel 0:
poke(foo, value, i, 0);
// channel 1:
poke(foo, value, i, 1);
}
}
Example:
If the user wants to save or upload the content to disk?
Edit or view it?
Data also for some reason is reported as a dummy parameter.
I'm attempting to impliment the Buffer methods Graham suggested, but I'm quite new to C++ so will use Data instead if not. Thanks Guys.
I wonder how likely it is that non-Gen~ Max MSP objects could be used as encapsulated processes for other applications, technically and in terms of copyright. Maybe naive to think this would be possible legally?
@ARABRAB: saving, uploading, editing/viewing etc. are features are external to gen~, and thus external to the code gen~ can generate. They would depend on using facilities available in the host environment, which could be quite different -- different hardware, OS, frameworks, etc. We can only provide the genlib_buffer* stub functions and let users implement them and add support as desired.
I'm not quite sure what you mean by being reported as a dummy parameter.
@ADAMIAM: Yes I imagine using Data is going to be much easier, unless there is a specific buffer~ feature that can't be emulated, such as loading and audio file from disk. Unfortunately this isn't likely to be trivial to implement in C++, but as mentioned above, it depends very much on the host hardware/OS/framework etc., which is too large a combinatoric space for us to be able to provide implementations for.
When the gen~ code uses [data] object, that data then appears (is listed) as a parameter, but "for obvious reasons" can not be altered from outside (void ref), so even if the user does not show it in the "GUI" all hosts show it when they are listed or displayed Parameters with or without gui.
In that case the user has to take care of implementing a method to detect that type of parameter "and not show it", it is also a problem that is added to num_params ().
Helping the user with a generic method, or an example of implementation, not to be forced once again ... to think about copyright and license issues while developing, would have been kind and generous.
Since this type of questions have been repeated several times in the forum ...
It's intentionally left there, as some hosts *may* be able to use the parameter.
In Max, a [data foo] becomes a parameter so that you can send a message such as "foo mybuf" and it will copy the contents of a [buffer~ mybuf] into [data foo].
Other hosts that may use code export could implement a similar behavior, or some other behavior, for [data] parameters -- such as perhaps loading an audio file from disk. In this case the void * ref might be a string containing a file path, and the user implementation would take care of finding & loading the file and copying the content into the Data member variable. This is host dependent however. We can't provide an implementation, as this would depend on external libraries that may not be portable to all of the contexts gen~ code is used in, and makes too strong assumptions about how the host would use it.
If a [data] parameter doesn't make sense for the host you're using, you could remove it from the exported code perhaps?
BTW I have no idea what this has to do with copyright and license issues?
Hi all, would be great to have a tutorial on how to interface gen [data] stuff with audio buffer classes in Juce (or the coming iPlug2 if it will support gen code import). That would be a great advancement!