Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How to run a segment of code uninterrupted

$
0
0

Hello!

I am hooking up my electric piano to processing using The MidiBus library. I'm basically playing around with visualising the notes played in different ways. This often includes adding some sort of object to an array or arraylist and then iterating through the list to call .update() which updates position, size etc for the object and draws it on the canvas.

However I often get the problem of "concurrent modification exception". I do not get this error when I run the code without the pian but just randomly call the note-pressed function. After some googling this leads me to believe that the error stems from me sometimes calling the notePressed() function, which creates a new object and add to the list, right in the middle of the update loop. Hence I am modifying the list whilst I am iterating over it.

So with that long introduction, here is my question:

Is there a way for me to tell processing "Call this function as soon as possible, but wait until next iteration of draw()"?

or alternativley : "Excecute this block of code without any interruption" ?

From my few qourses in Java i vaguely recall this issue beeing about synchronization, am I right?

Appreciate any help! :)


Viewing all articles
Browse latest Browse all 2896

Trending Articles