You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
3.4KB

  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. #include "SpiralPlugin.h"
  19. using namespace std;
  20. SpiralPlugin::SpiralPlugin()
  21. {
  22. m_Version=1;
  23. m_PluginInfo.Name="BasePlugin";
  24. m_PluginInfo.Width=100;
  25. m_PluginInfo.Height=100;
  26. m_PluginInfo.NumInputs=0;
  27. m_PluginInfo.NumOutputs=0;
  28. UpdateInfo=NULL;
  29. cb_Update=NULL;
  30. m_Parent=NULL;
  31. m_HostID=-1;
  32. m_IsTerminal=false;
  33. m_IsDead=false;
  34. m_AudioCH = new ChannelHandler;
  35. }
  36. SpiralPlugin::~SpiralPlugin()
  37. {
  38. RemoveAllOutputs();
  39. RemoveAllInputs();
  40. delete m_AudioCH;
  41. }
  42. bool SpiralPlugin::Kill()
  43. {
  44. m_IsDead = true;
  45. return true;
  46. }
  47. void SpiralPlugin::ResetPorts()
  48. {
  49. for (int n=0; n<m_PluginInfo.NumOutputs; n++)
  50. {
  51. m_Output[n]->Clear();
  52. m_Output[n]->Allocate(m_HostInfo->BUFSIZE);
  53. }
  54. }
  55. void SpiralPlugin::Reset()
  56. {
  57. ResetPorts();
  58. }
  59. PluginInfo &SpiralPlugin::Initialise(const HostInfo *Host)
  60. {
  61. m_HostInfo=Host;
  62. for (int n=0; n<m_PluginInfo.NumInputs; n++)
  63. {
  64. m_Input.push_back(NULL);
  65. }
  66. for (int n=0; n<m_PluginInfo.NumOutputs; n++)
  67. {
  68. m_Output.push_back(new Sample(Host->BUFSIZE));
  69. }
  70. for (int n=0; n<m_PluginInfo.NumInputs+m_PluginInfo.NumOutputs; n++)
  71. {
  72. m_PluginInfo.PortTypes.push_back(0);
  73. }
  74. return m_PluginInfo;
  75. }
  76. bool SpiralPlugin::GetOutput(unsigned int n, Sample **s)
  77. {
  78. if (n>=m_Output.size()) return false;
  79. *s = m_Output[n];
  80. return true;
  81. }
  82. bool SpiralPlugin::SetInput(unsigned int n, const Sample *s)
  83. {
  84. if (n>=m_Input.size()) return false;
  85. m_Input[n]=s;
  86. return true;
  87. }
  88. void SpiralPlugin::UpdateChannelHandler()
  89. {
  90. m_AudioCH->UpdateDataNow();
  91. }
  92. void SpiralPlugin::AddOutput()
  93. {
  94. Sample* NewSample = new Sample(m_HostInfo->BUFSIZE);
  95. m_Output.push_back(NewSample);
  96. }
  97. void SpiralPlugin::RemoveOutput()
  98. {
  99. vector<Sample*>::iterator si=m_Output.end();
  100. si--;
  101. delete *si;
  102. m_Output.erase(si);
  103. }
  104. void SpiralPlugin::RemoveAllOutputs()
  105. {
  106. for (vector<Sample*>::iterator i=m_Output.begin();
  107. i!=m_Output.end(); i++)
  108. {
  109. delete *i;
  110. }
  111. m_Output.clear();
  112. }
  113. void SpiralPlugin::AddInput()
  114. {
  115. m_Input.push_back(NULL);
  116. }
  117. void SpiralPlugin::RemoveInput()
  118. {
  119. vector<const Sample*>::iterator si=m_Input.end();
  120. si--;
  121. m_Input.erase(si);
  122. }
  123. void SpiralPlugin::RemoveAllInputs()
  124. {
  125. m_Input.clear();
  126. }
  127. void SpiralPlugin::UpdatePluginInfoWithHost()
  128. {
  129. if (UpdateInfo!=NULL)
  130. {
  131. UpdateInfo(m_HostID,(void*)&m_PluginInfo);
  132. }
  133. }
  134. void SpiralPlugin::SetUpdateInfoCallback(int ID, void(*s)(int, void *))
  135. {
  136. m_HostID=ID;
  137. UpdateInfo=s;
  138. }
  139. void SpiralPlugin::SetInPortType(PluginInfo &pinfo, int port, Sample::SampleType type)
  140. {
  141. pinfo.PortTypes[port] = type;
  142. }
  143. void SpiralPlugin::SetOutPortType(PluginInfo &pinfo, int port, Sample::SampleType type)
  144. {
  145. pinfo.PortTypes[port+m_PluginInfo.NumInputs] = type;
  146. GetOutputBuf(port)->setSampleType(type);
  147. }