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.

141 lines
2.7KB

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