Forums > Java

Calling/placing abstractions in my Patcher via JAVA give error ….

May 28, 2012 | 4:28 pm


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 ??


May 28, 2012 | 4:32 pm

okay.
Nick answered here: http://cycling74.com/forums/topic.php?id=23901 (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 http://cycling74.com/forums/topic.php?id=40213)


May 28, 2012 | 4:32 pm

okay.
Nick answered here: http://cycling74.com/forums/topic.php?id=23901 (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 http://cycling74.com/forums/topic.php?id=40213)


May 28, 2012 | 5:49 pm

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.


May 28, 2012 | 5:49 pm

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.


May 28, 2012 | 5:56 pm

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 :/)


May 28, 2012 | 5:56 pm

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 :/)


May 28, 2012 | 6:30 pm

No, this would be your top-level object. Your abstractions would be contained within this object.


May 28, 2012 | 6:30 pm

No, this would be your top-level object. Your abstractions would be contained within this object.


May 28, 2012 | 6:39 pm

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?


May 28, 2012 | 6:39 pm

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?


May 28, 2012 | 7:20 pm

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.


May 28, 2012 | 7:20 pm

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.


May 28, 2012 | 7:31 pm

I got it.
But basically, how to initialize and call my abstractions from JAVA without creating a new MaxObject ?


May 28, 2012 | 7:31 pm

I got it.
But basically, how to initialize and call my abstractions from JAVA without creating a new MaxObject ?


May 28, 2012 | 7:53 pm

Just construct them within the constructor of your top-level MaxObject, or in response to a function call via a Max message.


May 28, 2012 | 7:53 pm

Just construct them within the constructor of your top-level MaxObject, or in response to a function call via a Max message.


May 28, 2012 | 8:07 pm

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 :-/


May 28, 2012 | 8:07 pm

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 :-/


May 28, 2012 | 10:13 pm

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.


May 28, 2012 | 10:13 pm

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.


May 29, 2012 | 7:48 am

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 : http://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


May 29, 2012 | 7:48 am

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 : http://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


May 29, 2012 | 4:35 pm

In that case you want to use the MaxPatcher and MaxBox objects within Java.


May 29, 2012 | 4:35 pm

In that case you want to use the MaxPatcher and MaxBox objects within Java.


May 29, 2012 | 4:50 pm

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)


May 29, 2012 | 4:50 pm

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)


Viewing 27 posts - 1 through 27 (of 27 total)