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.

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