Can't figure out where and how to make a new Thread for my object.
I've made a quite CPU expensive object in which I would to make a new Thread to make things a little bit lighter for Max. I tried copying some things from the tutorials in to It would be nice if somebody my object but I couldn't manage to get it working.
It would be nice if somebody could take a look at my code:
import com.cycling74.max.*;
import java.util.*;
public class ynsDataSampling extends MaxObject implements Executable {
private boolean isRecording = false;
private List storage = new ArrayList();
private double time = -1;
private double lastTime = 0;
private MaxClock clock;
private int curPbIndex = 0;
public ynsDataSampling() {
declareIO(2,1);
}
public void record(boolean b) {
isRecording = b;
if (b) {
stop();
storage.clear();
time = -1;
} else {
double currentTime = MaxClock.getTime();
lastTime = currentTime - time;
}
}
public void list(Atom[] value) {
if (getInlet() == 1 && isRecording) {
double currentTime = MaxClock.getTime();
double delta;
if (time == -1) {
delta = 0;
} else {
delta = currentTime - time;
}
storage.add(new ListWrapper(value, delta));
time = currentTime;
}
}
public void start() {
if (isRecording) {
record(false);
}
curPbIndex = 0;
clock = new MaxClock(this);
clock.delay(0);
}
public void execute() {
try {
outlet(0, storage.get(curPbIndex).dataList);
if (curPbIndex < (storage.size() - 1)) {
clock.delay(storage.get(curPbIndex + 1).deltaTime);
curPbIndex++;
} else {
curPbIndex = 0;
clock.delay(lastTime);
}
} catch (IndexOutOfBoundsException c) {
}
}
public void stop() {
if (clock!= null) {
clock.unset();
clock = null;
}
curPbIndex = 0;
}
public void deltalist() {
double[] deltaList = new double[storage.size()];
for(int i=0; i
deltaList[i] = storage.get(i).deltaTime;
}
outlet(1, deltaList);
}
}
class ListWrapper {
public Atom[] dataList;
public double deltaTime;
public ListWrapper(Atom[] dL, double dT) {
dataList = dL;
deltaTime = dT;
}
}