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.

237 lines
4.3KB

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