Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if self.count < self.occurrences:
dev = random.randint(-maxStep, maxStep)
while dev == 0 and not self.allowRepetition:
dev = random.randint(-maxStep, maxStep)
self.index += dev
if self.index < 0:
self.index = -self.index - dev + 1
elif self.index >= self.length:
self.index = self.length - (self.index - self.length) - dev - 1
value = self.values[self.index]
return self._checkValueTypeAndIncrementCount(value)
else:
return None
class EventNoise(EventGenerator):
"""
Return a random value between -1.0 and 1.0.
EventNoise returns a random value between -1.0 and 1.0, based on one of
three common noise generators, white, pink (1/f) and brown (1/f^2).
:Args:
type: int, optional
The type of noise used to generate the random sequence. Available
types are:
0: white noise (default)
1: pink noise
2:brown noise
occurrences: int, optional
if isinstance(arg, PyoObject):
args.append(arg.get(False))
elif isinstance(arg, EventGenerator):
arg.setMaster(self.master)
args.append(arg.next())
else:
args.append(arg)
if self.count < self.occurrences:
value = self.function(*args)
return self._checkValueTypeAndIncrementCount(value)
else:
return None
###################
class EventConditional(EventGenerator):
"""
Executes one generator or the other depending on the result of a condition.
EventConditional takes three values or generators as arguments and if the
value of `condition` is True (anything that python considers True), the
`iftrue` argument is used to produce the value for the event, otherwise
th `iffalse` argument is used.
:Args:
condition: int, PyoObject or EventGenerator
Conditional value. True for everything python considers True.
iftrue: int, PyoObject or EventGenerator
Output value if the condition is True.
iffalse: int, PyoObject or EventGenerator
Output value if the condition is False.
self.c2 = self.c2 * 0.96900 + rnd * 0.1538520;
self.c3 = self.c3 * 0.86650 + rnd * 0.3104856;
self.c4 = self.c4 * 0.55000 + rnd * 0.5329522;
self.c5 = self.c5 * -0.7616 - rnd * 0.0168980;
val = self.c0 + self.c1 + self.c2 + self.c3 + self.c4 + self.c5 + self.c6 + rnd * 0.5362;
self.c6 = rnd * 0.115926
return self._checkValueTypeAndIncrementCount(val * 0.2)
else:
rnd = random.uniform(-0.99, 0.99)
self.y1 = rnd + (self.y1 - rnd) * 0.996;
return self._checkValueTypeAndIncrementCount(self.y1 * 20.0)
else:
return None
###################
class EventCall(EventGenerator):
"""
Calls a function, with any number of arguments, and uses its return value.
EventCall can call any function (built-in, from a module or user-defined)
and use its return as the value for the Events's parameter where it is used.
The function *must* return a single number.
:Args:
function: callable
The function to call, which should return the value to use.
args: int, PyoObject or EventGenerator, optional
Any number of arguments to pass to the function call. If given a
PyoObject or an EventGenerator, these will be resolved for each
event and the result passed, as number, to the function.
occurrences: int, optional
self.generator = None
self.count = 0
def next(self):
if self.generator is not None:
return self._internalGeneratorNextCall()
self.length = len(self.values)
if self.count < self.occurrences:
value = random.choice(self.values)
return self._checkValueTypeAndIncrementCount(value)
else:
return None
class EventDrunk(EventGenerator):
"""
Performs a random walk over a list of values.
A random walk is a stochastic process that consists of a succession of
random steps, within a distance of +/- `maxStep` from the previous state.
:Args:
values: EventScale or list
List of values to read. Values in list can be floats,
PyoObject or other EventGenerator.
maxStep: int, PyoObject or EventGenerator, optional
Determine the larger step the walk can do between two successive
events. A negative 'maxStep' is the same but repetition are not
allowed. Defaults to 2.
occurrences: int, optional
return self._internalGeneratorNextCall()
order = self.getOrderValue()
if order is None:
return None
self.markov.setOrder(order)
if self.count < self.occurrences:
value = self.markov.next()
return self._checkValueTypeAndIncrementCount(value)
else:
return None
###################
class EventChoice(EventGenerator):
"""
Plays values randomly chosen from a list.
:Args:
values: EventScale or list
List of possible values to read. Values in list can be floats,
PyoObject or other EventGenerator.
occurrences: int, optional
Number of values to play. Defaults to inf (infinite).
stopEventsWhenDone: bool, optional
If True, the Events playback will stop if this generator reaches
its end. If False, the Events will ignore this signal and probably
get None as value for the given parameter. It's the user
responsability to handle this case correctly. Defaults to True.
value = self.values[position]
return self._checkValueTypeAndIncrementCount(value)
else:
self.completed += 1
if self.completed >= self.occurrences:
return None
else:
self.count = 0
self.start += step
if self.start < 0:
self.start += self.length
elif self.start >= self.length:
self.start -= self.length
return self.next()
class EventIndex(EventGenerator):
"""
Plays values from a list based on a position index.
:Args:
values: EventScale or list
List of values to read. Values in list can be floats,
PyoObject or other EventGenerator.
index: int, PyoObject or EventGenerator
Position to read in the list, starting at 0.
occurrences: int, optional
Number of values to play. Defaults to inf (infinite).
stopEventsWhenDone: bool, optional
If True, the Events playback will stop if this generator reaches
its end. If False, the Events will ignore this signal and probably
get None as value for the given parameter. It's the user
return self._internalGeneratorNextCall()
self.length = len(self.values)
if self.count < self.length:
value = self.values[self.count]
return self._checkValueTypeAndIncrementCount(value)
else:
self.completed += 1
if self.completed >= self.occurrences:
return None
else:
self.count = 0
return self.next()
class EventSlide(EventGenerator):
"""
Plays overlapping segments from a list of values.
EventSlide will play a segment of length `segment` from startpos,
then another segment with a start position incremented by `step`,
and so on.
:Args:
values: EventScale or list
List of values to read. Values in list can be floats,
PyoObject or other EventGenerator.
segment: int, PyoObject or EventGenerator
Number of values of each segment.
step: int, PyoObject or EventGenerator
How far to step the start of each segment from the previous. A
if self.generator is not None:
return self._internalGeneratorNextCall()
self.length = len(self.values)
index = self.getIndexValue()
if index is None:
return None
if self.count < self.occurrences:
value = self.values[index]
return self._checkValueTypeAndIncrementCount(value)
else:
return None
class EventMarkov(EventGenerator):
"""
Applies a Markov algorithm to a list of values.
A Markov chain is a stochastic model describing a sequence of possible events
in which the probability of each event depends only on the state attained in
the previous events.
:Args:
values: EventScale or list
Original list of values.
order: int, PyoObject or EventGenerator, optional
Order of the Markov chain, between 1 and 10. Determines how many past
values will be used to build the probability table for the next note.
Defaults to 2.
occurrences: int, optional
def next(self):
if self.generator is not None:
return self._internalGeneratorNextCall()
args = []
for arg in self.args:
if isinstance(arg, PyoObject):
args.append(arg.get(False))
elif isinstance(arg, EventGenerator):
arg.setMaster(self.master)
args.append(arg.next())
else:
args.append(arg)
if self.count < self.occurrences:
value = self.function(*args)
return self._checkValueTypeAndIncrementCount(value)
else:
return None