Skip to content

Commit

Permalink
start listener when multiple clients expected, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
adcxyz committed Jun 10, 2024
1 parent 205af43 commit fe60bc6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 32 deletions.
72 changes: 40 additions & 32 deletions SCClassLibrary/Common/Control/Volume.sc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Volume {

// only create synth now if it won't be created by ServerTree
if (persist.not) { this.updateSynth };

// only start listener is multiple clients expected
if (server.options.maxLogins > 1) {
this.startListener
}
};
ServerBoot.add(initFunc, server);

Expand All @@ -45,38 +50,41 @@ Volume {

}

makeListener {
listener = OSCFunc({ |msg|
var invol, inlag, ingate, inbus;
#invol, inlag, ingate, inbus = msg.drop(3);

// server.post; msg.round(0.001).postcs;

invol = invol.ampdb;
if (invol.equalWithPrecision(volume).not) {
"sync vol: ".postln;
volume = invol;
this.changed(\amp, volume);
};
if (inlag.equalWithPrecision(lag).not) {
"sync lag:".postln;
lag = inlag;
};
if (ingate <= 0.0) {
"ampSynth ended".postln;
ampSynthRunning = false;
msg.round(0.001).postcs;
volume = invol;
this.changed(\amp, volume);
} {
ampSynthRunning = true;
};
if (inbus != startBus) {
"*** startBus changed!".postln;
startBus = inbus;
};

}, '/volumeUpdate', server.addr).permanent_(true)
startListener {
listener = listener ?? {
OSCFunc({ |msg|
var invol, inlag, ingate, inbus;
#invol, inlag, ingate, inbus = msg.drop(3);

// server.post; msg.round(0.001).postcs;

invol = invol.ampdb;
if (invol.equalWithPrecision(volume).not) {
"sync vol: ".postln;
volume = invol;
this.changed(\amp, volume);
};
if (inlag.equalWithPrecision(lag).not) {
"sync lag:".postln;
lag = inlag;
};
if (ingate <= 0.0) {
"ampSynth ended".postln;
ampSynthRunning = false;
msg.round(0.001).postcs;
volume = invol;
this.changed(\amp, volume);
} {
ampSynthRunning = true;
};
if (inbus != startBus) {
"*** startBus changed!".postln;
startBus = inbus;
};

}, '/volumeUpdate', server.addr).permanent_(true)
};
listener.enable;
}

sendSynthDef {
Expand Down
24 changes: 24 additions & 0 deletions testsuite/classlibrary/TestVolume.sc
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,28 @@ TestVolume : UnitTest {
s.quit.remove;
}

test_remoteSetVolume {
var s = Server(thisMethod.name);

s.options.bindAddress = "0.0.0.0"; // allow connections from any address
s.options.maxLogins = 2; // set to 2 clients

this.bootServer(s);

0.2.wait;
// create ampSynth
s.volume = -3;

0.1.wait;
// send from outside like a remote client
s.sendMsg(15, 3, \volumeAmp, 0.25);

0.1.wait;
this.assertFloatEquals(s.volume.volume, 0.25.ampdb,
"server should update volume level when set from remote client."
);

s.quit.remove;
}

}

0 comments on commit fe60bc6

Please sign in to comment.