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.

226 lines
4.7KB

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