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.

235 lines
4.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 "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::Reset()
  98. {
  99. ResetPorts();
  100. m_Triggered = false;
  101. m_ChannelSelect = false;
  102. m_TrigDelay = 0;
  103. }
  104. void DistributorPlugin::Execute() {
  105. const int Stream = 0;
  106. const int Switch = 1;
  107. const int Reset = 2;
  108. for (int n=0; n<m_HostInfo->BUFSIZE; n++) {
  109. float InpStream = InputExists (Stream) ? GetInput (Stream, n) : 0.0;
  110. float InpSwitch = InputExists (Switch) ? GetInput (Switch, n) : 0.0;
  111. float InpReset = InputExists (Reset) ? GetInput (Reset, n) : 0;
  112. if (InpReset)
  113. {
  114. m_Triggered = false;
  115. m_ChannelSelect = false;
  116. m_TrigDelay = 0;
  117. }
  118. if (InpSwitch <= 0.0)
  119. m_Triggered = false;
  120. if (! m_Triggered && (InpSwitch > 0.0))
  121. {
  122. m_Triggered = true;
  123. SetOutput (m_ChannelSelect+Switch, n, 0);
  124. m_ChannelSelect = m_ChannelSelect + 2;
  125. if (m_ChannelSelect >= (GetChannelCount()*2))
  126. m_ChannelSelect = 0;
  127. m_TrigDelay = 0;
  128. }
  129. SetOutput (m_ChannelSelect+Stream, n, InpStream);
  130. if (m_TrigDelay < 10)
  131. {
  132. m_TrigDelay++;
  133. SetOutput (m_ChannelSelect+Switch, n, InpSwitch);
  134. }
  135. else
  136. {
  137. SetOutput (m_ChannelSelect+Switch, n, 0);
  138. }
  139. }
  140. }
  141. void DistributorPlugin::ExecuteCommands ()
  142. {
  143. if (m_AudioCH->IsCommandWaiting ())
  144. {
  145. switch (m_AudioCH->GetCommand()) {
  146. case SETCHANNELCOUNT :
  147. {
  148. SetChannelCount(GetChannelCount());
  149. }
  150. break;
  151. }
  152. }
  153. }
  154. void DistributorPlugin::StreamOut (ostream &s)
  155. {
  156. s << m_Version << " " << GetChannelCount() << " ";
  157. }
  158. void DistributorPlugin::StreamIn (istream &s)
  159. {
  160. char Test;
  161. int Version, Channels;
  162. s.seekg (2, ios::cur );//skip to next line
  163. Test = s.peek();//peek first char
  164. s.seekg (-2, ios::cur );//jump back to prior line
  165. if ( (Test >= '0') && (Test <= '9') )
  166. {
  167. s >> Version;
  168. }
  169. else
  170. {
  171. //No Version, so use Version 1
  172. Version = 1;
  173. }
  174. switch (Version)
  175. {
  176. case 2:
  177. {
  178. s >> Channels;
  179. SetChannelCount (Channels);
  180. }
  181. break;
  182. case 1:
  183. {
  184. //use original fixed defaults
  185. SetChannelCount (4);
  186. }
  187. break;
  188. }
  189. }