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.

232 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 <stdio.h>
  19. #include "ControllerPlugin.h"
  20. #include "ControllerPluginGUI.h"
  21. #include <FL/Fl_Button.h>
  22. #include "SpiralIcon.xpm"
  23. extern "C" {
  24. SpiralPlugin* CreateInstance()
  25. {
  26. return new ControllerPlugin;
  27. }
  28. char** GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int GetID()
  33. {
  34. return 0x0003;
  35. }
  36. }
  37. ///////////////////////////////////////////////////////
  38. ControllerPlugin::ControllerPlugin() :
  39. m_Num(4)
  40. {
  41. m_Version=3;
  42. m_PluginInfo.Name="CV Control";
  43. m_PluginInfo.Width=240;
  44. m_PluginInfo.Height=224;
  45. m_PluginInfo.NumInputs=0;
  46. m_PluginInfo.NumOutputs=4;
  47. m_PluginInfo.PortTips.push_back("CV 1");
  48. m_PluginInfo.PortTips.push_back("CV 2");
  49. m_PluginInfo.PortTips.push_back("CV 3");
  50. m_PluginInfo.PortTips.push_back("CV 4");
  51. for (int n=0; n<MAX_CHANNELS; n++)
  52. {
  53. m_ChannelVal[n]=0.0f;
  54. }
  55. m_AudioCH->Register("Number",&m_GUIArgs.Number);
  56. m_AudioCH->Register("Value",&m_GUIArgs.Value);
  57. m_AudioCH->Register("Min",&m_GUIArgs.Min);
  58. m_AudioCH->Register("Max",&m_GUIArgs.Max);
  59. m_AudioCH->RegisterData("Name",ChannelHandler::INPUT,m_GUIArgs.Name,sizeof(m_GUIArgs.Name));
  60. }
  61. ControllerPlugin::~ControllerPlugin()
  62. {
  63. }
  64. PluginInfo &ControllerPlugin::Initialise(const HostInfo *Host)
  65. {
  66. return SpiralPlugin::Initialise(Host);
  67. }
  68. SpiralGUIType *ControllerPlugin::CreateGUI()
  69. {
  70. return new ControllerPluginGUI(m_PluginInfo.Width,
  71. m_PluginInfo.Height,
  72. this,m_AudioCH,m_HostInfo);
  73. }
  74. void ControllerPlugin::Execute()
  75. {
  76. for(int c=0; c<m_Num; c++)
  77. {
  78. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  79. {
  80. SetOutput(c,n,m_ChannelVal[c]);
  81. }
  82. }
  83. }
  84. void ControllerPlugin::ExecuteCommands()
  85. {
  86. if (m_AudioCH->IsCommandWaiting())
  87. {
  88. switch (m_AudioCH->GetCommand())
  89. {
  90. case (SETCHANNEL) :
  91. SetChannel(m_GUIArgs.Number,m_GUIArgs.Value,m_GUIArgs.Min,m_GUIArgs.Max,m_GUIArgs.Name);
  92. break;
  93. case (SETNUM) :
  94. SetNum(m_GUIArgs.Number);
  95. break;
  96. }
  97. }
  98. }
  99. void ControllerPlugin::SetNum(int n)
  100. {
  101. // once to clear the connections with the current info
  102. UpdatePluginInfoWithHost();
  103. if (m_Num<n)
  104. {
  105. char t[256];
  106. sprintf(t,"CV %d",n);
  107. m_PluginInfo.PortTips.push_back(t);
  108. AddOutput();
  109. m_PluginInfo.NumOutputs++;
  110. }
  111. else
  112. {
  113. vector<string>::iterator i=m_PluginInfo.PortTips.end();
  114. m_PluginInfo.PortTips.erase(i--);
  115. RemoveOutput();
  116. m_PluginInfo.NumOutputs--;
  117. }
  118. m_Num=n;
  119. m_PluginInfo.NumOutputs=n;
  120. // do the actual update
  121. UpdatePluginInfoWithHost();
  122. }
  123. // use with caution
  124. void ControllerPlugin::Clear()
  125. {
  126. m_PluginInfo.PortTips.clear();
  127. RemoveAllOutputs();
  128. m_PluginInfo.NumOutputs=0;
  129. }
  130. void ControllerPlugin::StreamOut(ostream &s)
  131. {
  132. s<<m_Version<<" ";
  133. switch (m_Version)
  134. {
  135. case 3:
  136. {
  137. s<<m_Num<<" ";
  138. for (int n=0; n<m_Num; n++)
  139. {
  140. s<<m_ChannelVal[n]<<" ";
  141. }
  142. s<<m_Num<<" ";
  143. for (int n=0; n<m_Num; n++)
  144. {
  145. s<<m_Names[n].size()<<endl;
  146. s<<m_Names[n]<<" ";
  147. s<<m_MinVal[n]<<" ";
  148. s<<m_MaxVal[n]<<" ";
  149. s<<m_ChannelVal[n]<<endl;
  150. }
  151. } break;
  152. default :
  153. cerr<<"ControllerPlugin - I dont support this streaming version any more"<<endl;
  154. break;
  155. }
  156. }
  157. void ControllerPlugin::StreamIn(istream &s)
  158. {
  159. int version;
  160. s>>version;
  161. switch (version)
  162. {
  163. case 3:
  164. {
  165. Clear();
  166. s>>m_Num;
  167. for (int n=0; n<m_Num; n++)
  168. {
  169. s>>m_ChannelVal[n];
  170. }
  171. char Buf[4096];
  172. int size;
  173. s>>m_Num;
  174. for (int n=0; n<m_Num; n++)
  175. {
  176. s>>size;
  177. s.ignore(1);
  178. s.get(Buf,size+1);
  179. m_Names[n]=Buf;
  180. s>>m_MinVal[n];
  181. s>>m_MaxVal[n];
  182. s>>m_ChannelVal[n];
  183. }
  184. // add the channels one by one
  185. for (int n=0; n<m_Num; n++)
  186. {
  187. char t[256];
  188. sprintf(t,"CV %d",n);
  189. m_PluginInfo.PortTips.push_back(t);
  190. AddOutput();
  191. }
  192. m_PluginInfo.NumOutputs=m_Num;
  193. UpdatePluginInfoWithHost();
  194. } break;
  195. default :
  196. cerr<<"ControllerPlugin - I dont support this streaming version any more"<<endl;
  197. break;
  198. }
  199. }