1 /*  SpiralSound
2  *  Copyleft (C) 2002 David Griffiths <dave@pawfal.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 
19 #include "SpiralPlugin.h"
20 
21 using namespace std;
22 
SpiralPlugin()23 SpiralPlugin::SpiralPlugin()
24 {
25 	m_Version=1;
26 	m_PluginInfo.Name="BasePlugin";
27 	m_PluginInfo.Width=100;
28 	m_PluginInfo.Height=100;
29 	m_PluginInfo.NumInputs=0;
30 	m_PluginInfo.NumOutputs=0;
31 	UpdateInfo=NULL;
32 	cb_Update=NULL;
33 	m_Parent=NULL;
34 	m_HostID=-1;
35 	m_IsTerminal=false;
36 	m_IsDead=false;
37 	m_AudioCH = new ChannelHandler;
38 }
39 
~SpiralPlugin()40 SpiralPlugin::~SpiralPlugin()
41 {
42 	RemoveAllOutputs();
43 	RemoveAllInputs();
44 	delete m_AudioCH;
45 }
46 
Kill()47 bool SpiralPlugin::Kill()
48 {
49 	m_IsDead = true;
50 	return true;
51 }
52 
Initialise(const HostInfo * Host)53 PluginInfo &SpiralPlugin::Initialise(const HostInfo *Host)
54 {
55 	m_HostInfo=Host;
56 
57         for (int n=0; n<m_PluginInfo.NumInputs; n++)
58 	{
59 		m_Input.push_back(NULL);
60 	}
61 
62 	for (int n=0; n<m_PluginInfo.NumOutputs; n++)
63 	{
64 		m_Output.push_back(new Sample(Host->BUFSIZE));
65 	}
66 
67 	for (int n=0; n<m_PluginInfo.NumInputs+m_PluginInfo.NumOutputs; n++)
68  	{
69  		m_PluginInfo.PortTypes.push_back(0);
70  	}
71 
72 	return m_PluginInfo;
73 }
74 
GetOutput(unsigned int n,Sample ** s)75 bool SpiralPlugin::GetOutput(unsigned int n, Sample **s)
76 {
77 	if (n>=m_Output.size()) return false;
78 	*s = m_Output[n];
79 
80 	return true;
81 }
82 
SetInput(unsigned int n,const Sample * s)83 bool SpiralPlugin::SetInput(unsigned int n, const Sample *s)
84 {
85 	if (n>=m_Input.size()) return false;
86 	m_Input[n]=s;
87 	return true;
88 }
89 
UpdateChannelHandler()90 void SpiralPlugin::UpdateChannelHandler()
91 {
92     m_AudioCH->UpdateDataNow();
93 }
94 
AddOutput()95 void SpiralPlugin::AddOutput()
96 {
97 	Sample* NewSample = new Sample(m_HostInfo->BUFSIZE);
98 	m_Output.push_back(NewSample);
99 }
100 
RemoveOutput()101 void SpiralPlugin::RemoveOutput()
102 {
103 	vector<Sample*>::iterator si=m_Output.end();
104 	si--;
105 	delete *si;
106 	m_Output.erase(si);
107 }
108 
RemoveAllOutputs()109 void SpiralPlugin::RemoveAllOutputs()
110 {
111 	for (vector<Sample*>::iterator i=m_Output.begin();
112 		 i!=m_Output.end(); i++)
113 	{
114 		delete *i;
115 	}
116 
117 	m_Output.clear();
118 }
119 
AddInput()120 void SpiralPlugin::AddInput()
121 {
122 	m_Input.push_back(NULL);
123 }
124 
RemoveInput()125 void SpiralPlugin::RemoveInput()
126 {
127 	vector<const Sample*>::iterator si=m_Input.end();
128 	si--;
129 	m_Input.erase(si);
130 }
131 
RemoveAllInputs()132 void SpiralPlugin::RemoveAllInputs()
133 {
134 	m_Input.clear();
135 }
136 
UpdatePluginInfoWithHost()137 void SpiralPlugin::UpdatePluginInfoWithHost()
138 {
139 	if (UpdateInfo!=NULL)
140 	{
141 		UpdateInfo(m_HostID,(void*)&m_PluginInfo);
142 	}
143 }
SetUpdateInfoCallback(int ID,void (* s)(int,void *))144 void SpiralPlugin::SetUpdateInfoCallback(int ID, void(*s)(int, void *))
145 {
146 	m_HostID=ID;
147 	UpdateInfo=s;
148 }
149 
SetInPortType(PluginInfo & pinfo,int port,Sample::SampleType type)150 void SpiralPlugin::SetInPortType(PluginInfo &pinfo, int port, Sample::SampleType type)
151 {
152     pinfo.PortTypes[port] = type;
153 }
154 
SetOutPortType(PluginInfo & pinfo,int port,Sample::SampleType type)155 void SpiralPlugin::SetOutPortType(PluginInfo &pinfo, int port, Sample::SampleType type)
156 {
157     pinfo.PortTypes[port+m_PluginInfo.NumInputs] = type;
158     GetOutputBuf(port)->setSampleType(type);
159 }
160