OMDE

OMDE signals

In OMDE OMDE signals come in two flavors: function (subclasses of Function) and generators (subclasses of Generator). The concept of FunctionModel may also make your life easier sometimes.

Functions

Functions derive from the Function class in the omde.functional module and are function of time. Thus they can be evaluated at a specific instant t0 by calling them. For example if f is an instance of some kind of Function, then you could write

        value = f(t0)
	

A well behavied function should always return the same value when evaluated a the same time, but there is no way for OMDE to enforce this condition and there could be case where this statement is not true.

Note

Functions are the most similar concept to Cmask's generators and to early versions of pmask's generators.

Generators

Generators derive from the Generator class in the omde.functional module. They just return a new value each time they are called. For example if g is an instance of some kind of Function, then you could write.

        value = g()
	

There is not explicit time dependence here and a generator (for example a pseudo random number generator) is free to return whatever result at each call.

Function models

Function models are subclasses of FunctionModel and can be regarded as functions «out of time». They store a function shape but not the time interval within it developts. They are very similar to Csound function tables read by an oscillator.

If m is a function model you can get a real function (an instance) in the [t0, t1] time range by using the instance() method.

          f = m.instance(t0, t1)
        

Each Function is also a FunctionModel and return itself when instanced.

Converting between generators and functions

Of course you can convert back and forth between generators and functions but most of the time this kind of conversion is performed automatically behind the scene (see below).

Converting a generator into a function

Converting a generator into a function is done by using a TimeDependenceAdaptor object from the omde.functional module. If g is a generator you could write something like this:

            f = TimeDependenceAdaptor(g)
	  

Now f can be evaluated as a function of time even if it is not:

            value = f(t0)
	  

Anyway you should be aware that f still behaves like a generator: if g is, say, a RNG evaluating twice the f at the same time is likely to return two different values!

Converting a function to a generator

Converting a function into a generator is done by using a Freezer object from the omde.functional module. If f is a function and t is a generator that returns real numbers representing points in the time axis, you could write something like this:

            g = Freezer(f, t)
	  

Now g can called as generator to get the next value:

            value = g()
	  

As a special case t could be a real number and in this case the function would be evaluated always at the same time. The default value for the t argument in Freezer is zero.

Automatic conversion

There are a pair of functions from the omde.functional module that help you to be sure of the kind of signal you are handling. They are used by the omde.pmask algorithms and make life easier to both algorithm developer and user.

Making a function out of almost anything

If you have a not well defined object and you want to turn it into a function you could use the make_function() function from the omde.functional module.

The syntax is as follows:

            make_function(object, begin = None, end = None)
          

If object is a function, make_function() returns object.

If object is a Generator make_function() performs adaptation and return the resulting Function.

If object is a FunctionModel it is instanced and make_function() returns the resulting function. But if both begin and end are None, make_function() expects only ready-to-use generators and not models.

Everything else is turned into a ConstantFunction.

Making a generator out of almost anything

If you have a not well defined object and you want to turn it into a generator you could use the make_generator() function from the omde.functional module.

The syntax is as follows:

            make_generator(object [, t0=0.0])
          

If object is a Generator make_generator() returns object.

A Function be converted to a Generator by freezing it at t0 (default value for t0 is 0.0).

Everything else is turned into a ConstantGenerator.