Open Ignotus-mago opened 1 month ago
I've been handling concurrency so far with Timer objects:
case 'c':
isAutoShift = !isAutoShift;
if (isAutoShift) {
shiftTimer = new java.util.Timer();
shiftTimer.schedule(
new java.util.TimerTask() {
public void run() {
runShiftTracker();
}
},
32, shiftInterval
);
}
else {
if (shiftTimer != null) {
shiftTimer.cancel();
}
}
println("----->>> autoShift is "+ isAutoShift);
break;
See line 427 in PixelAudio.pde, the application that suggested the name for the PixelAudio library. This anonymous method works fine for simple Timer events.
This is going to be a large issue. I have mostly handled it with
Timer
andTimerTask
for calls that run in comparatively short periods of time.Concurrency became a problem in WaveSynth when opening a JSON file to load new values. The file i/o is handled in its own thread while animation continues, which is desirable in a performance. Once a file is selected, there may be an ArrayIndexOutOfBoundsException -- or maybe not. That seems to happen when the JSON data changes the size of an array precisely in the middle of the animation loop. My solution was to add the keyword
synchronized
so that the loop would complete before any variables were changed:Now I am getting a warning in the console:
2024-08-02 10:49:57.739 java[39825:8591584] +[CATransaction synchronize] called within transaction
A little research reveals this to be a MacOS event from Core Animation. I am not sure is this is a problem or not. For the moment, everything seems to work as desired. Should I be concerned?