Skip to content

Commit

Permalink
Volume: use own group with id 2, synth with id 3, update test
Browse files Browse the repository at this point in the history
  • Loading branch information
adcxyz committed May 17, 2024
1 parent 9a5838f commit 44e7382
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions HelpSource/Classes/Volume.schelp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ categories:: Server

description::
Internally used by Server. When volume value != 0 dB or muted, a server's volume object will create a synth for controlling the volume on the main outputs for the number of channels given.
For shared use of this volume synth with remote clients on this server, volume has its own group with fixed nodeID 2, and the synth (when present) uses the fixed nodeID 3.

classmethods::
method:: new
Expand Down
23 changes: 17 additions & 6 deletions SCClassLibrary/Common/Control/Volume.sc
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ Volume {

var <volume = 0.0, <lag = 0.1, <isMuted = false;

var <ampSynth, <numOutputChannels, defName, updateFunc, initFunc;
var <ampSynth, <numOutputChannels, <defName, updateFunc, initFunc;
var <>window;
var <permID, <baseAmpSynth;
var <group, baseAmpSynth;

*new { | server, startBus = 0, numChannels, min = -90, max = 6, persist = false |
^super.newCopyArgs(server ?? { Server.default }, startBus, numChannels, min, max, persist).init;
}

init {
permID = permID ?? { server.nextPermNodeID };
baseAmpSynth = Synth.basicNew('volumeAmpControl2', server, permID);
baseAmpSynth.group = server.defaultGroup;
// group nodeID should always be 2, so multiple clients can use it
group = Group.basicNew(server, server.nextPermNodeID);
defName = (\volumeAmpControl ++ this.numChannels).asSymbol;
// synth nodeID should always be 3, so multiple clients can use it
baseAmpSynth = Synth.basicNew(defName, server, server.nextPermNodeID);
baseAmpSynth.group = group;

// execute immediately if we're already past server tree functions
if(server.serverRunning) {
Expand All @@ -25,6 +28,7 @@ Volume {

initFunc = {
ampSynth = nil;
server.sendMsg(*group.newMsg(RootNode(server), \addToTail));
this.sendSynthDef;

// only create synth now if it won't be created by ServerTree
Expand All @@ -36,6 +40,7 @@ Volume {
ampSynth = nil;
if(persist) { this.updateSynth }
};

ServerTree.add(updateFunc, server);

}
Expand All @@ -44,6 +49,7 @@ Volume {
if (server.hasBooted) {
fork {
numOutputChannels = this.numChannels;
// update defName in case numChannels has changed
defName = (\volumeAmpControl ++ numOutputChannels).asSymbol;
baseAmpSynth.defName = defName;

Expand Down Expand Up @@ -79,10 +85,15 @@ Volume {
// [\volumeAmp, amp, \volumeLag, lag, \bus, startBus])

ampSynth = baseAmpSynth;

server.sendMsg(*group.newMsg(RootNode(server), \addToTail));
server.sendMsg(9, //"s_new"
defName, permID, Node.addActions[\addAfter], ampSynth.group.nodeID,
defName, baseAmpSynth.nodeID,
Node.addActions[\addToTail],
group.nodeID,
*[\volumeAmp, amp, \volumeLag, lag, \bus, startBus]
);

} {
ampSynth.set(\volumeAmp, amp);
}
Expand Down
2 changes: 1 addition & 1 deletion testsuite/classlibrary/TestVolume.sc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TestVolume : UnitTest {

test_booting {
var s = Server(thisMethod.name);
var correctReply = [ '/g_queryTree.reply', 0, 0, 2, 1, 0, 1000, -1, 'volumeAmpControl2' ];
var correctReply = [ '/g_queryTree.reply', 0, 0, 2, 1, 0, 2, 1, 3, -1, 'volumeAmpControl2' ];
var queryReply;
var nodeIDidx = 6;

Expand Down

0 comments on commit 44e7382

Please sign in to comment.