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.

100 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 "EnvFollowerPlugin.h"
  19. #include "EnvFollowerPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include "SpiralIcon.xpm"
  22. extern "C" {
  23. SpiralPlugin* CreateInstance()
  24. {
  25. return new EnvFollowerPlugin;
  26. }
  27. char** GetIcon()
  28. {
  29. return SpiralIcon_xpm;
  30. }
  31. int GetID()
  32. {
  33. return 0x0013;
  34. }
  35. }
  36. ///////////////////////////////////////////////////////
  37. EnvFollowerPlugin::EnvFollowerPlugin() :
  38. m_Attack(0.5),
  39. m_Decay(0.5),
  40. m_Value(0)
  41. {
  42. m_PluginInfo.Name="EnvFollower";
  43. m_PluginInfo.Width=140;
  44. m_PluginInfo.Height=100;
  45. m_PluginInfo.NumInputs=1;
  46. m_PluginInfo.NumOutputs=1;
  47. m_PluginInfo.PortTips.push_back("Input");
  48. m_PluginInfo.PortTips.push_back("Output");
  49. m_AudioCH->Register("Attack",&m_Attack);
  50. m_AudioCH->Register("Decay",&m_Decay);
  51. }
  52. EnvFollowerPlugin::~EnvFollowerPlugin()
  53. {
  54. }
  55. PluginInfo &EnvFollowerPlugin::Initialise(const HostInfo *Host)
  56. {
  57. return SpiralPlugin::Initialise(Host);
  58. }
  59. SpiralGUIType *EnvFollowerPlugin::CreateGUI()
  60. {
  61. return new EnvFollowerPluginGUI(m_PluginInfo.Width,
  62. m_PluginInfo.Height,
  63. this,m_AudioCH,m_HostInfo);
  64. }
  65. void EnvFollowerPlugin::Execute()
  66. {
  67. float Value;
  68. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  69. {
  70. Value = fabs(GetInput(0,n));
  71. if (Value>m_Value) m_Value+=(m_Attack*100);
  72. else m_Value-=(m_Decay*100);
  73. SetOutput(0,n,m_Value);
  74. }
  75. }
  76. void EnvFollowerPlugin::StreamOut(ostream &s)
  77. {
  78. s<<m_Version<<" ";
  79. s<<m_Attack<<" "<<m_Decay;
  80. }
  81. void EnvFollowerPlugin::StreamIn(istream &s)
  82. {
  83. s>>m_Version;
  84. s>>m_Attack>>m_Decay;
  85. }