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.

157 lines
3.5KB

  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 "LogicPlugin.h"
  19. #include "LogicPluginGUI.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 LogicPlugin;
  27. }
  28. char** GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int GetID()
  33. {
  34. return 52;
  35. }
  36. string GetGroupName()
  37. {
  38. return "Maths/Logic";
  39. }
  40. }
  41. ///////////////////////////////////////////////////////
  42. LogicPlugin::LogicPlugin() :
  43. m_Operator(AND),
  44. m_Constant(0)
  45. {
  46. m_PluginInfo.Name="Logic";
  47. m_PluginInfo.Width=75;
  48. m_PluginInfo.Height=100;
  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. LogicPlugin::~LogicPlugin()
  58. {
  59. }
  60. PluginInfo &LogicPlugin::Initialise(const HostInfo *Host)
  61. {
  62. return SpiralPlugin::Initialise(Host);
  63. }
  64. SpiralGUIType *LogicPlugin::CreateGUI()
  65. {
  66. return new LogicPluginGUI(m_PluginInfo.Width,
  67. m_PluginInfo.Height,
  68. this,m_AudioCH,m_HostInfo);
  69. }
  70. void LogicPlugin::Execute()
  71. {
  72. float Freq=0, OldFreq=0;
  73. switch (m_Operator)
  74. {
  75. case AND :
  76. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  77. {
  78. if (GetInput(0,n)>0 && GetInput(1,n)>0) SetOutput(0,n,1.0f);
  79. else SetOutput(0,n,-1.0f);
  80. }
  81. break;
  82. case OR :
  83. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  84. {
  85. if (GetInput(0,n)>0 || GetInput(1,n)>0) SetOutput(0,n,1.0f);
  86. else SetOutput(0,n,-1.0f);
  87. }
  88. break;
  89. case NOT :
  90. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  91. {
  92. if (GetInput(0,n)>0) SetOutput(0,n,-1.0f);
  93. else SetOutput(0,n,1.0f);
  94. }
  95. break;
  96. case NAND :
  97. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  98. {
  99. if (!(GetInput(0,n)>0 && GetInput(1,n)>0)) SetOutput(0,n,1.0f);
  100. else SetOutput(0,n,-1.0f);
  101. }
  102. break;
  103. case NOR :
  104. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  105. {
  106. if (!(GetInput(0,n)>0) && !(GetInput(1,n)>0)) SetOutput(0,n,1.0f);
  107. else SetOutput(0,n,-1.0f);
  108. }
  109. break;
  110. case XOR :
  111. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  112. {
  113. if ((GetInput(0,n)>0 || GetInput(1,n)>0) &&
  114. !(GetInput(0,n)>0 && GetInput(1,n)>0)) SetOutput(0,n,1.0f);
  115. else SetOutput(0,n,-1.0f);
  116. }
  117. break;
  118. case XNOR :
  119. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  120. {
  121. if ((GetInput(0,n)>0 && GetInput(1,n)>0) ||
  122. (!(GetInput(0,n)>0) && !(GetInput(1,n)>0))) SetOutput(0,n,1.0f);
  123. else SetOutput(0,n,-1.0f);
  124. }
  125. break;
  126. }
  127. }
  128. void LogicPlugin::ExecuteCommands()
  129. {
  130. }
  131. void LogicPlugin::StreamOut(ostream &s)
  132. {
  133. s<<m_Version<<endl;
  134. s<<m_Constant<<" ";
  135. }
  136. void LogicPlugin::StreamIn(istream &s)
  137. {
  138. int version;
  139. s>>version;
  140. s>>m_Constant;
  141. }