hey there, i have a program which is designed to run at a low frame rate(2fps) but i also want to be able to update the frame in between the draw loop running(via event driven).
Is there a way to update the frame from outside the draw method without calling the draw method?
- import arb.soundcipher.*;
int rows;
int columns;
int[] pitches = {71,70,69,67,65,64,62,60};
float[] playing = {0};
note[][] notes;
int beatcounter;
int tracklength;
int playercounter;
SoundCipher[] players;
void setup(){
rows = pitches.length;
columns = 29;
playercounter = 0;
players = new SoundCipher[4];
for(int x = 0;x<4;x+=1){
players[x] = new SoundCipher();
}
beatcounter = 0;
notes= new note[columns][rows];
size(columns * 20, rows * 20);
for(int y = 0; y < rows; y += 1){
for(int x = 0; x<columns; x+= 1){
notes[x][y] = new note(x * 20, y * 20, pitches[y]);
notes[x][y].display(false);
}
}
frameRate(2);
}
void draw(){
for(int x = 0;x < rows; x+= 1){
notes[beatcounter][x].play();
notes[beatcounter][x].display(true);
if(beatcounter==0){
notes[columns-1][x].display(false);
}
else{
notes[beatcounter-1][x].display(false);
}
}
if(beatcounter == columns-1){
beatcounter = 0;
}
else{
beatcounter += 1;
}
if(playercounter==3){
playercounter = 0;
}
else{
playercounter += 1;
}
if(playing[0] != 0){
players[playercounter].playChord(playing,100,1);
}
for(int x = playing.length;x>1;x-=1){
playing = shorten(playing);
}
playing[0] = 0;
}
void mousePressed(){
for(int x = 0; x<columns; x +=1){
if(mouseX>notes[x][1].x && mouseX<(notes[x][1].x + 20)){
for(int y = 0; y < rows; y+=1){
if(mouseY>notes[x][y].y && mouseY<(notes[x][y].y+20)){
notes[x][y].toggle();
}
}
}
}
}
class note{
int x;
int y;
int pitch;
boolean on;
note(int tx,int ty,int tpitch){
x = tx;
y = ty;
pitch = tpitch;
on = false;
}
void play(){
if(on){
if (playing[0] == 0){
playing[0] = pitch;
}
else{
playing = (float[])append(playing, pitch);
}
}
}
void toggle(){
if(on){
on = false;
stroke(50);
fill(80);
rect(x,y,20,20);
}
else{
on = true;
stroke(100);
fill(150);
rect(x,y,20,20);
}
}
void display(boolean playing){
if(playing){
if(on){
fill(255);
stroke(0);
rect(x,y,20,20);
}
else{
fill(50);
stroke(255);
rect(x,y,20,20);
}
}
else{
if(!on){
stroke(50);
fill(80);
rect(x,y,20,20);
}
else{
stroke(100);
fill(150);
rect(x,y,20,20);
}
}
}
}
here's my code, the boxes drawn in toggle() don't appear until the next frame, up to half a second later, which can be confusing if you're trying to rapidly change things.
1