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

Julien Bayle's icon

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 ?

Julien Bayle's icon

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

Julien Bayle's icon

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

sysex's icon

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

Julien Bayle's icon
sysex's icon

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.

Julien Bayle's icon

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.

sysex's icon

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

Julien Bayle's icon

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

JavaProgrammer & Jesse gave a lot of ideas there