Graph.h 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
// 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 <vector>
#include <map>
#include <set>
#include <list>
#include <math.h>
#include "GraphNode.h"
#include "ModuleNodes.h"

#ifndef GRAPH
#define GRAPH

class Graph
{
public:
	Graph(unsigned int NumNodes, unsigned int SampleRate);
	~Graph();
Dave Griffiths's avatar
Dave Griffiths committed
33

Dave Griffiths's avatar
Dave Griffiths committed
34
	enum Type{TERMINAL,SINOSC,SAWOSC,TRIOSC,SQUOSC,WHITEOSC,PINKOSC,ADSR,ADD,SUB,MUL,DIV,POW,
Dave Griffiths's avatar
Dave Griffiths committed
35
		      MOOGLP,MOOGBP,MOOGHP,FORMANT,SAMPLER,CRUSH,DISTORT,CLIP,DELAY,KS,XFADE,SAMPNHOLD,
Dave Griffiths's avatar
Dave Griffiths committed
36
			  TRACKNHOLD,PAD,NUMTYPES};
Dave Griffiths's avatar
Dave Griffiths committed
37

Dave Griffiths's avatar
Dave Griffiths committed
38 39 40 41 42 43 44
	void Init();
	void Clear();
	void Create(unsigned int id, Type t, float v);
	void Connect(unsigned int id, unsigned int arg, unsigned int to);
	void Play(float time, unsigned int id, float pan);
	void Process(unsigned int bufsize, Sample &left, Sample &right);
	void SetMaxPlaying(int s) { m_MaxPlaying=s; }
Dave Griffiths's avatar
Dave Griffiths committed
45

Dave Griffiths's avatar
Dave Griffiths committed
46 47 48 49 50 51 52 53
private:
	class NodeDesc
	{
	public:
		NodeDesc(): m_Node(NULL), m_ID(0) {}
		GraphNode *m_Node;
		unsigned int m_ID;
	};
Dave Griffiths's avatar
Dave Griffiths committed
54

Dave Griffiths's avatar
Dave Griffiths committed
55 56 57 58 59 60
	class NodeDescVec
	{
	public:
		unsigned int NewIndex()
		{
			m_Current++;
Dave Griffiths's avatar
Dave Griffiths committed
61
			if (m_Current>=m_Vec.size())
Dave Griffiths's avatar
Dave Griffiths committed
62 63 64 65 66 67
			{
				//cerr<<"going round..."<<endl;
				m_Current=0;
			}
			return m_Current;
		}
Dave Griffiths's avatar
Dave Griffiths committed
68

Dave Griffiths's avatar
Dave Griffiths committed
69 70 71 72
		NodeDescVec(): m_Current(0) {}
		unsigned int m_Current;
		vector<NodeDesc*> m_Vec;
	};
Dave Griffiths's avatar
Dave Griffiths committed
73

Dave Griffiths's avatar
Dave Griffiths committed
74
	unsigned int m_MaxPlaying;
dave griffiths's avatar
dave griffiths committed
75
	std::list<pair<unsigned int, float> > m_RootNodes;
Dave Griffiths's avatar
Dave Griffiths committed
76 77 78 79 80 81 82
	map<unsigned int,GraphNode*> m_NodeMap;
	map<Type,NodeDescVec*> m_NodeDescMap;
	unsigned int m_NumNodes;
	unsigned int m_SampleRate;
};

#endif