Graph.h 2.14 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
// 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();
	
	enum Type{TERMINAL,SINOSC,SAWOSC,TRIOSC,SQUOSC,WHITEOSC,PINKOSC,ADSR,ADD,SUB,MUL,DIV,POW,
		      MOOGLP,MOOGBP,MOOGHP,FORMANT,/*SAMPLER,*/CRUSH,DISTORT,CLIP,DELAY,KS,XFADE,SAMPNHOLD,
			  TRACKNHOLD,NUMTYPES};
	
	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; }
	
private:
	class NodeDesc
	{
	public:
		NodeDesc(): m_Node(NULL), m_ID(0) {}
		GraphNode *m_Node;
		unsigned int m_ID;
	};
	
	class NodeDescVec
	{
	public:
		unsigned int NewIndex()
		{
			m_Current++;
			if (m_Current>=m_Vec.size()) 
			{
				//cerr<<"going round..."<<endl;
				m_Current=0;
			}
			return m_Current;
		}
		
		NodeDescVec(): m_Current(0) {}
		unsigned int m_Current;
		vector<NodeDesc*> m_Vec;
	};
	
	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