Esempio n. 1
0
def dataflow_safe_append(dataflow, component, params):
    """
    Append component step to dataflow. Dataflow must have at most 1 final node.
    Parameters are filtered according to the component parameters.
    """
    filtered_params = {}
    for name, default, desc in yaafecore.getComponentParameters(component):
        filtered_params[name] = params.get(name, default)
    fNodes = dataflow.finalNodes()
    n = dataflow.createNode(component, filtered_params)
    if len(fNodes) != 1:
        print "WARNING: dataflow has %i final nodes when appending " "component %s !" % (len(fNodes), component)
        return
    dataflow.link(fNodes[0], "", n, "")
Esempio n. 2
0
def dataflow_safe_append(dataflow, component, params):
    """
    Append component step to dataflow. Dataflow must have at most 1 final node.
    Parameters are filtered according to the component parameters.
    """
    filtered_params = {}
    for name, default, desc in yaafecore.getComponentParameters(component):
        filtered_params[name] = params.get(name, default)
    fNodes = dataflow.finalNodes()
    n = dataflow.createNode(component, filtered_params)
    if (len(fNodes) != 1):
        print('WARNING: dataflow has %i final nodes when appending '\
              'component %s !' % (len(fNodes), component))
        return
    dataflow.link(fNodes[0], '', n, '')
Esempio n. 3
0
 def __new__(mcs, name, base, kdict):
     # check class attributes
     if not 'PARAMS' in kdict:
         kdict['PARAMS'] = []
     if not 'TRANSFORM' in kdict:
         kdict['TRANSFORM'] = False
     # load component libraries
     if 'COMPONENT_LIBS' in kdict:
         for lib in kdict['COMPONENT_LIBS']:
             if yaafecore.loadComponentLibrary(lib) != 0:
                 return
     # compute exposed parameters and check components
     exposed_params = []
     components_available = True
     for p in kdict['PARAMS']:
         if not type(p) == tuple or not len(p) in [2, 3]:
             print('ERROR: invalid PARAMS attribute for feature %s !' %
                   name)
             return None
         if len(p) == 3:
             # explicit parameter
             exposed_params.append(p)
         else:
             params = []
             if isinstance(p[0], AudioFeatureFactory):
                 if not AudioFeatureFactory.feature_available(p[0]):
                     components_available = False
                 # import parameters from a feature
                 params = p[0].get_parameters()
             else:
                 # import parameters from a component
                 if yaafecore.isComponentAvailable(p[0]):
                     params = yaafecore.getComponentParameters(p[0])
                 else:
                     components_available = False
             # override defaults
             params = [(key, p[1].get(key, value), desc)
                       for (key, value, desc) in params
                       if p[1].get(key, True)]
             exposed_params.extend(params)
     exposed_params.sort(key=lambda x: x[0])
     kdict['_EXPOSED_PARAM_DESCRIPTORS'] = exposed_params
     kdict['_COMPONENTS_AVAILABLE'] = components_available
     # list all params
     kdict['_ALL_PARAMS'] = [key for (key, default, desc) in exposed_params]
     # create class
     return type.__new__(mcs, name, base, kdict)
Esempio n. 4
0
 def __new__(mcs, name, base, kdict):
     # check class attributes
     if not 'PARAMS' in kdict:
         kdict['PARAMS'] = []
     if not 'TRANSFORM' in kdict:
         kdict['TRANSFORM'] = False
     # load component libraries
     if 'COMPONENT_LIBS' in kdict:
         for lib in kdict['COMPONENT_LIBS']:
             if yaafecore.loadComponentLibrary(lib) != 0:
                 return
     # compute exposed parameters and check components
     exposed_params = []
     components_available = True
     for p in kdict['PARAMS']:
         if not type(p) == tuple or not len(p) in [2, 3]:
             print('ERROR: invalid PARAMS attribute for feature %s !'
                   % name)
             return None
         if len(p) == 3:
             # explicit parameter
             exposed_params.append(p)
         else:
             params = []
             if isinstance(p[0], AudioFeatureFactory):
                 if not AudioFeatureFactory.feature_available(p[0]):
                     components_available = False
                 # import parameters from a feature
                 params = p[0].get_parameters()
             else:
                 # import parameters from a component
                 if yaafecore.isComponentAvailable(p[0]):
                     params = yaafecore.getComponentParameters(p[0])
                 else:
                     components_available = False
             # override defaults
             params = [(key, p[1].get(key, value), desc)
                       for (key, value, desc) in params
                       if p[1].get(key, True)]
             exposed_params.extend(params)
     exposed_params.sort(key=lambda x: x[0])
     kdict['_EXPOSED_PARAM_DESCRIPTORS'] = exposed_params
     kdict['_COMPONENTS_AVAILABLE'] = components_available
     # list all params
     kdict['_ALL_PARAMS'] = [key for (key, default, desc) in exposed_params]
     # create class
     return type.__new__(mcs, name, base, kdict)