Declaring Outlets on MXJ externals

lordcacops's icon

Hello,

I can't seem to be able to create new outlets for mxj objects even thought iv'e read and re read the WritingExternalsInJava pdf that's included in the program's documentation. Here's the code:

import java.util.Iterator;

import biogenesis.Gene;
import biogenesis.GeneticCode;
import biogenesis.MainWindow;
import biogenesis.Organism;
import biogenesis.World;

import com.cycling74.max.*;

public class helloWorld extends MaxObject {
    public static MainWindow mw = ClassicSingleton.getInstance();

    public void bang() {

        declareInlets(new int[]{ DataTypes.ALL, DataTypes.ALL});
        declareOutlets(new int[]{ DataTypes.ALL, DataTypes.ALL});

        Organism org;
        GeneticCode gc;
        Gene g;

        World theWorld = mw.getWorld();//yo meti esto.

             //yo cambie esto.
        for (Iterator it = theWorld.getOrganismIterator(); it.hasNext(); ) {
             org = it.next();
             if (org.isAlive()) {
             gc = org.getGeneticCode();
             for (int i=0; i
             g = gc.getGene(i);

             outlet(0, new Atom[]{Atom.newAtom(g.getTheta())});

             }
             }
             }
             }

            }

What could I be doing wrong?

Emmanuel Jourdan's icon

The inlets/outlets need to be declared in the mxj's constructor.

lordcacops's icon

Thanks for the quick answer. Where in the code is the constructor?

Floating Point's icon

I guess that's the problem-- you haven't made a constructor.
You need to make a function (or method) that has the same name as the class (in this case helloWorld, which btw needs to be the same name as the class file.
Inside the constructor put: declareOutlets(new int[]{ DataTypes.ALL, DataTypes.ALL, DataTypes.ALL, DataTypes.ALL, DataTypes.ALL}); etc for as many outlets you need.

the best thing to do is type in an empty object: mxj quickie name_of-the_class_you_want_to_make and then bang it. A window will appear with a template, with the constructor:
`    public whatever_your_exeternal_is_called(Atom[] args)
    {
        declareInlets(new int[]{DataTypes.ALL});
        declareOutlets(new int[]{DataTypes.ALL});

        setInletAssist(INLET_ASSIST);
        setOutletAssist(OUTLET_ASSIST);

    }
best to follow the template in quickie if you don't know java

Emmanuel Jourdan's icon

I would also recommend taking a quick look at the tutorial in java-doc/tutorial/html. The tutorial 4 covers the inlets/outlets thingie.

lordcacops's icon

Thanks for the awesome advice!