I’m not sure we’ll be able to get these callback functions working, but I think we can get pretty god results without them. In your example you are checking to metro for a 1, but it would be better to simply increment a counter, and then check if it has changed. As you have seen, it’s near impossible to check every k-rate cycle because of the different update rates between Processing and Csound. The next best thing is to check if a change has taken place since the last draw. Something like this seems to work fairly well.
instr 1
kCnt init 0
if metro(4)==1 then
chnset kCnt, "counter"
kCnt += 1
endif
endin
And then in Processing do something like this:
import csoundo.*;
Csoundo cs;
int cnt=0;
float x,y,amp;
boolean setup = false;
int counter = 0;
void setup() {
size(400, 400);
//orientation(LANDSCAPE);
background(0);
cs = new Csoundo(this, "Random.csd");
cs.run();
setup = true;
}
void draw() {
if (cs.getChn("counter") != counter)
{
if (cs.getChn("counter") % 2 == 0)
{
fill(255);
ellipse(width/2, height/2, 200, 200);
}
else
background(0);
counter = int(cs.getChn("counter"));
}
}
I’ve attached a zipped example. Random.zip (11.0 KB)
For what it’s worth, I dropped Processing for p5js some time ago. The WASM version of Csound is very usable in p5js. There is an example in the csoundo git repo. It’s already a little dated, but still runs fine. In fact, it’s based on this example, which might actually be a little more up to date in terms of the Csound version it ships with. A sample of pure JS examples can be found here.
Here’s a silly game I wrote with it some time back.