[chuck-users] Killing thread from without

Hans Aberg haberg at math.su.se
Thu Apr 23 07:45:54 EDT 2009

On 23 Apr 2009, at 10:46, eduard aylon wrote:

>> Is it possible to kill a thread by saving a reference and calling  
>> exit() (or something) on that reference? Are there any means by  
>> which a created thread can be manipulated from without it by its  
>> reference?
>> On a keyboard, I want a generator to be disconnected first some  
>> time after a key has been released - otherwise the sound will be  
>> truncated. How long depends on the generator, so I want to be able  
>> to set it arbitrarily. Then the problem is when the key is  
>> depressed again before this waiting time for disconnect has  
>> elapsed. One way to fix it is to let the thread check if the key  
>> has been depressed again, say by looking at the key down times, and  
>> if so, just skip the disconnect.
> If I understand this correctly, I would use an envelope for that. So  
> when the key is pressed the envelope fires up, and when the key is  
> released, the oscillator will stop at the end of the envelope's  
> release time.
> You may want to have a look at a chuck template for polyphony I  
> wrote a year ago for a workshop. You'll find it at http://www.lullcec.org/chuck/template_polyphony.ck 
> . At that time it was working, not sure now. Be aware that  
> envelope's release time is set quite long (1::second).

 From what I can see from a quick look at your code, I do the same,  
i.e., setting a time for the generator to decay after the key is  
released. The problem is when a key is released and pressed again  
before the decay time has elapsed. Then, if the key controls the same  
generators, and the disconnect event is not cancelled, the note will  
be cut short.

I could not see how you solved that problem. Do yo create a new  
generator every time the same key is pressed?

I have one generator per key. This roughly corresponds to MIDI  
numbers, because E12 enharmonic equivalence does not apply.

In view of the thread-kill problem, and that I haven't figured out how  
to schedule and cancel future events, I use:
   fun void noteoff(int x, int y, dur t) {
     note_on[x][y] => time t_my;
     1 => s[x][y].noteOff;
     t => now;
     if ((note_on[x][y] == t_my) && s[x][y].isConnectedTo(r))
       s[x][y] =< r;
It simply checks if the key has been pressed again, and then skips the  
disconnect - some other thread will handle that.


More information about the chuck-users mailing list