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.

221 lines
4.6KB

  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 "DistributorPlugin.h"
  19. #include "DistributorPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include "SpiralIcon.xpm"
  22. using namespace std;
  23. extern "C" {
  24. SpiralPlugin* SpiralPlugin_CreateInstance() {
  25. return new DistributorPlugin;
  26. }
  27. char** SpiralPlugin_GetIcon() {
  28. return SpiralIcon_xpm;
  29. }
  30. int SpiralPlugin_GetID() {
  31. return 0x0056;
  32. }
  33. string SpiralPlugin_GetGroupName() {
  34. return "Control";
  35. }
  36. }
  37. ///////////////////////////////////////////////////////
  38. DistributorPlugin::DistributorPlugin():
  39. m_Triggered (false),
  40. m_ChannelSelect (0),
  41. m_TrigDelay (0)
  42. {
  43. m_PluginInfo.Name = "Distributor";
  44. m_PluginInfo.Width=80;
  45. m_PluginInfo.Height=40;
  46. m_Version = 2;
  47. m_GUIArgs.ChannelCount = 2;
  48. CreatePorts ();
  49. m_AudioCH->Register("ChannelCount", &m_GUIArgs.ChannelCount);
  50. }
  51. DistributorPlugin::~DistributorPlugin()
  52. {
  53. }
  54. void DistributorPlugin::CreatePorts (int n, bool AddPorts)
  55. {
  56. int c;
  57. char t[256];
  58. m_PluginInfo.NumInputs = 3;
  59. m_PluginInfo.PortTips.push_back ("Stream");
  60. m_PluginInfo.PortTips.push_back ("Switcher");
  61. m_PluginInfo.PortTips.push_back ("Reset CV");
  62. m_PluginInfo.NumOutputs = n*2;
  63. for (c=1; c<=n; c++) {
  64. sprintf (t, "Stream %d", c);
  65. m_PluginInfo.PortTips.push_back (t);
  66. sprintf (t, "Switcher %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 DistributorPlugin::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 &DistributorPlugin::Initialise (const HostInfo *Host)
  87. {
  88. return SpiralPlugin::Initialise (Host);
  89. }
  90. SpiralGUIType *DistributorPlugin::CreateGUI()
  91. {
  92. return new DistributorPluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  93. }
  94. void DistributorPlugin::Execute() {
  95. const int Stream = 0;
  96. const int Switch = 1;
  97. const int Reset = 2;
  98. for (int n=0; n<m_HostInfo->BUFSIZE; n++) {
  99. float InpStream = InputExists (Stream) ? GetInput (Stream, n) : 0.0;
  100. float InpSwitch = InputExists (Switch) ? GetInput (Switch, n) : 0.0;
  101. float InpReset = InputExists (Reset) ? GetInput (Reset, n) : 0;
  102. if (InpReset)
  103. {
  104. m_Triggered = false;
  105. m_ChannelSelect = false;
  106. m_TrigDelay = 0;
  107. }
  108. if (InpSwitch <= 0.0)
  109. m_Triggered = false;
  110. if (! m_Triggered && (InpSwitch > 0.0))
  111. {
  112. m_Triggered = true;
  113. SetOutput (m_ChannelSelect+Switch, n, 0);
  114. m_ChannelSelect = m_ChannelSelect + 2;
  115. if (m_ChannelSelect >= (GetChannelCount()*2))
  116. m_ChannelSelect = 0;
  117. m_TrigDelay = 0;
  118. }
  119. SetOutput (m_ChannelSelect+Stream, n, InpStream);
  120. if (m_TrigDelay < 10)
  121. {
  122. m_TrigDelay++;
  123. SetOutput (m_ChannelSelect+Switch, n, InpSwitch);
  124. }
  125. else
  126. {
  127. SetOutput (m_ChannelSelect+Switch, n, 0);
  128. }
  129. }
  130. }
  131. void DistributorPlugin::ExecuteCommands ()
  132. {
  133. if (m_AudioCH->IsCommandWaiting ())
  134. {
  135. switch (m_AudioCH->GetCommand()) {
  136. case SETCHANNELCOUNT :
  137. {
  138. SetChannelCount(GetChannelCount());
  139. }
  140. break;
  141. }
  142. }
  143. }
  144. void DistributorPlugin::StreamOut (ostream &s)
  145. {
  146. s << m_Version << " " << GetChannelCount() << " ";
  147. }
  148. void DistributorPlugin::StreamIn (istream &s)
  149. {
  150. char Test;
  151. int Version, Channels;
  152. s.seekg (2, ios_base::cur );//skip to next line
  153. Test = s.peek();//peek first char
  154. s.seekg (-2, ios_base::cur );//jump back to prior line
  155. if ( (Test >= '0') && (Test <= '9') )
  156. {
  157. s >> Version;
  158. }
  159. else
  160. {
  161. //No Version, so use Version 1
  162. Version = 1;
  163. }
  164. switch (Version)
  165. {
  166. case 2:
  167. {
  168. s >> Channels;
  169. SetChannelCount (Channels);
  170. }
  171. break;
  172. case 1:
  173. {
  174. //use original fixed defaults
  175. SetChannelCount (4);
  176. }
  177. break;
  178. }
  179. }