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.

108 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::Execute()
  68. {
  69. // Just copy the data through.
  70. GetOutputBuf(0)->Zero();
  71. if (InputExists(0) && InputExists(1))
  72. {
  73. for (int i=0;i<m_HostInfo->BUFSIZE;i++)
  74. {
  75. float v = GetInput(0,i);
  76. float c = GetInput(1,i);
  77. if (c > 0.666)
  78. {
  79. if (!m_flag)
  80. {
  81. m_val = v;
  82. SetOutput(0,i,v);
  83. m_flag = 1;
  84. }
  85. else
  86. SetOutput(0,i,m_val);
  87. }
  88. else
  89. SetOutput(0,i,m_val);
  90. if (c < 0.333)
  91. {
  92. m_flag = 0;
  93. }
  94. }
  95. }
  96. }