Exemplo n.º 1
0
def network_from_minidom(networknode):
    if networknode.tagName != "network":
        raise Exception("Cannot create network from node {}".format(
            networknode.tagName))

    # get sample rate
    sr = float(networknode.getAttributeNode('samplerate').value)

    network = Network()
    network.samplerate = sr

    # create nodes
    for filterNode in networknode.childNodes:
        f = filter_from_node(filterNode, sr)
        if f != None:
            network.add_node(f)

    # create connections
    # objects have been created with an additional attribute "imported_inputnames" that will be used now
    for f in network.get_nodes():
        try:
            inputnames = f.imported_inputnames
        except AttributeError:
            continue

        if len(inputnames) == 1:
            inputobject = network.get_node_by_name(inputnames[0])
            if inputobject is not None:
                f.set_input(inputobject)
            else:
                raise Exception("Cannot connect {} with {}".format(
                    f.name, inputnames[0]))

        else:
            for i in inputnames:
                inputobject = network.get_node_by_name(i)
                if inputobject is not None:
                    f.add_input(inputobject)
                else:
                    raise Exception("Cannot connect {} with {}".format(
                        f.name, inputnames[0]))

    return network
Exemplo n.º 2
0
def network_from_minidom(networknode):
    if networknode.tagName != "network":
        raise Exception("Cannot create network from node {}".format(networknode.tagName))
    
    # get sample rate
    sr=float(networknode.getAttributeNode('samplerate').value)
    
    network=Network()
    network.samplerate=sr
    
    # create nodes
    for filterNode in networknode.childNodes:
        f = filter_from_node(filterNode,sr)
        if f != None:
            network.add_node(f)
            
    # create connections
    # objects have been created with an additional attribute "imported_inputnames" that will be used now
    for f in network.get_nodes():
        try:
            inputnames=f.imported_inputnames
        except AttributeError:
            continue
        
        if len(inputnames)==1:
            inputobject=network.get_node_by_name(inputnames[0])
            if inputobject is not None:
                f.set_input(inputobject)
            else:
                raise Exception("Cannot connect {} with {}".format(f.name,inputnames[0]))
            
        else:
            for i in inputnames:
                inputobject=network.get_node_by_name(i)
                if inputobject is not None:
                    f.add_input(inputobject)
                else:
                    raise Exception("Cannot connect {} with {}".format(f.name,inputnames[0]))
    
    return network