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.

115 lines
2.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 "SampleHoldPlugin.h"
  19. #include "SampleHoldPluginGUI.h"
  20. #include <FL/Fl_Button.H>
  21. #include "SpiralIcon.xpm"
  22. using namespace std;
  23. extern "C" {
  24. SpiralPlugin* SpiralPlugin_CreateInstance()
  25. {
  26. return new SampleHoldPlugin;
  27. }
  28. char** SpiralPlugin_GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int SpiralPlugin_GetID()
  33. {
  34. return 0x0033;
  35. }
  36. string SpiralPlugin_GetGroupName()
  37. {
  38. return "Control";
  39. }
  40. }
  41. ///////////////////////////////////////////////////////
  42. SampleHoldPlugin::SampleHoldPlugin()
  43. {
  44. m_PluginInfo.Name="SampleHold";
  45. m_PluginInfo.Width=220;
  46. m_PluginInfo.Height=125;
  47. m_PluginInfo.NumInputs=2;
  48. m_PluginInfo.NumOutputs=1;
  49. m_PluginInfo.PortTips.push_back("Input");
  50. m_PluginInfo.PortTips.push_back("Clock");
  51. m_PluginInfo.PortTips.push_back("Out");
  52. }
  53. SampleHoldPlugin::~SampleHoldPlugin()
  54. {
  55. }
  56. PluginInfo &SampleHoldPlugin::Initialise(const HostInfo *Host)
  57. {
  58. PluginInfo& Info = SpiralPlugin::Initialise(Host);
  59. m_val = 0;
  60. m_flag = 0;
  61. return Info;
  62. }
  63. SpiralGUIType *SampleHoldPlugin::CreateGUI()
  64. {
  65. return NULL;
  66. }
  67. void SampleHoldPlugin::Reset()
  68. {
  69. ResetPorts();
  70. m_val = 0;
  71. m_flag = 0;
  72. }
  73. void SampleHoldPlugin::Execute()
  74. {
  75. // Just copy the data through.
  76. GetOutputBuf(0)->Zero();
  77. if (InputExists(0) && InputExists(1))
  78. {
  79. for (int i=0;i<m_HostInfo->BUFSIZE;i++)
  80. {
  81. float v = GetInput(0,i);
  82. float c = GetInput(1,i);
  83. if (c > 0.666)
  84. {
  85. if (!m_flag)
  86. {
  87. m_val = v;
  88. SetOutput(0,i,v);
  89. m_flag = 1;
  90. }
  91. else
  92. SetOutput(0,i,m_val);
  93. }
  94. else
  95. SetOutput(0,i,m_val);
  96. if (c < 0.333)
  97. {
  98. m_flag = 0;
  99. }
  100. }
  101. }
  102. }