diff --git a/SCClassLibrary/Common/Control/Volume.sc b/SCClassLibrary/Common/Control/Volume.sc index 6c6c2ed0a5b..da4e53b2878 100644 --- a/SCClassLibrary/Common/Control/Volume.sc +++ b/SCClassLibrary/Common/Control/Volume.sc @@ -6,7 +6,7 @@ Volume { var window; - var 1) { this.startListener } @@ -42,7 +42,7 @@ Volume { ServerBoot.add(initFunc, server); updateFunc = { - ampSynthRunning = false; + ampSynth.isPlaying = false; if(persist) { this.updateSynth } }; @@ -64,12 +64,13 @@ Volume { if (inlag.equalWithPrecision(lag).not) { lag = inlag; }; + // triggers when gate closed, so we know ampSynth ends if (ingate <= 0.0) { - ampSynthRunning = false; + ampSynth.isPlaying = false; volume = invol; this.changed(\amp, volume); } { - ampSynthRunning = true; + ampSynth.isPlaying = true; }; if (inbus != startBus) { startBus = inbus; @@ -109,7 +110,7 @@ Volume { numChannels { ^numChannels ? server.options.numOutputBusChannels } numChannels_ { |num| - if(ampSynthRunning and: { num != this.numChannels }) { + if(ampSynth.isPlaying and: { num != this.numChannels }) { "Change in number of channels will not take effect until volume is reset to 0dB.".warn; }; numChannels = num; @@ -121,7 +122,7 @@ Volume { if(active) { if(server.hasBooted) { - if(ampSynthRunning.not) { + if(ampSynth.isPlaying.not) { // Synth.after(server.defaultGroup, defName, // [\volumeAmp, amp, \volumeLag, lag, \bus, startBus]) @@ -133,15 +134,21 @@ Volume { *[\volumeAmp, amp, \volumeLag, lag, \bus, startBus] ); - ampSynthRunning = true; + // also catches stray endings of ampSynth + ampSynth.onFree { + // "ampSynth was freed".postln; + this.volume = 0; + ampSynth.isPlaying = false; + }; + ampSynth.isPlaying = true; } { ampSynth.set(\volumeAmp, amp); } } } { - if(ampSynthRunning) { + if(ampSynth.isPlaying) { ampSynth.set(\volumeAmp, 1).release; - ampSynthRunning = false + ampSynth.isPlaying = false } } } @@ -164,7 +171,7 @@ Volume { freeSynth { ampSynth.release; - ampSynthRunning = false; + ampSynth.isPlaying = false; } // sets volume back to 1 - removes the synth diff --git a/testsuite/classlibrary/TestVolume.sc b/testsuite/classlibrary/TestVolume.sc index da4b28c3b6a..75041484807 100644 --- a/testsuite/classlibrary/TestVolume.sc +++ b/testsuite/classlibrary/TestVolume.sc @@ -89,4 +89,29 @@ TestVolume : UnitTest { s.quit.remove; } + test_resetVolumeAfterKill { + 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.2.wait; + // kill ampSynth irregularly + s.sendMsg("n_free", s.volume.ampSynth.nodeID); + + 0.2.wait; + this.assertFloatEquals(s.volume.volume, 0, + "server should reset volume level when ampSynth dies irregularly." + ); + + s.quit.remove; + } + + }