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.

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