@@ -390,3 +390,96 @@ def arg(self):
390390 @arg .setter
391391 def arg (self , x ):
392392 self .setArg (x )
393+
394+ class CallAlways (PyoObject ):
395+ """
396+ Calls a Python function every processing frame.
397+
398+ :Parent: :py:class:`PyoObject`
399+
400+ :Args:
401+
402+ function: Python callable (function or method)
403+ Python callable executed every buffer size.
404+ arg: any Python object, optional
405+ Argument sent to the called function. Defaults to None.
406+
407+ .. note::
408+
409+ The out() method is bypassed. CallAlways doesn't return signal.
410+
411+ CallAlways has no `mul` and `add` attributes.
412+
413+ If `arg` is None, the function must be defined without argument:
414+
415+ >>> def tocall():
416+ >>> pass # function's body
417+
418+ If `arg` is not None, the function must be defined with one argument:
419+
420+ >>> def tocall(arg):
421+ >>> print(arg)
422+
423+ >>> s = Server().boot()
424+ >>> s.start()
425+ >>> t = DataTable(size=s.getBufferSize())
426+ >>> n = Noise()
427+ >>> f = TableFill(n, t)
428+ >>> def callback(arg):
429+ ... # Apply a lowpass filter and a gain on the table content
430+ ... t.lowpass(arg)
431+ ... t.mul(0.25)
432+ >>> a = CallAlways(callback, 500)
433+ >>> o = TableScan(t).out()
434+
435+ """
436+
437+ def __init__ (self , function , arg = None ):
438+ pyoArgsAssert (self , "c" , function )
439+ PyoObject .__init__ (self )
440+ self ._function = getWeakMethodRef (function )
441+ self ._arg = arg
442+ function , arg , lmax = convertArgsToLists (function , arg )
443+ self ._base_objs = [
444+ CallAlways_base (WeakMethod (wrap (function , i )), wrap (arg , i ))
445+ for i in range (lmax )
446+ ]
447+ self ._init_play ()
448+
449+ def out (self , x = 0 , inc = 1 , dur = 0 , delay = 0 ):
450+ return self .play (dur , delay )
451+
452+ def setMul (self , x ):
453+ pass
454+
455+ def setAdd (self , x ):
456+ pass
457+
458+ def setSub (self , x ):
459+ pass
460+
461+ def setDiv (self , x ):
462+ pass
463+
464+ def setArg (self , x ):
465+ """
466+ Replace the `arg` attribute.
467+
468+ :Args:
469+
470+ x: Anything
471+ new `arg` attribute.
472+
473+ """
474+ self ._arg = x
475+ x , lmax = convertArgsToLists (x )
476+ [obj .setArg (wrap (x , i )) for i , obj in enumerate (self ._base_objs )]
477+
478+ @property
479+ def arg (self ):
480+ """Anything. Callable's argument."""
481+ return self ._arg
482+
483+ @arg .setter
484+ def arg (self , x ):
485+ self .setArg (x )
0 commit comments