5 a = Volume(s, 0, s.options.numOutputBusChannels);
8 z = {SinOsc.ar(440, 0, 0.1)}.play
25 var startBus, numChans, <min, <max, server, persist, <ampSynth, <>window, <volume, spec;
26 var <lag, sdname, gui = false, <muteamp, cpFun, <isMuted=false;
27 var <synthNumChans; // the actual number of channels, which might be set automatically
30 *new { arg server, startBus = 0, numChans, min = -90, max = 6, persist = false;
31 ^super.newCopyArgs(startBus, numChans, min, max, server, persist).initVolume;
36 server = server ?? {Server.default};
40 sdInitialized = Condition();
41 if (server.serverRunning) {
53 synthNumChans = server.options.numOutputBusChannels;
55 synthNumChans = numChans;
58 sdname = (\volumeAmpControl ++ synthNumChans).asSymbol;
60 sdInitialized = Condition();
63 { arg volumeAmp = 1, volumeLag = 0.1, gate=1, bus;
65 Linen.kr(gate, releaseTime: 0.05, doneAction:2),
66 In.ar(bus, synthNumChans) * Lag.kr(volumeAmp, volumeLag) );
70 server.sync(sdInitialized);
72 ServerTree.add(cpFun = {
75 this.volume_(this.volume)
81 if (server.serverRunning.not) {
82 this.volume_(this.volume)
87 play {arg mute = false;
89 if(server.serverRunning) {
90 ampSynth = Synth.after(server.defaultGroup, sdname,
91 [\volumeAmp, volume.dbamp, \volumeLag, lag, \bus, startBus]);
94 "Volume only works on a running Server. Please boot".warn;
104 numChans { ^numChans ? synthNumChans ? server.options.numOutputBusChannels }
106 if(ampSynth.notNil and: { num != synthNumChans }) {
107 "Change in number of channels will not take effect until volume is reset to 0dB.".warn;
115 this.changed(\mute, true);
116 if (ampSynth.notNil) {
117 ampSynth.set(\volumeAmp, 0);
119 this.playVolume(true)
125 ampSynth.set(\volumeAmp, muteamp.dbamp);
126 this.changed(\mute, false);
127 if (this.muteamp == 0.0) {
132 // sets volume back to 1 - removes the synth
137 // cleaner with MVC - in db
138 volume_ { arg aVolume;
141 if (ampSynth.notNil and: {this.isMuted.not}) {
145 if (server.serverRunning) {
146 this.playVolume(isMuted);
149 volume = volume.clip(min, max);
150 if(isMuted) { muteamp = volume };
151 if(ampSynth.notNil && isMuted.not) { ampSynth.set(\volumeAmp, volume.dbamp) };
152 this.changed(\amp, volume);
155 playVolume { arg muted = false;
156 if (ampSynth.isNil and: {
157 (volume != 0.0) or: {muted} }) {
164 ampSynth.set(\volumeLag, lag);
167 setVolumeRange { arg argMin, argMax;
168 argMin !? { min = argMin };
169 argMax !? { max = argMax };
170 this.changed(\ampRange, min, max);
174 gui { arg window, bounds;
176 ^VolumeGui(this, window, bounds)
186 var window, spec, slider, box, simpleController;
188 *new{|model, win, bounds|
189 ^super.new.model_(model).init(win, bounds)
193 spec = [model.min, model.max, \db].asSpec;
194 bounds = bounds ?? {Rect(100, 100, 80, 330)};
195 window = win ?? {GUI.window.new("Volume", bounds).front};
196 box = GUI.numberBox.new(window, Rect(10, 10, 60, 30))
197 .value_(model.volume) ;
198 slider = GUI.slider.new(window, Rect(10, 40, 60, 280))
199 .value_(spec.unmap(model.volume)) ;
200 slider.action_({ arg item ;
201 model.volume_(spec.map(item.value));
203 box.action_({ arg item ;
204 model.volume_(item.value) ;
207 simpleController.remove;
209 simpleController = SimpleController(model)
210 .put(\amp, {|changer, what, volume|
212 box.value_(volume.round(0.01)) ;
213 slider.value_(spec.unmap(volume)) ;
215 .put(\ampRange, {|changer, what, min, max|
216 spec = [min, max, \db].asSpec.debug;
217 slider.value_(spec.unmap(model.volume)) ;