Graph.h 2.29 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
// 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"
dave griffiths's avatar
dave griffiths committed
24
#include "EventQueue.h"
Dave Griffiths's avatar
Dave Griffiths committed
25 26 27 28 29 30 31 32 33

#ifndef GRAPH
#define GRAPH

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

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

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

Dave Griffiths's avatar
Dave Griffiths committed
47
private:
dave griffiths's avatar
dave griffiths committed
48 49
	void _Play(float time, unsigned int id, float pan);

Dave Griffiths's avatar
Dave Griffiths committed
50 51 52 53 54 55 56
	class NodeDesc
	{
	public:
		NodeDesc(): m_Node(NULL), m_ID(0) {}
		GraphNode *m_Node;
		unsigned int m_ID;
	};
Dave Griffiths's avatar
Dave Griffiths committed
57

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

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

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

	EventQueue m_EventQueue;
	Time m_CurrentTime;
Dave Griffiths's avatar
Dave Griffiths committed
86 87 88
};

#endif