Calling/placing abstractions in my Patcher via JAVA give error ....
import com.cycling74.max.MaxObject;
[...]
ArrayList myObjectsList = new ArrayList();
[...]
myObjectsList.add( new MaxObject("myAbstraction") );
This is basic but I have an error because I'm missing something for sure.
The error is :
com.cycling74.max.MaxObject is abstract; cannot be instantiated
myObjectsList.add( new MaxObject("myAbstraction") );
^
anyone to unstick me ??
okay.
Nick answered here: https://cycling74.com/forums/jython-instantiating-max-class (2 years ago)
So How can I place an abstraction via JAVA ... ?
It is okay with JS but I'd need stuff via JAVA unavailable with JS (afaik) (related to https://cycling74.com/forums/how-to-grab-some-objects-variables-values-from-js)
You create a class which extends MaxObject, as you would with any abstract class.
public class Foo extends MaxObject
{
...
}
This class is the class you call via the mxj object in your patcher.
It means I would have to create one class/mxj per abstraction created ?
this is insane in my case (and it probably means I missed smthg :/)
No, this would be your top-level object. Your abstractions would be contained within this object.
yep I got it.
I would extend MaxObject as you proposed (and as I'm doing) for each abstractions or type of abstractions ?
I mean.
(considering this is not the best solution, probably..)
One abstraction = One type of object = One visuals & sounds object
I need to create sometimes a lot of objects.
How would I apply this to my case?
I don't think you would need to extend MaxObject for each of your abstractions. The class that extends MaxObject can contain any number of Java objects, even ones that wrap around JitterObjects.
The only class that needs to extend MaxObject would be the one that you use to initialize your entire system, via mxj. This object would also be responsible for messaging all of its child object, so you could create a messaging structure with inlets/outlets and functions to do so - this exposes the child objects to messages from the patcher environment.
I got it.
But basically, how to initialize and call my abstractions from JAVA without creating a new MaxObject ?
Just construct them within the constructor of your top-level MaxObject, or in response to a function call via a Max message.
Jesse, I don't know another way to "construct" them than to use :
new MaxObject("myAbstraction")
and this is particularly that one that doesn't work :-/
I got the concept, I guess
But I cannot do that because of the error :-/
Yes, I can see that you're still confused.
MaxObject and MSPObject are an abstract classes that one extends to create Java objects that can live at the level of the patcher, instantiated through MXJ.
The issue appears to be the "abstraction" which still has not been clearly defined. If I understand what you're wanting to do, this abstraction is a Java class that wraps Jitter objects and sound related data.
If this is right you should take a look at the JitterObject class, which could be contained inside your abstractions. JitterObject allows you to instantiate Jitter objects that reside inside your Java code, and not in the patcher.
Hi Jesse.
an abstraction in my case here, wouldn't be JAVA stuff, but a "basic" abstraction as defined in Max patchers (I mean, that one : https://cycling74.com/docs/max6/dynamic/c74_docs.html#abstractions
The idea would be to create abstractions on a side and to call them (I mean, to create them in a patcher) via JAVA.
I have that working with JS but because I'd need to have a powerful communication system between my core (here JS, wanting JAVA) and all the abstractions, I thought about JAVA compiled stuff would be more fast
In that case you want to use the MaxPatcher and MaxBox objects within Java.
just before your answer (I swear I swear)
I did that and indeed, as you wrote, it works fine:
import com.cycling74.max.*;
public class testAbstractionLoad extends MaxObject {
private MaxPatcher _p = null;
testAbstractionLoad() {
_p = this.getParentPatcher();
}
public void buildAbstraction()
{
MaxBox b11 = _p.newDefault(20,20,"myAbstraction",null);
}
}
It means I can begin to build the core that would "dispatch" my abstraction on the go
I'll keep references of all abstractions in nice Java data structures better than array for what I want to do
Indeed, I'll need to add/remove abstraction without to have to make an array with empty slot :p
(maxi thanks Jesse to have taken time to explain me things a lot)