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.

182 lines
3.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 "OperatorPlugin.h"
  19. #include "OperatorPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include "SpiralIcon.xpm"
  22. #include "../../NoteTable.h"
  23. extern "C" {
  24. SpiralPlugin* SpiralPlugin_CreateInstance()
  25. {
  26. return new OperatorPlugin;
  27. }
  28. char** SpiralPlugin_GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int SpiralPlugin_GetID()
  33. {
  34. return 44;
  35. }
  36. string SpiralPlugin_GetGroupName()
  37. {
  38. return "Maths/Logic";
  39. }
  40. }
  41. ///////////////////////////////////////////////////////
  42. OperatorPlugin::OperatorPlugin() :
  43. m_Operator(ADD),
  44. m_Constant(0)
  45. {
  46. m_Version=2;
  47. m_PluginInfo.Name="Operator";
  48. m_PluginInfo.Width=120;
  49. m_PluginInfo.Height=80;
  50. m_PluginInfo.NumInputs=2;
  51. m_PluginInfo.NumOutputs=1;
  52. m_PluginInfo.PortTips.push_back("Input 1");
  53. m_PluginInfo.PortTips.push_back("Input 2");
  54. m_PluginInfo.PortTips.push_back("Output");
  55. m_AudioCH->Register("Operator",(int*)&m_Operator);
  56. m_AudioCH->Register("Constant",&m_Constant);
  57. }
  58. OperatorPlugin::~OperatorPlugin()
  59. {
  60. }
  61. PluginInfo &OperatorPlugin::Initialise(const HostInfo *Host)
  62. {
  63. return SpiralPlugin::Initialise(Host);
  64. }
  65. SpiralGUIType *OperatorPlugin::CreateGUI()
  66. {
  67. return new OperatorPluginGUI(m_PluginInfo.Width,
  68. m_PluginInfo.Height,
  69. this,m_AudioCH,m_HostInfo);
  70. }
  71. void OperatorPlugin::Execute()
  72. {
  73. float Freq=0, OldFreq=0;
  74. switch (m_Operator)
  75. {
  76. case ADD :
  77. if (InputExists(1))
  78. {
  79. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  80. {
  81. SetOutput(0,n,GetInput(0,n)+GetInput(1,n));
  82. }
  83. }
  84. else
  85. {
  86. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  87. {
  88. SetOutput(0,n,GetInput(0,n)+m_Constant);
  89. }
  90. }
  91. break;
  92. case SUB :
  93. if (InputExists(1))
  94. {
  95. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  96. {
  97. SetOutput(0,n,GetInput(0,n)-GetInput(1,n));
  98. }
  99. }
  100. else
  101. {
  102. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  103. {
  104. SetOutput(0,n,GetInput(0,n)-m_Constant);
  105. }
  106. }
  107. break;
  108. case DIV :
  109. if (InputExists(1))
  110. {
  111. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  112. {
  113. if (GetInput(1,n)==0) SetOutput(0,n,0);
  114. else SetOutput(0,n,GetInput(0,n)/GetInput(1,n));
  115. }
  116. }
  117. else
  118. {
  119. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  120. {
  121. if (m_Constant==0) SetOutput(0,n,0);
  122. else SetOutput(0,n,GetInput(0,n)/m_Constant);
  123. }
  124. }
  125. break;
  126. case MUL :
  127. if (InputExists(1))
  128. {
  129. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  130. {
  131. SetOutput(0,n,GetInput(0,n)*GetInput(1,n));
  132. }
  133. }
  134. else
  135. {
  136. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  137. {
  138. SetOutput(0,n,GetInput(0,n)*m_Constant);
  139. }
  140. }
  141. break;
  142. default:
  143. break;
  144. }
  145. }
  146. void OperatorPlugin::ExecuteCommands()
  147. {
  148. }
  149. void OperatorPlugin::StreamOut(ostream &s)
  150. {
  151. s<<m_Version<<endl;
  152. s<<m_Constant<<" ";
  153. s<<(int)m_Operator<<" ";
  154. }
  155. void OperatorPlugin::StreamIn(istream &s)
  156. {
  157. int version;
  158. s>>version;
  159. s>>m_Constant;
  160. if (version>1)
  161. {
  162. int t;
  163. s>>t;
  164. m_Operator=(OperatorType)t;
  165. }
  166. }