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.

193 lines
3.8KB

  1. /* SpiralSound
  2. * Copyleft (C) 2001 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 "SplitterPlugin.h"
  19. #include "SplitterPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include "SpiralIcon.xpm"
  22. using namespace std;
  23. extern "C" {
  24. SpiralPlugin* SpiralPlugin_CreateInstance()
  25. {
  26. return new SplitterPlugin;
  27. }
  28. char** SpiralPlugin_GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int SpiralPlugin_GetID()
  33. {
  34. return 0x0006;
  35. }
  36. string SpiralPlugin_GetGroupName()
  37. {
  38. return "Control";
  39. }
  40. }
  41. ///////////////////////////////////////////////////////
  42. SplitterPlugin::SplitterPlugin()
  43. {
  44. m_PluginInfo.Name="Splitter";
  45. m_PluginInfo.Width=80;
  46. m_PluginInfo.Height=40;
  47. m_Version = 2;
  48. m_GUIArgs.ChannelCount = 4;
  49. CreatePorts ();
  50. m_AudioCH->Register ("ChannelCount", &m_GUIArgs.ChannelCount);
  51. }
  52. SplitterPlugin::~SplitterPlugin()
  53. {
  54. }
  55. void SplitterPlugin::CreatePorts (int n, bool AddPorts)
  56. {
  57. int c;
  58. char t[256];
  59. m_PluginInfo.NumInputs = 1;
  60. m_PluginInfo.PortTips.push_back ("Input");
  61. m_PluginInfo.NumOutputs = n;
  62. for (c=1; c<=n; c++) {
  63. sprintf (t, "Out %d", c);
  64. m_PluginInfo.PortTips.push_back (t);
  65. }
  66. if (AddPorts) {
  67. for (int c=0; c<m_PluginInfo.NumInputs; c++) AddInput();
  68. for (int c=0; c<m_PluginInfo.NumOutputs; c++) AddOutput();
  69. }
  70. }
  71. void SplitterPlugin::SetChannelCount (int count)
  72. {
  73. m_GUIArgs.ChannelCount = count;
  74. UpdatePluginInfoWithHost();
  75. RemoveAllInputs ();
  76. RemoveAllOutputs ();
  77. m_PluginInfo.NumInputs = 0;
  78. m_PluginInfo.NumOutputs = 0;
  79. m_PluginInfo.PortTips.clear ();
  80. CreatePorts (count, true);
  81. UpdatePluginInfoWithHost ();
  82. }
  83. PluginInfo &SplitterPlugin::Initialise(const HostInfo *Host)
  84. {
  85. return SpiralPlugin::Initialise( Host);
  86. }
  87. SpiralGUIType *SplitterPlugin::CreateGUI()
  88. {
  89. return new SplitterPluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  90. }
  91. void SplitterPlugin::Execute()
  92. {
  93. // Just copy the data through.
  94. for (int i=0; i<GetChannelCount(); i++)
  95. {
  96. GetOutputBuf(i)->Zero();
  97. }
  98. if (InputExists(0))
  99. {
  100. for (int i=0; i<GetChannelCount(); i++)
  101. {
  102. GetOutputBuf(i)->Mix(*GetInput(0),0);
  103. }
  104. }
  105. }
  106. void SplitterPlugin::ExecuteCommands ()
  107. {
  108. if (m_AudioCH->IsCommandWaiting ())
  109. {
  110. switch (m_AudioCH->GetCommand()) {
  111. case SETCHANNELCOUNT :
  112. {
  113. UpdatePluginInfoWithHost();
  114. RemoveAllInputs ();
  115. RemoveAllOutputs ();
  116. m_PluginInfo.NumInputs = 0;
  117. m_PluginInfo.NumOutputs = 0;
  118. m_PluginInfo.PortTips.clear ();
  119. CreatePorts (m_GUIArgs.ChannelCount, true);
  120. UpdatePluginInfoWithHost ();
  121. }
  122. break;
  123. }
  124. }
  125. }
  126. void SplitterPlugin::StreamOut (ostream &s)
  127. {
  128. s << m_Version << " " << GetChannelCount() << " ";
  129. }
  130. void SplitterPlugin::StreamIn (istream &s)
  131. {
  132. char Test;
  133. int Version, Channels;
  134. s.seekg (2, ios_base::cur );//skip to next line
  135. Test = s.peek();//peek first char
  136. s.seekg (-2, ios_base::cur );//jump back to prior line
  137. if ( (Test >= '0') && (Test <= '9') )
  138. {
  139. s >> Version;
  140. }
  141. else
  142. {
  143. //No Version, so use Version 1
  144. Version = 1;
  145. }
  146. switch (Version)
  147. {
  148. case 2:
  149. {
  150. s >> Channels;
  151. SetChannelCount (Channels);
  152. }
  153. break;
  154. case 1:
  155. {
  156. //use original fixed defaults
  157. SetChannelCount (4);
  158. }
  159. break;
  160. }
  161. }