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.

101 lines
2.1KB

  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. extern "C" {
  23. SpiralPlugin* CreateInstance()
  24. {
  25. return new SampleHoldPlugin;
  26. }
  27. char** GetIcon()
  28. {
  29. return SpiralIcon_xpm;
  30. }
  31. int GetID()
  32. {
  33. return 0x0033;
  34. }
  35. }
  36. ///////////////////////////////////////////////////////
  37. SampleHoldPlugin::SampleHoldPlugin()
  38. {
  39. m_PluginInfo.Name="SampleHold";
  40. m_PluginInfo.Width=220;
  41. m_PluginInfo.Height=125;
  42. m_PluginInfo.NumInputs=2;
  43. m_PluginInfo.NumOutputs=1;
  44. m_PluginInfo.PortTips.push_back("Input");
  45. m_PluginInfo.PortTips.push_back("Clock");
  46. m_PluginInfo.PortTips.push_back("Out");
  47. }
  48. SampleHoldPlugin::~SampleHoldPlugin()
  49. {
  50. }
  51. PluginInfo &SampleHoldPlugin::Initialise(const HostInfo *Host)
  52. {
  53. PluginInfo& Info = SpiralPlugin::Initialise(Host);
  54. m_val = 0;
  55. m_flag = 0;
  56. return Info;
  57. }
  58. SpiralGUIType *SampleHoldPlugin::CreateGUI()
  59. {
  60. return NULL;
  61. }
  62. void SampleHoldPlugin::Execute()
  63. {
  64. // Just copy the data through.
  65. GetOutputBuf(0)->Zero();
  66. if (InputExists(0) && InputExists(1))
  67. {
  68. for (int i=0;i<m_HostInfo->BUFSIZE;i++)
  69. {
  70. float v = GetInput(0,i);
  71. float c = GetInput(1,i);
  72. if (c > 0.666)
  73. {
  74. if (!m_flag)
  75. {
  76. m_val = v;
  77. SetOutput(0,i,v);
  78. m_flag = 1;
  79. }
  80. else
  81. SetOutput(0,i,m_val);
  82. }
  83. else
  84. SetOutput(0,i,m_val);
  85. if (c < 0.333)
  86. {
  87. m_flag = 0;
  88. }
  89. }
  90. }
  91. }