OSCdefs triggering twice per message?


#1

Hi all, I’m using OSCdefs to trigger different functions based on incoming messages from another process.

The problem is, the OSCdefs are executed twice per incoming message, resulting in some memory leaks due to the same synth being instantiated twice, under the same name, almost simultaneously.

To make things worse, this only happens sometimes. :disappointed:

Below is the console output with OSC tracing enabled. Debug messages starting with OSC- are printed when the respective OSCdef gets called, and right before calling the actual function, while the rest are printed when the function finishes evaluating (which is asynchronous for functions like loadSynthBuffers or setSynthOrder).

DEBUG: OSC-setSession done, t = 62768.9605786
DEBUG: setSession: FiniteMode done, t = 62768.9605786
DEBUG: OSC-setSession done, t = 62768.9605786
DEBUG: setSession: FiniteMode done, t = 62768.9605786
OSC Message Received:
    time: 62768.9605786
    address: a NetAddr(127.0.0.1, 65411)
    recvPort: 57121
    msg: [ /TimeLines/setSession, FiniteMode, s1_fm ]
 
DEBUG: OSC-setWindowDur done, t = 62768.9605786
DEBUG: setWindowDur done, t = 62768.9605786
DEBUG: OSC-setWindowDur done, t = 62768.9605786
DEBUG: setWindowDur done, t = 62768.9605786
OSC Message Received:
    time: 62768.9605786
    address: a NetAddr(127.0.0.1, 65411)
    recvPort: 57121
    msg: [ /TimeLines/setWindowDur, 1.0 ]
 
DEBUG: OSC-loadSynthBuffers done, t = 62768.9806922
DEBUG: OSC-loadSynthBuffers done, t = 62768.9806922
OSC Message Received:
    time: 62768.9806922
    address: a NetAddr(127.0.0.1, 65411)
    recvPort: 57121
    msg: [ /TimeLines/loadSynthBuffers, C:\Users\Carl\AppData\Local\Temp\TimeLines\buffers\s1_fm_amp.w64, C:\Users\Carl\AppData\Local\Temp\TimeLines\buffers\s1_fm_freq.w64, C:\Users\Carl\AppData\Local\Temp\TimeLines\buffers\s1_fm_ratio.w64, C:\Users\Carl\AppData\Local\Temp\TimeLines\buffers\s1_fm_index.w64, C:\Users\Carl\AppData\Local\Temp\TimeLines\buffers\s1_fm_pan.w64 ]
 
DEBUG: OSC-setSynthOrder done, t = 62768.9842005
DEBUG: OSC-setSynthOrder done, t = 62768.9842005
OSC Message Received:
    time: 62768.9842005
    address: a NetAddr(127.0.0.1, 65411)
    recvPort: 57121
    msg: [ /TimeLines/setSynthOrder ]
 
DEBUG: OSC-setPatches done, t = 62768.9842005
DEBUG: OSC-setPatches done, t = 62768.9842005
OSC Message Received:
    time: 62768.9842005
    address: a NetAddr(127.0.0.1, 65411)
    recvPort: 57121
    msg: [ /TimeLines/setPatches ]
 
DEBUG: OSC-setMute done, t = 62768.9842005
DEBUG: setMute: 0 done, t = 62768.9842005
DEBUG: OSC-setMute done, t = 62768.9842005
DEBUG: setMute: 0 done, t = 62768.9842005
OSC Message Received:
    time: 62768.9842005
    address: a NetAddr(127.0.0.1, 65411)
    recvPort: 57121
    msg: [ /TimeLines/setMute, 0 ]
 
DEBUG: loadSynthBuffers (s1_fm), added buffer amp done, t = 62769.0009476
DEBUG: loadSynthBuffers (s1_fm), added buffer freq done, t = 62769.0009476
DEBUG: loadSynthBuffers (s1_fm), added buffer ratio done, t = 62769.0009476
DEBUG: loadSynthBuffers (s1_fm), added buffer index done, t = 62769.0009476
DEBUG: loadSynthBuffers (s1_fm), added buffer pan done, t = 62769.0009476
DEBUG: loadSynthBuffers (s1_fm), added buffer amp done, t = 62769.0044526
DEBUG: loadSynthBuffers (s1_fm), added buffer freq done, t = 62769.0044526
DEBUG: loadSynthBuffers (s1_fm), added buffer ratio done, t = 62769.0044526
DEBUG: loadSynthBuffers (s1_fm), added buffer index done, t = 62769.0044526
DEBUG: loadSynthBuffers (s1_fm), added buffer pan done, t = 62769.0044526
DEBUG: loadSynthBuffers, server sync done, t = 62769.0044526
DEBUG: loadSynthBuffers, server sync done, t = 62769.0044526
DEBUG: setSynthOrder done, t = 62769.0044526
DEBUG: setSynthOrder done, t = 62769.0044526
DEBUG: setPatches done, t = 62769.0044526
DEBUG: setPatches done, t = 62769.0044526
DEBUG: loadSynthBuffers done, t = 62769.030667
DEBUG: loadSynthBuffers done, t = 62769.030667
DEBUG: freeOldBuffers done, t = 62769.1406032

As you can see, for every OSC message received there are two executions of the OSCdef, which results in loadSynthBuffers loading the buffers and creating the synth twice.

Immediately after doing this I restarted the server and tried it again, and this time they executed only once. Here is the relevant SC code, if that helps.

What can be causing this?


#2

Maybe you sometimes have two OSCdefs active at the same time?

Perhaps try to clear and remove your OSCdefs at the start of your program with

OSCdef.freeAll

#3

If I recall correctly, OSCdefs are not automatically removed if you just stop your program with ctrl-.


#4

Thanks for the suggestion, I tried it but it didn’t solve the problem.

I thought the whole point of a -def was to only have one under each name, so whenever I change and re-evaluate an OSCdef or SynthDef it just updates the old one, instead of making a second one with the same name.

Either way, it seems that there’s something wrong with the way incomming messages are being handled. I keep restarting the server and trying again, and it (apparently) randomly either works or doesn’t, without me changing any code.


#5

You should not .add the OSCdefs.

Simply declare them: OSCdef(\name, { ... }, ...); and done.

o = OSCFunc({ |msg| msg.postln }, '/hi');  // <<-- no '.add'
NetAddr.localAddr.sendMsg("/hi", 0);

-> a NetAddr(127.0.0.1, 57120)
[ /hi, 0 ]  <<-- yep, there's the response, no problem

.add is for the old OSCresponder classes. You don’t need it anymore.

hjh


#6

They are removed, unless you .fix them.

hjh


#7

Thanks, that did the trick!