Essentia  2.1-beta6-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()

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()

~Network ( )

Member Function Documentation

◆ buildExecutionNetwork()

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.

Referenced by Network::executionNetworkRoot(), and Network::update().

◆ buildVisibleNetwork()

void buildVisibleNetwork ( )
protected

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

Referenced by Network::update().

◆ checkBufferSizes()

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.

◆ checkConnections()

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.

◆ clear()

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).

◆ clearExecutionNetwork()

void clearExecutionNetwork ( )
protected

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

◆ clearVisibleNetwork()

void clearVisibleNetwork ( )
protected

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

◆ deleteAlgorithms()

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.

◆ executionNetworkRoot()

◆ findAlgorithm()

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.

◆ innerVisibleAlgorithms()

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).

◆ linearExecutionOrder()

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.

References Network::_toposortedNetwork.

◆ printBufferFillState()

void printBufferFillState ( )

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

◆ reset()

void reset ( )

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

◆ run()

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.

◆ runPrepare()

void runPrepare ( )

Does the preparation needed to process the tokens of the network

◆ runStep()

bool runStep ( )

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

Returns False if there are no more tokens to process.

◆ topologicalSortExecutionNetwork()

void topologicalSortExecutionNetwork ( )
protected

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

Referenced by Network::update().

◆ update()

void update ( )
inline

◆ visibleNetworkRoot()

NetworkNode* visibleNetworkRoot ( )
inline

Member Data Documentation

◆ _algos

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.

◆ _executionNetworkRoot

NetworkNode* _executionNetworkRoot
protected

◆ _generator

streaming::Algorithm* _generator
protected

◆ _takeOwnership

bool _takeOwnership
protected

◆ _toposortedNetwork

std::vector<streaming::Algorithm*> _toposortedNetwork
protected

◆ _visibleNetworkRoot

NetworkNode* _visibleNetworkRoot
protected

◆ lastCreated

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: