GraphNode.cpp 2.13 KB
Newer Older
Dave Griffiths's avatar
Dave Griffiths committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
// Copyright (C) 2006 David Griffiths <dave@pawfal.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "GraphNode.h"
#include <iostream>
#include <string>

using namespace std;

///////////////////////////////////////////
	
GraphNode::GraphNode(unsigned int numinputs) 
{ 
	for(unsigned int n=0; n<numinputs; n++)
	{
		m_ChildNodes.push_back(NULL);
	}
	
	m_Output.Allocate(1);
}

GraphNode::~GraphNode() 
{
	Clear();
}

void GraphNode::TriggerChildren(float time)
{
	for(vector<GraphNode*>::iterator i=m_ChildNodes.begin(); 
		i!=m_ChildNodes.end(); ++i)
	{
		if (*i!=NULL)
		{
			(*i)->Trigger(time);
		}
	}
}

void GraphNode::ProcessChildren(unsigned int bufsize)
{
	for(vector<GraphNode*>::iterator i=m_ChildNodes.begin(); 
		i!=m_ChildNodes.end(); ++i)
	{
		if (*i!=NULL)
		{
			(*i)->Process(bufsize);
		}
	}
}

void GraphNode::Clear()
{
	for(unsigned int n=0; n<m_ChildNodes.size(); n++)
	{
		m_ChildNodes[n]=NULL;
	}
}

void GraphNode::SetChild(unsigned int num, GraphNode *s)
{
	if(num<m_ChildNodes.size())
	{ 
		m_ChildNodes[num]=s;
	}
}

bool GraphNode::ChildExists(unsigned int num)
{
	return GetChild(num)!=NULL;
}

GraphNode* GraphNode::GetChild(unsigned int num) 
{
	if(num<m_ChildNodes.size())
	{ 
		return m_ChildNodes[num]; 
	}
	return NULL;
}

Sample &GraphNode::GetInput(unsigned int num) 
{ 
	assert(GetChild(num)!=NULL);
	return GetChild(num)->GetOutput(); 
}

float GraphNode::GetCVValue()
{
	if (IsTerminal()) return GetValue();
	else return GetOutput()[(unsigned int)0];
}