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.

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