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.

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