GraphNode.cpp 2.16 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
// 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;

dave griffiths's avatar
dave griffiths committed
23
#define DEFAULT_BUFSIZE 4096*2
Dave Griffiths's avatar
Dave Griffiths committed
24

Dave Griffiths's avatar
Dave Griffiths committed
25
///////////////////////////////////////////
Dave Griffiths's avatar
Dave Griffiths committed
26
27
28

GraphNode::GraphNode(unsigned int numinputs)
{
Dave Griffiths's avatar
Dave Griffiths committed
29
30
31
32
	for(unsigned int n=0; n<numinputs; n++)
	{
		m_ChildNodes.push_back(NULL);
	}
Dave Griffiths's avatar
Dave Griffiths committed
33
34

	m_Output.Allocate(DEFAULT_BUFSIZE);
Dave Griffiths's avatar
Dave Griffiths committed
35
36
}

Dave Griffiths's avatar
Dave Griffiths committed
37
GraphNode::~GraphNode()
Dave Griffiths's avatar
Dave Griffiths committed
38
39
40
41
42
43
{
	Clear();
}

void GraphNode::TriggerChildren(float time)
{
Dave Griffiths's avatar
Dave Griffiths committed
44
	for(vector<GraphNode*>::iterator i=m_ChildNodes.begin();
Dave Griffiths's avatar
Dave Griffiths committed
45
46
47
48
49
50
51
52
53
54
55
		i!=m_ChildNodes.end(); ++i)
	{
		if (*i!=NULL)
		{
			(*i)->Trigger(time);
		}
	}
}

void GraphNode::ProcessChildren(unsigned int bufsize)
{
Dave Griffiths's avatar
Dave Griffiths committed
56
	for(vector<GraphNode*>::iterator i=m_ChildNodes.begin();
Dave Griffiths's avatar
Dave Griffiths committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
		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())
Dave Griffiths's avatar
Dave Griffiths committed
77
	{
Dave Griffiths's avatar
Dave Griffiths committed
78
79
80
81
82
83
84
85
86
		m_ChildNodes[num]=s;
	}
}

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

Dave Griffiths's avatar
Dave Griffiths committed
87
GraphNode* GraphNode::GetChild(unsigned int num)
Dave Griffiths's avatar
Dave Griffiths committed
88
89
{
	if(num<m_ChildNodes.size())
Dave Griffiths's avatar
Dave Griffiths committed
90
91
	{
		return m_ChildNodes[num];
Dave Griffiths's avatar
Dave Griffiths committed
92
93
94
95
	}
	return NULL;
}

Dave Griffiths's avatar
Dave Griffiths committed
96
97
Sample &GraphNode::GetInput(unsigned int num)
{
Dave Griffiths's avatar
Dave Griffiths committed
98
	assert(GetChild(num)!=NULL);
Dave Griffiths's avatar
Dave Griffiths committed
99
	return GetChild(num)->GetOutput();
Dave Griffiths's avatar
Dave Griffiths committed
100
101
102
103
104
105
106
}

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