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