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.

106 lines
2.2KB

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