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.

130 lines
2.5KB

  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 "CounterPlugin.h"
  19. #include "CounterPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include "SpiralIcon.xpm"
  22. #include "../../NoteTable.h"
  23. extern "C" {
  24. SpiralPlugin* SpiralPlugin_CreateInstance()
  25. {
  26. return new CounterPlugin;
  27. }
  28. char** SpiralPlugin_GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int SpiralPlugin_GetID()
  33. {
  34. return 45;
  35. }
  36. string SpiralPlugin_GetGroupName()
  37. {
  38. return "Maths/Logic";
  39. }
  40. }
  41. ///////////////////////////////////////////////////////
  42. CounterPlugin::CounterPlugin() :
  43. m_Count(4),
  44. m_Current(0),
  45. m_Triggered(false),
  46. m_CurrentLevel(1.0f)
  47. {
  48. m_PluginInfo.Name="Counter";
  49. m_PluginInfo.Width=60;
  50. m_PluginInfo.Height=50;
  51. m_PluginInfo.NumInputs=1;
  52. m_PluginInfo.NumOutputs=1;
  53. m_PluginInfo.PortTips.push_back("Input");
  54. m_PluginInfo.PortTips.push_back("Output");
  55. m_AudioCH->Register("Count",&m_Count);
  56. }
  57. CounterPlugin::~CounterPlugin()
  58. {
  59. }
  60. PluginInfo &CounterPlugin::Initialise(const HostInfo *Host)
  61. {
  62. return SpiralPlugin::Initialise(Host);
  63. }
  64. SpiralGUIType *CounterPlugin::CreateGUI()
  65. {
  66. return new CounterPluginGUI(m_PluginInfo.Width,
  67. m_PluginInfo.Height,
  68. this,m_AudioCH,m_HostInfo);
  69. }
  70. void CounterPlugin::Execute()
  71. {
  72. bool Triggered;
  73. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  74. {
  75. if (GetInput(0,n)>0)
  76. {
  77. if(!m_Triggered)
  78. {
  79. m_Triggered=true;
  80. m_Current++;
  81. }
  82. }
  83. else
  84. {
  85. if (m_Triggered)
  86. {
  87. m_Triggered=false;
  88. m_Current++;
  89. }
  90. }
  91. if (m_Current>=m_Count)
  92. {
  93. m_CurrentLevel=-m_CurrentLevel;
  94. m_Current=0;
  95. }
  96. SetOutput(0,n,m_CurrentLevel);
  97. }
  98. }
  99. void CounterPlugin::ExecuteCommands()
  100. {
  101. }
  102. void CounterPlugin::StreamOut(ostream &s)
  103. {
  104. s<<m_Version<<endl;
  105. s<<m_Count<<" "<<m_Current<<" ";
  106. }
  107. void CounterPlugin::StreamIn(istream &s)
  108. {
  109. int version;
  110. s>>version;
  111. s>>m_Count>>m_Current;
  112. }