Essentia  2.1-dev
Network Class Reference

#include <network.h>

Public Member Functions

 Network (streaming::Algorithm *generator, bool takeOwnership=true)
 
 ~Network ()
 
void run ()
 
void runPrepare ()
 
bool runStep ()
 
void update ()
 
void reset ()
 
void clear ()
 
void deleteAlgorithms ()
 
streaming::AlgorithmfindAlgorithm (const std::string &name)
 
NetworkNodevisibleNetworkRoot ()
 
NetworkNodeexecutionNetworkRoot ()
 
const std::vector< streaming::Algorithm * > & linearExecutionOrder () const
 
void printBufferFillState ()
 

Static Public Member Functions

static std::vector< streaming::Algorithm * > innerVisibleAlgorithms (streaming::Algorithm *algo)
 

Static Public Attributes

static NetworklastCreated
 

Protected Member Functions

void buildVisibleNetwork ()
 
void buildExecutionNetwork ()
 
void topologicalSortExecutionNetwork ()
 
void checkConnections ()
 
void checkBufferSizes ()
 
void clearVisibleNetwork ()
 
void clearExecutionNetwork ()
 

Protected Attributes

bool _takeOwnership
 
streaming::Algorithm_generator
 
NetworkNode_visibleNetworkRoot
 
NetworkNode_executionNetworkRoot
 
std::vector< streaming::Algorithm * > _toposortedNetwork
 
AlgoSet _algos
 

Detailed Description

A Network is a structure that holds all algorithms that have been connected together and is able to run them.

It contains 2 networks of algorithms:

  • the visible network, which is the network of algorithms explicitly connected together by the user, which can contain AlgorithmComposites
  • the execution network, where all the AlgorithmComposites have been replaced with their respective constituent algorithms, so that only non-composite algorithms are left.

The main functionality of the Network, once it is built, is to run the generator node at the root of the Network (an audio loader, usually) and carry the data through all the other algorithms automatically.

Constructor & Destructor Documentation

Network ( streaming::Algorithm generator,
bool  takeOwnership = true 
)

Builds an execution Network using the given Algorithm. This will only work if the given algorithm is a generator, ie: it has no input ports.

Parameters
generatorthe root generator node to which all the network is connected
takeOwnershipwhether to take ownership of the algorithms and delete them when this Network object is destroyed
~Network ( )

Member Function Documentation

void buildExecutionNetwork ( )
protected

Build the network execution, ie: the network of single algorithms in the order in which they should be executed. All composite algorithms should have been expanded and the only remaining composites in there should be those that call themselves as part of a declareProcessStep() call in the declareProcessOrder() method.

void buildVisibleNetwork ( )
protected

Build the network of visibly connected algorithms (ie: do not enter composite algorithms) and stores its root in _visibleNetworkRoot.

void checkBufferSizes ( )
protected

Check for all the connections that the source buffer size (phantom size, actually) is at least as big as the preferred size of the connected sink. If not, it automatically resizes the source buffer.

void checkConnections ( )
protected

Check that all the algorithms inputs/outputs are connected somewhere, so as to make sure that no buffer is being filled without anybody to empty it, which would cause the whole network to be blocked. This function returns normally if it didn't find any problems, otherwise it throws an exception.

void clear ( )

Clear the network to an empty state (ie: no algorithms contained in it, delete previous algorithms if Network had ownership of them). This is the recommended way to proceed (do not use deleteAlgorithms() unless you really know what you're doing).

void clearExecutionNetwork ( )
protected

Delete all the NetworkNodes used in the execution network. Do not touch the algorithms pointed to by these nodes.

void clearVisibleNetwork ( )
protected

Delete all the NetworkNodes used in the visible network. Do not touch the algorithms pointed to by these nodes.

void deleteAlgorithms ( )

Delete all the algorithms contained in this network. Be careful as this method will indeed delete all the algorithms in the Network, even if it didn't take ownership over them.

NetworkNode* executionNetworkRoot ( )
inline
streaming::Algorithm* findAlgorithm ( const std::string &  name)

Find and return an algorithm by its name. Throw an exception if no algorithm was found with the given name.

static std::vector<streaming::Algorithm*> innerVisibleAlgorithms ( streaming::Algorithm algo)
static

Helper function that returns the list of visibly connected algorithms starting from the given one, without crossing the borders of a possibly encompassing AlgorithmComposite (ie: all returned algorithms are inside the composite).

const std::vector<streaming::Algorithm*>& linearExecutionOrder ( ) const
inline

Return a list of algorithms which have been topologically sorted. You can assume that each node in there will have either 1 or 0 children.

void printBufferFillState ( )

Prints the fill state of all the buffers in the network.

void reset ( )

Reset all the algorithms contained in this network. (This in effect calls their reset() method)

void run ( )

Executes all the algorithms in the network until all the tokens given by the source generator are processed by all the algorithms.

Internally it just calls runPrepare and then runStep repeatedly.

void runPrepare ( )

Does the preparation needed to process the tokens of the network

bool runStep ( )

Processes all tokens generated with one call of process() on the generator.

Returns False if there are no more tokens to process.

void topologicalSortExecutionNetwork ( )
protected

Perform a topological sort of the execution network and store it internally.

void update ( )
inline

Rebuilds the visible and execution network.

NetworkNode* visibleNetworkRoot ( )
inline

Member Data Documentation

AlgoSet _algos
protected

Execution dependencies are stored inside the network nodes themselves, and might enter/exit CompositeAlgorithms boundaries. This variable does not do that and only keeps the simple list of algorithms, for the purpose of resetting/deleting them.

NetworkNode* _executionNetworkRoot
protected
streaming::Algorithm* _generator
protected
bool _takeOwnership
protected
std::vector<streaming::Algorithm*> _toposortedNetwork
protected
NetworkNode* _visibleNetworkRoot
protected
Network* lastCreated
static

Last instance of Network created, 0 if it has been deleted or if no network has been created yet.


The documentation for this class was generated from the following file: