Outlet an array/vector in Java?
Hi This shouldnt be difficult but for some reason I cant find the answer anywhere!
I have a vector full of doubles. How do I outlet it to max?
I've figured out I can do:Object[] arr = vec.toArray();
...which converts the vector to an array. But I still cant convert the array to an Atom for max.
Any ideas?
If you can convert this into an actual double array (i.e. declare as double[] arr, or do conversion as a separate step) then the outlet method of MaxObject should work fine:
outlet(int outletIdx, double[] value)
Maybe something like this?
import com.cycling74.max.*;
import java.util.Random;
public class ListOutput1 extends MaxObject{
int values[]=new int[4];
int count=0;
Random value=new Random();
public ListOutput1(){
declareAttribute("count");
}
public void bang(){
for(int i=0;i
values[i]=value.nextInt(10);
}
outlet(0,values);
}
}
Man java is a pedantic bastard when it comes to data types!
My vector is full of doubles but despite this,Double[] arr = vec.toArray();
Gives an error "incompatible types found".
So if you're saying outlet() can take a double array as a parameter then I just need to figure out how to convert a vector to a double array.
@efe thanks - this looks great but I have a dynamic number of doubles to go into the array. (this is why I'm using vectors). I suppose I could set the for loop counter dynamically when I know how many values will be needed?
Maybe you guys could help me with this function?
private Atom toAtom(Vector v){
Object[] arr = v.toArray();
Atom[] a = new Atom[]{Atom.newAtom(v)};
return(a);
}
I get this compile error:
cannot find symbol symbol : method newAtom(java.util.Vector)
location: class com.cycling74.max.Atom
Or do I need to do it in a for loop like this?
private void toAtom(Vector a){
Atom[] b = new Atom[a.size()];
for(int i=0;i
Error:array required, but java.util.Vector found