/usr/lib/python2.7/dist-packages/pyolib/pattern.py is in python-pyo 0.8.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | """
Set of objects that call Python functions from triggers or number counts.
Useful for event sequencing.
"""
from __future__ import absolute_import
"""
Copyright 2009-2015 Olivier Belanger
This file is part of pyo, a python module to help digital signal
processing script creation.
pyo is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
pyo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with pyo. If not, see <http://www.gnu.org/licenses/>.
"""
from ._core import *
from ._maps import *
class Pattern(PyoObject):
"""
Periodically calls a Python function.
The play() method starts the pattern timer and is not called
at the object creation time.
:Parent: :py:class:`PyoObject`
:Args:
function: Python function
Python function to be called periodically.
time: float or PyoObject, optional
Time, in seconds, between each call. Default to 1.
arg: anything, optional
Argument sent to the function's call. If None, the function
will be called without argument. Defaults to None.
.. note::
The out() method is bypassed. Pattern doesn't return signal.
Pattern has no `mul` and `add` attributes.
If `arg` is None, the function must be defined without argument:
>>> def tocall():
>>> # function's body
If `arg` is not None, the function must be defined with one argument:
>>> def tocall(arg):
>>> print(arg)
>>> s = Server().boot()
>>> s.start()
>>> t = HarmTable([1,0,.33,0,.2,0,.143,0,.111])
>>> a = Osc(table=t, freq=[250,251], mul=.2).out()
>>> def pat():
... f = random.randrange(200, 401, 25)
... a.freq = [f, f+1]
>>> p = Pattern(pat, .125)
>>> p.play()
"""
def __init__(self, function, time=1, arg=None):
pyoArgsAssert(self, "cO", function, time)
PyoObject.__init__(self)
self._function = getWeakMethodRef(function)
self._time = time
self._arg = arg
function, time, arg, lmax = convertArgsToLists(function, time, arg)
self._base_objs = [Pattern_base(WeakMethod(wrap(function,i)), wrap(time,i), wrap(arg,i)) for i in range(lmax)]
def setFunction(self, x):
"""
Replace the `function` attribute.
:Args:
x: Python function
new `function` attribute.
"""
pyoArgsAssert(self, "c", x)
self._function = getWeakMethodRef(x)
x, lmax = convertArgsToLists(x)
[obj.setFunction(WeakMethod(wrap(x,i))) for i, obj in enumerate(self._base_objs)]
def setTime(self, x):
"""
Replace the `time` attribute.
:Args:
x: float or PyoObject
New `time` attribute.
"""
pyoArgsAssert(self, "O", x)
self._time = x
x, lmax = convertArgsToLists(x)
[obj.setTime(wrap(x,i)) for i, obj in enumerate(self._base_objs)]
def setArg(self, x):
"""
Replace the `arg` attribute.
:Args:
x: Anything
new `arg` attribute.
"""
self._arg = x
x, lmax = convertArgsToLists(x)
[obj.setArg(wrap(x,i)) for i, obj in enumerate(self._base_objs)]
def out(self, x=0, inc=1, dur=0, delay=0):
return self.play(dur, delay)
def setMul(self, x):
pass
def setAdd(self, x):
pass
def setSub(self, x):
pass
def setDiv(self, x):
pass
def ctrl(self, map_list=None, title=None, wxnoserver=False):
self._map_list = [SLMap(0.125, 4., 'lin', 'time', self._time)]
PyoObject.ctrl(self, map_list, title, wxnoserver)
@property
def function(self):
"""Python function. Function to be called."""
return self._function
@function.setter
def function(self, x):
self.setFunction(x)
@property
def time(self):
"""float or PyoObject. Time, in seconds, between each call."""
return self._time
@time.setter
def time(self, x): self.setTime(x)
@property
def arg(self):
"""Anything. Callable's argument."""
return self._arg
@arg.setter
def arg(self, x):
self.setArg(x)
class Score(PyoObject):
"""
Calls functions by incrementation of a preformatted name.
Score takes audio stream containning integers in input and calls
a function whose name is the concatenation of `fname` and the changing
integer.
Can be used to sequence events, first by creating functions p0, p1,
p2, etc. and then, by passing a counter to a Score object with "p"
as `fname` argument. Functions are called without parameters.
:Parent: :py:class:`PyoObject`
:Args:
input: PyoObject
Audio signal. Must contains integer numbers. Integer must change
before calling its function again.
fname: string, optional
Name of the functions to be called. Defaults to "event_", meaning
that the object will call the function "event_0", "event_1", "event_2",
and so on... Available at initialization time only.
.. note::
The out() method is bypassed. Score's signal can not be sent
to audio outs.
Score has no `mul` and `add` attributes.
.. seealso:: :py:class:`Pattern`, :py:class:`TrigFunc`
>>> s = Server().boot()
>>> s.start()
>>> a = SineLoop(freq=[200,300,400,500], feedback=0.05, mul=.1).out()
>>> def event_0():
... a.freq=[200,300,400,500]
>>> def event_1():
... a.freq=[300,400,450,600]
>>> def event_2():
... a.freq=[150,375,450,525]
>>> m = Metro(1).play()
>>> c = Counter(m, min=0, max=3)
>>> sc = Score(c)
"""
def __init__(self, input, fname="event_"):
pyoArgsAssert(self, "os", input, fname)
PyoObject.__init__(self)
self._input = input
self._fname = fname
self._in_fader = InputFader(input)
in_fader, fname, lmax = convertArgsToLists(self._in_fader, fname)
self._base_objs = [Score_base(wrap(in_fader,i), wrap(fname,i)) for i in range(lmax)]
self.play()
def out(self, chnl=0, inc=1, dur=0, delay=0):
return self.play(dur, delay)
def setMul(self, x):
pass
def setAdd(self, x):
pass
def setInput(self, x, fadetime=0.05):
"""
Replace the `input` attribute.
:Args:
x: PyoObject
New signal to process.
fadetime: float, optional
Crossfade time between old and new input. Defaults to 0.05.
"""
pyoArgsAssert(self, "oN", x, fadetime)
self._input = x
self._in_fader.setInput(x, fadetime)
@property
def input(self):
"""PyoObject. Audio signal sending integer numbers."""
return self._input
@input.setter
def input(self, x):
self.setInput(x)
class CallAfter(PyoObject):
"""
Calls a Python function after a given time.
:Parent: :py:class:`PyoObject`
:Args:
function: Python function
Python callable execute after `time` seconds.
time: float, optional
Time, in seconds, before the call. Default to 1.
arg: any Python object, optional
Argument sent to the called function. Default to None.
.. note::
The out() method is bypassed. CallAfter doesn't return signal.
CallAfter has no `mul` and `add` attributes.
If `arg` is None, the function must be defined without argument:
>>> def tocall():
>>> # function's body
If `arg` is not None, the function must be defined with one argument:
>>> def tocall(arg):
>>> print(arg)
The object is not deleted after the call. The user must delete it himself.
>>> s = Server().boot()
>>> s.start()
>>> # Start an oscillator with a frequency of 250 Hz
>>> syn = SineLoop(freq=[250,251], feedback=.07, mul=.2).out()
>>> def callback(arg):
... # Change the oscillator's frequency to 300 Hz after 2 seconds
... syn.freq = arg
>>> a = CallAfter(callback, 2, [300,301])
"""
def __init__(self, function, time=1, arg=None):
pyoArgsAssert(self, "cn", function, time)
PyoObject.__init__(self)
self._function = getWeakMethodRef(function)
function, time, arg, lmax = convertArgsToLists(function, time, arg)
self._base_objs = [CallAfter_base(WeakMethod(wrap(function,i)), wrap(time,i), wrap(arg,i)) for i in range(lmax)]
self.play()
def out(self, x=0, inc=1, dur=0, delay=0):
return self.play(dur, delay)
def setMul(self, x):
pass
def setAdd(self, x):
pass
def setSub(self, x):
pass
def setDiv(self, x):
pass
|