Skip to content

Commit

Permalink
Merge pull request #4493 from telephon/topic/fix-NodeProxy-freeBus-ti…
Browse files Browse the repository at this point in the history
…ming

Topic/fix node proxy free bus timing
  • Loading branch information
mossheim authored Nov 28, 2019
2 parents 72b7ac6 + 05b51de commit 479a6f1
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 8 deletions.
8 changes: 8 additions & 0 deletions HelpSource/Classes/NodeProxy.schelp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ reset everything to nil, neutralizes rate/numChannels
argument::fadeTime
if a fadeTime is given, first fade out, then clear.

method::schedAfterFade

Calls a function after the fadeTime and server latency have passed. If the proxy specifies a code::quant:: value, the function is evaluated code::fadeTime + latency:: seconds after the next timepoint on the quant grid; otherwise, the fade delay begins immediately.

argument::func
a function to be called at the appropriate time


subsection::Accessing Instance Variables

method::sources
Expand Down
22 changes: 14 additions & 8 deletions SCClassLibrary/JITLib/ProxySpace/NodeProxy.sc
Original file line number Diff line number Diff line change
Expand Up @@ -896,19 +896,25 @@ NodeProxy : BusPlug {
// allocation

freeBus {
var oldBus = bus, c;
var oldBus = bus;
if(oldBus.isNil) { ^this };
if(this.isPlaying) {
c = (clock ? TempoClock.default);
c.sched(server.latency ? 0.01 + quant.nextTimeOnGrid(c) + this.fadeTime, { oldBus.free(true); nil });
CmdPeriod.doOnce { if(oldBus.index.notNil) { oldBus.free(true) } };
} {
oldBus.free(true)
};
this.schedAfterFade({
if(oldBus.index.notNil) { oldBus.free(true) }
});
busArg = bus = nil;
busLoaded = false;
}

schedAfterFade { |func|
var usedClock, time;
if(this.isPlaying, {
usedClock = clock ? TempoClock.default;
time = this.fadeTime + (server.latency ? 0.01) + (quant ? 0).nextTimeOnGrid(usedClock);
usedClock.schedAbs(time, { func.value; func = nil });
CmdPeriod.doOnce { func.value; func = nil };
}, func)
}

reallocBusIfNeeded { // bus is reallocated only if the server was not booted on creation.
if(busLoaded.not and: { bus.notNil }) {
bus.realloc;
Expand Down
17 changes: 17 additions & 0 deletions testsuite/classlibrary/TestNodeProxy.sc
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,21 @@ TestNodeProxy : UnitTest {
this.assertEquals(proxy.isPlaying, false, "Setting the proxy's source should not set isPlaying = true");
}

test_schedAfterFade_notPlaying {
var ok = false;
proxy.fadeTime = 0.1;
proxy.schedAfterFade { ok = true };
this.assert(ok, "if not playing, schedAfterFade should happen immediately");
}

test_schedAfterFade {
var ok = false;
proxy.fadeTime = 0.1;
proxy.source = { Silent.ar };
proxy.schedAfterFade { ok = true };
0.11.wait;
this.assert(ok, "if playing, schedAfterFade should happen right after fadeTime");
}


}
73 changes: 73 additions & 0 deletions testsuite/classlibrary/TestNodeProxy_Server.sc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,79 @@ TestNodeProxy_Server : UnitTest {
this.assertEquals(proxy.numChannels, 8, "When reshaping is expanding, NodeProxy's number of channels should NOT be able to contract");
}

test_schedAfterFade_afterQuant {
var ok = false;
proxy.source = { Silent.ar };
1.wait;
proxy.fadeTime = 0.1;
proxy.clock = TempoClock.new(1);
proxy.quant = [1, 0.5];
0.2.wait;
proxy.schedAfterFade { ok = true };
(proxy.fadeTime + 1.5 + proxy.server.latency - 0.2).wait;
this.assert(ok, "schedAfterFade should happened right after quant and fadeTime");
}

test_schedAfterFade_notBeforeQuant {
var ok = true, earlierThan = 0.01;
proxy.source = { Silent.ar };
proxy.fadeTime = 0.1;
proxy.clock = TempoClock.new(1);
proxy.quant = 1.0;
0.2.wait;
proxy.schedAfterFade { ok = false };
(proxy.fadeTime + proxy.server.latency + 1.0 - 0.2 - earlierThan).wait;
this.assert(ok, "schedAfterFade should not happened before quant and fadeTime");
}

test_schedAfterFade_cmdPeriod {
var ok = false;
proxy.fadeTime = 0.1;
proxy.source = { Silent.ar };
proxy.schedAfterFade { ok = true };
CmdPeriod.run;
this.assert(ok, "scheduled function should be run at CmdPeriod");
}

test_schedAfterFade_cmdPeriod_removed {
var count = 0;
proxy.fadeTime = 0.1;
proxy.source = { Silent.ar };
proxy.schedAfterFade { count = count + 1 };
CmdPeriod.run;
0.11.wait;
this.assertEquals(count, 1, "scheduled function should be run at CmdPeriod, not twice");
}

test_reshaping_freeOldBus_after_fadeTime {
var oldBus;
proxy.reshaping = \expanding;
proxy.source = { Silent.ar.dup(2) };
proxy.fadeTime = 0.1;
oldBus = proxy.bus;
proxy.source = { Silent.ar.dup(3) };
(proxy.fadeTime + server.latency).wait;
this.assert(oldBus.index.isNil,
"When reshaping, the old bus should be free right after fadeTime and server latency"
);
}

test_reshaping_freeOldBus_after_fadeTime_quant {
var oldBus;
proxy.reshaping = \expanding;
proxy.source = { Silent.ar.dup(2) };
proxy.fadeTime = 0.1;
proxy.clock = TempoClock.new(10);
proxy.quant = [1.0, 0.5];
oldBus = proxy.bus;
0.01.wait;
proxy.source = { Silent.ar.dup(3) };
(proxy.fadeTime + server.latency + 0.5).wait;
this.assert(oldBus.index.isNil,
"When reshaping, the old bus should be free right after fadeTime, quant and server latency"
);
}

test_clear_fadeTime {
var clearTime = 0.1;

Expand Down

0 comments on commit 479a6f1

Please sign in to comment.