Processing and Supercollider

Hi everyone, I’m still going crazy with some sc stuff. I’m communicating via osc from processing to sc, telling me to execute a routine (with an audio file inside) when I move to the left with the mouse in the processing project but I would like this routine to stop when I go to the right side of the screen. the code seems correct (both in processing and in sc), but I don’t understand how to stop this routine. I can possibly attach the codes.

When starting the routine, retain it in a variable, e.g. r = Routine { ... your stuff... }.play;. I’d recommend creating a new routine at this point, not reusing an old one.

Then, when crossing to the other side, do r.stop.

hjh

ok but what do I put in the new routine? if then in any case when I recall it it is still r? I can send you the code, so maybe we can understand each other better. in the meantime, thanks

In general, it’s better to share a code snippet of what you’re trying to do. Otherwise it’s too vague.

hjh

This is Supercollider code.


// BUFFER && SOUNDFILE
(
Buffer.freeAll;
~paths = ("sss".resolveRelative ++ "/*.wav").pathMatch;
~bufs = ~paths.collect{arg i; Buffer.read(s,i)};
)


// TEST SOUND
~bufs[0].play;
~bufs[1].play;
~bufs[2].play;
~bufs[3].play;
~bufs[4].play;
~bufs[5].play;
~bufs[6].play;


// SYNTHDEF

(
SynthDef(\riv, {arg busIn=7,mix=0.5,room=0.5,damp=0.5;
                var in, rev;
                    in  = In.ar(busIn, 2);
                    rev = FreeVerb2.ar(in[0],in[1],mix,room,damp);
                Out.ar(0,rev)
}).add;
SynthDef(\sound, {arg buf=0,pos=0,dur=0.2,amp=0,dir=1,pan=0,trsp=1,t_gate=0;
                 var sig,env;
                     sig = PlayBuf.ar(1, buf,
                                      BufRateScale.kr(buf)*trsp.midiratio * dir, t_gate,
                                      BufSampleRate.kr(buf)* pos,1);
                     env = Env.linen(0.01,dur-0.02,0.01);
                     env = EnvGen.kr(env,t_gate,doneAction:0);
                     sig = Pan2.ar(sig*env*amp,pan);
                 Out.ar(7,sig)
}).add;
)


// SYNTH

(
Synth(\riv,[\mix,0,\room,0,\damp,0]);
Synth(\sound,[\buf,~bufs[4],\pos,0, \dur,~bufs[0].duration,\amp,0.2,\pan,1,\t_gate,0]);
)



// OSC
c = NetAddr("127.0.0.1",  12000);



// routine with osc

(
Synth(\riv,[\mix,0,\room,0,\damp,0]);
Synth(\sound,[\buf,~bufs[0],\pos,0, \dur,~bufs[0].duration,\amp,0,\pan,1,\t_gate,0]);


OSCdef(\oscR1, {arg msg;         // Riceve il Trigger da Processing
                     msg.postln;

	if(msg.at(1) == 1, {~strada.reset.play})
	},'/strada',
                 recvPort:57120);

OSCdef(\oscR11, {arg msg;         // Riceve il Trigger da Processing
                     msg.postln;

	if(msg.at(1) == 1, {~strada.play})
	},'/stopstrada',
                 recvPort:57120);

~strada = Routine.new({ 1.do
	 ({

Synth(\sound,[\buf,~bufs[0],
     	      \pos,0,
		      \dur,~bufs[0].duration,
		      \amp,0.5,
		      \pan,0,
		      \t_gate,1]);
	0.wait;

})
});
)

there’isnt .play beacuse it started by mouse in processing.

This is a part o processing code that active the routine:

if (mouseX < 800 && pmouseX >= 800) {
                       
                          OscMessage start = new OscMessage("/strada");
                          start.add(1);
                          locale.send(start, remoto);

                      } else if (mouseX > 1000 && pmouseX <= 1000) {

                          OscMessage start = new OscMessage("/lavori"); // lavori is another routine for the 
 
// other which activates when the mouse is on the other side of the screen

                          start.add(1);
                          locale.send(start, remoto);
                      }                           
                      
                      if (mouseX > 1000 && pmouseX <= 1000) {
                        
                       OscMessage start = new OscMessage("/stopstrada"); // code that should stop the "road" //                     routine
                          start.add(1);
                          locale.send(start, remoto);
                      
                      }