Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit pattern zero repeats #3603

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SCClassLibrary/Common/Streams/Patterns.sc
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ Pgeom : Pattern { // geometric series
var cur = start.value(inval);
var len = length.value(inval);
var growStr = grow.asStream, growVal;

while { counter < len } {
growVal = growStr.next(inval);
if(growVal.isNil) { ^inval };
Expand Down Expand Up @@ -449,6 +448,7 @@ Pbrown : Pattern {
hiVal = hiStr.next(inval);
stepVal = stepStr.next(inval);
cur = rrand(loVal, hiVal);

if(loVal.isNil or: { hiVal.isNil } or: { stepVal.isNil }) { ^inval };

length.value(inval).do {
Expand Down
2 changes: 2 additions & 0 deletions SCClassLibrary/Common/Streams/Ppar.sc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Pgpar : Ppar {
var lag = 0, clock = thisThread.clock,
groupReleaseTime = inevent[\groupReleaseTime] ? 0.1;

if(repeats <= 0) { ^inevent };

server = inevent[\server] ?? { Server.default };
ingroup = inevent[\group];
ids = { server.nextNodeID } ! this.numberOfGroups;
Expand Down
60 changes: 60 additions & 0 deletions testsuite/classlibrary/TestPattern.sc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,66 @@ TestPattern : UnitTest {

}


test_pattern_zero_length {
var func, patterns;

func = { |pat|
var val = Pseq([pat, 1]).asStream.next(());
this.assert(val == 1,
"% : a pattern of length zero should return nothing but pass control (returned %)".format(pat, val)
)
};
patterns = [
Pfuncn({ 2 }, 0),
Pseries(length:0),
Pgeom(length:0),
Pbrown(length:0),
Pgbrown(length:0),
Pwhite(length:0),
Pmeanrand(length:0),
Plprand(length:0),
Phprand(length:0),
Pexprand(length:0),
Ppoisson(length:0),
Pcauchy(length:0),
Pbeta(length:0),
Pgauss(length:0),
Pprob([1, 2, 3], length:0),
Ptime(repeats:0),
Pkey(repeats:0),
Pseq([20, 30], repeats:0),
Pseg([20, 30], repeats:0),
Pstep([20, 30], repeats:0),
Pser([20, 30], repeats:0),
Pshuf([20, 30], repeats:0),
Prand([20, 30], repeats:0),
Pxrand([20, 30], repeats:0),
Pwrand([20, 30], repeats:0),
Pfsm([20, 30], repeats:0),
Pdfsm([20, 30], repeats:0),
Ptuple([20, 30], repeats:0),
Place([20, 30], repeats:0),
Ppatlace([20, 30], repeats:0),
Pslide([20, 30], repeats:0),
Pindex(repeats:0),
Pevent(Pget(\a, 20, repeats:0), (eventScope: ())),
Pgate(repeats:0),
Pn(repeats:0),
Pdict((a: 20), Pn(\a), repeats:0),
Peventmod({ ~a = ~a + 1 }, (a: 20), repeats:0),
Ppar([Pbind.new], repeats:0),
Pgpar([Pbind.new], repeats:0),
Ptpar([0.0, Pbind.new], repeats:0),
Pfpar([Pbind.new], repeats:0),

];

patterns.do(func)

}


/*
test_storeArgs {
Pattern.allSubclasses.do({ |class|
Expand Down