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.

163 lines
3.1KB

  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 "FlipflopPlugin.h"
  19. #include "FlipflopPluginGUI.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 FlipflopPlugin;
  28. }
  29. char** SpiralPlugin_GetIcon()
  30. {
  31. return SpiralIcon_xpm;
  32. }
  33. int SpiralPlugin_GetID()
  34. {
  35. return 46;
  36. }
  37. string SpiralPlugin_GetGroupName()
  38. {
  39. return "Maths/Logic";
  40. }
  41. }
  42. ///////////////////////////////////////////////////////
  43. FlipflopPlugin::FlipflopPlugin() :
  44. m_TriggerTime(0.01f),
  45. m_Monostable(false),
  46. m_Current(0),
  47. m_Triggered(false),
  48. m_CurrentLevel(1.0f),
  49. m_TriggerSamples(0)
  50. {
  51. m_Version = 2;
  52. m_PluginInfo.Name="Flipflop";
  53. m_PluginInfo.Width=80;
  54. m_PluginInfo.Height=100;
  55. m_PluginInfo.NumInputs=1;
  56. m_PluginInfo.NumOutputs=1;
  57. m_PluginInfo.PortTips.push_back("Input");
  58. m_PluginInfo.PortTips.push_back("Output");
  59. m_AudioCH->Register("TriggerTime",&m_TriggerTime);
  60. m_AudioCH->Register("Monostable",&m_Monostable);
  61. }
  62. FlipflopPlugin::~FlipflopPlugin()
  63. {
  64. }
  65. PluginInfo &FlipflopPlugin::Initialise(const HostInfo *Host)
  66. {
  67. return SpiralPlugin::Initialise(Host);
  68. }
  69. SpiralGUIType *FlipflopPlugin::CreateGUI()
  70. {
  71. return new FlipflopPluginGUI(m_PluginInfo.Width,
  72. m_PluginInfo.Height,
  73. this,m_AudioCH,m_HostInfo);
  74. }
  75. void FlipflopPlugin::Execute()
  76. {
  77. bool Triggered;
  78. if (m_Monostable)
  79. {
  80. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  81. {
  82. if (GetInput(0,n)>0)
  83. {
  84. if(!m_Triggered)
  85. {
  86. m_Triggered=true;
  87. m_CurrentLevel=1.0f;
  88. m_TriggerSamples=(int)(m_TriggerTime*m_HostInfo->SAMPLERATE)+1;
  89. }
  90. }
  91. else
  92. {
  93. m_Triggered=false;
  94. }
  95. if (m_TriggerSamples<=0)
  96. {
  97. m_CurrentLevel=-1.0f;
  98. }
  99. if (m_TriggerSamples>0) m_TriggerSamples--;
  100. SetOutput(0,n,m_CurrentLevel);
  101. }
  102. }
  103. else
  104. {
  105. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  106. {
  107. if (GetInput(0,n)>0)
  108. {
  109. if(!m_Triggered)
  110. {
  111. m_Triggered=true;
  112. m_CurrentLevel=-m_CurrentLevel;
  113. }
  114. }
  115. else
  116. {
  117. if (m_Triggered)
  118. {
  119. m_Triggered=false;
  120. }
  121. }
  122. SetOutput(0,n,m_CurrentLevel);
  123. }
  124. }
  125. }
  126. void FlipflopPlugin::ExecuteCommands()
  127. {
  128. }
  129. void FlipflopPlugin::StreamOut(ostream &s)
  130. {
  131. s<<m_Version<<" ";
  132. s<<m_TriggerTime<<" "<<m_Monostable<<" "<<endl;
  133. }
  134. void FlipflopPlugin::StreamIn(istream &s)
  135. {
  136. int version;
  137. s>>version;
  138. if (version>1)
  139. {
  140. s>>m_TriggerTime>>m_Monostable;
  141. }
  142. }