Forums > Java

How could I use other classes with my core JAVA mxj ??

May 31, 2012 | 9:11 am

Hi folks,

I have now my pretty mxj instantiated the core of my engine.
It works fine.

I’m using it to keep reference to objects (basically Max abstraction) I’m placing in the patcher.
I’d like to store values for those objects in my JAVA.
So, I prototyped an ugly data model like that:
- MaxBox array containing my … MaxBox objects
- float array for x coordinates
- float array for y
… etc.

the index in the arrayS is a reference to a particular object.
ugly of course, but it has worked fine for me to prototype fast.

now moving to HashMap(s)
I’d like to be able to store my MaxBox objects on one side in an HashMap and, inside another HashMap, the JAVA representation of those objects using a bunch of values like 3 coordinates, 3 angle for orientations, color etc all in the same object sitting in that second HashMap.

Should I use absolutely package imported in my Core ?
How can I make … a package ??
I’m a bit confused by the mxj stuff etc. I mean, I’m using a lot of classes in C, less in JAVA, and here in max … no classes except the core one :)

Anyone ?


May 31, 2012 | 10:03 am

I progressed a bit.

I created a package which is based on one class only at the moment:

package net.julienbayle.myUniverse;

public class myObject {

	public float x,y,z;
	public float pitch;
	public float colorR, colorG, colorB;

	// ----------------------------------------------------------------------------- CONSTRUCTOR
	public myObject() {

	}
}

I’m using eclipse.
I’m compiling the core (the one importing the package), it works.

I’m putting the .class in my Max project folder.
When I’m trying to instantiate, it yells saying it cannot find my package.

That one is now a pretty jar in the same folder AND I changed max.java.config.txt by adding :

max.dynamic.jar.dir /

any ideas ??


May 31, 2012 | 10:18 am

Ok it works.
It was just I didn’t add the root folder of the jar.

I mean.

my package is net.julienbayle.myUniverse.*
the folder structure to the jar is: /some/folder/of/the/disk/net/julienbayle/myUniverse/

I had to put this:

max.dynamic.jar.dir /some/folder/of/the/disk/net

Hope it could help someone else :)


May 31, 2012 | 11:06 am

Hi,

I don’t know what you really want to achieve but why using a Hashmap? You could put the reference to the MaxBox-Instance in myObject as field and store the instances of myObject in something that implements the List Interface, like ArrayList. In case of a HashMap what would be your key (I guess the values will be the myObjects) ?.


May 31, 2012 | 11:08 am

answering there : http://cycling74.com/forums/topic.php?id=40284


May 31, 2012 | 11:15 am

Ok, but what type is your ID? F.i. do you assign unique int ID’s to the max objects? Never mind if you are busy its just interesting how other handle Max to Java persistence etc. as there are too few getters/setters for the objects.


May 31, 2012 | 11:21 am

I just answered you there.
yes I’m busy with this :)
I mean, I’m very interested by other methods and ways.

yes the int is incremented each time.

Basically, I’m creating an object with a light GUI made in Max.
I change properties, etc move it in the 3D space etc.
At creation time, I call an abstraction with the variable i=1 for instance.
I create other objects etc…
and I decide to remove the 1
no problem
I do
no matter if the "slot" 1 is empty (I mean on an accounting point of view because hashmap doesn’t care about order etc)

at the end of my composition session, I save the whole stuff in XML or whatever.
when I reload it, everything is re created with new index without pb.

I prototyped it for a small part, it doesn’t seem to look too bad.


May 31, 2012 | 11:49 am

Ok, than HashMap seems to be a good choice as it assures the ID to be unique. BTW What do you use for the XML JOS? JavaBeans Persistence? You just want to serialize and it’s not needed to edit the XML manually (e.g. text editor)?


May 31, 2012 | 11:53 am

I’m currently (only) doing that for 2 variables dumped in the XML in a very stupid way.
Yes, serialization is the thing I’ll look for in 1 week probably, considering I’m progressing slowly which means correctly for me :)

About serialization, you could be interested by :

http://cycling74.com/forums/topic.php?id=40119

JavaProgrammer & Jesse gave a lot of ideas there


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