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.

172 lines
3.4KB

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