-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeRandomEnvValidation.scd
More file actions
56 lines (51 loc) · 1.22 KB
/
Copy pathmakeRandomEnvValidation.scd
File metadata and controls
56 lines (51 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
~validateRandomEnvConstraints = { |
duration,
minLevel,
maxLevel,
minSegments,
maxSegments,
minSegmentDuration,
startLevel,
endLevel,
maxLevelChange
|
if(
duration.isNil
or: { minLevel.isNil }
or: { maxLevel.isNil }
or: { minSegments.isNil }
or: { maxSegments.isNil },
{
Error("Duration, level, and segment ranges are required").throw;
}
);
if(
(duration <= 0)
or: { maxLevel < minLevel }
or: { minSegments < 1 }
or: { maxSegments < minSegments }
or: { minSegmentDuration <= 0 },
{
Error("Invalid random envelope constraints").throw;
}
);
if(
(minSegments * minSegmentDuration) > duration,
{
Error(
"Duration cannot accommodate the minimum segments"
).throw;
}
);
if(maxLevelChange.notNil and: { maxLevelChange < 0 }, {
Error("maxLevelChange cannot be negative").throw;
});
};
~randomEnvLevelBetween = { |lo, hi|
if(lo > hi, {
Error(
"The endpoint and interior level constraints cannot be connected"
).throw;
});
rrand(lo, hi)
};