deprecate SCViewHolder-layRight
[supercollider.git] / SCClassLibrary / Common / Streams / RandomDistPatterns.sc
blob30de6fa52d41a72a151d3e0f09181cca2545a4ed
1 Plprand : Pwhite {
2         embedInStream { |inval|
3                 var     localLength = length.value(inval),
4                         pat = Pwhite(lo, hi, localLength);
5                 ^min(pat, pat).embedInStream(inval)
6         }
9 Phprand : Pwhite {
10         embedInStream { |inval|
11                 var     localLength = length.value(inval),
12                         pat = Pwhite(lo, hi, localLength);
13                 ^max(pat, pat).embedInStream(inval)
14         }
17 Pmeanrand : Pwhite {
18         embedInStream { |inval|
19                 var     localLength = length.value(inval),
20                         pat = Pwhite(lo, hi, localLength);
21                 ^((pat + pat) * 0.5).embedInStream(inval)
22         }
25 Pbeta : Pattern {
26         var <>lo, <>hi, <>prob1, <>prob2, <>length;
28         *new{ arg lo = 0.0, hi = 1.0, prob1 = 1, prob2 = 1, length = inf;
29                 ^super.newCopyArgs(lo, hi, prob1, prob2, length);
30         }
32         storeArgs { ^[lo, hi, prob1, prob2, length] }
34         embedInStream { arg inval;
35                 var loStr = lo.asStream;
36                 var hiStr = hi.asStream;
37                 var prob1Str = prob1.asStream;
38                 var prob2Str = prob2.asStream;
39                 var loVal, hiVal;
41                 length.value(inval).do({
42                         var sum = 2, temp, rprob1, rprob2;
43                         rprob1 = prob1Str.next(inval);
44                         rprob2 = prob2Str.next(inval);
45                         if(rprob1.isNil or: { rprob2.isNil }) { ^inval };
46                         rprob1 = rprob1.reciprocal;
47                         rprob2 = rprob2.reciprocal;
48                         loVal = loStr.next(inval);
49                         hiVal = hiStr.next(inval);
50                         if(loVal.isNil or: { hiVal.isNil }) { ^inval };
52                         while ({
53                                 temp = 1.0.rand ** rprob1;
54                                 sum = temp + (1.0.rand ** rprob2);
55                                 sum > 1;
56                         });
57                         inval = (((temp/sum) * (hiVal - loVal)) + loVal).yield;
58                 });
59                 ^inval;
60         }
63 Pcauchy : Pattern {
64         var <>mean, <>spread, <>length;
66         *new{arg mean = 0.0, spread = 1.0, length = inf;
67                 ^super.newCopyArgs(mean, spread, length);
68         }
70         storeArgs{ ^[mean, spread, length] }
72         embedInStream { arg inval;
73                 var meanStr = mean.asStream;
74                 var spreadStr = spread.asStream;
75                 var meanVal, spreadVal;
76                 length.value(inval).do({
77                         var ran = 0.5;
78                         meanVal = meanStr.next(inval);
79                         spreadVal = spreadStr.next(inval);
80                         if(meanVal.isNil or: { spreadVal.isNil }) { ^inval };
81                         while({
82                                 ran = 1.0.rand;
83                                 ran == 0.5
84                         });
85                         inval = ((spreadVal * (ran * pi).tan) + meanVal).yield;
86                 });
87                 ^inval;
88         }
91 Pgauss : Pattern {
92         var <>mean, <>dev, <>length;
94         *new{ arg mean = 0.0, dev = 1, length = inf;
95                 ^super.newCopyArgs(mean, dev, length);
96         }
98         storeArgs{ ^[mean, dev, length] }
100         embedInStream{arg inval;
101                 var meanStr = mean.asStream;
102                 var devStr = dev.asStream;
103                 var devVal, meanVal;
104                 length.value(inval).do({
105                         devVal = devStr.next(inval);
106                         meanVal = meanStr.next(inval);
107                         if(meanVal.isNil or: { devVal.isNil }) { ^inval };
108                         inval = ((((-2*log(1.0.rand)).sqrt * sin(2pi.rand)) * devVal) + meanVal).yield;
109                 });
110                 ^inval;
111         }
115 Ppoisson : Pattern {
116         var <>mean, <>length;
117         *new{arg mean = 1, length = inf;
118                 ^super.newCopyArgs(mean, length);
119                 }
120         storeArgs{ ^[mean, length] }
121         embedInStream{ arg inval;
122                 var meanStr = mean.asStream;
123                 length.value(inval).do({
124                         var inc, test, temp, meanVal = meanStr.next(inval);
125                         if(meanVal.isNil) { ^inval };
126                         inc = 0;
127                         test = 1.0.rand;
128                         temp = exp(meanVal.neg);
129                         while({
130                                 test > temp;
131                                 }, {
132                                 inc = inc + 1;
133                                 test = test * 1.0.rand;
134                         });
135                         inval = inc.yield;
136                 });
137                 ^inval;
138         }
141 Pexprand : Pwhite {
142         *new { arg lo=0.0001, hi=1.0, length=inf;
143                 ^super.newCopyArgs(lo, hi, length)
144         }
145         storeArgs { ^[ lo, hi, length ] }
146         embedInStream { arg inval;
147                 var loStr = lo.asStream;
148                 var hiStr = hi.asStream;
149                 var hiVal, loVal;
150                 length.value(inval).do({
151                         hiVal = hiStr.next(inval);
152                         loVal = loStr.next(inval);
153                         if(hiVal.isNil or: { loVal.isNil }) { ^inval };
154                         inval = exprand(loVal, hiVal).yield;
155                 });
156                 ^inval;
157         }