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.

172 lines
3.3KB

  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::Reset()
  76. {
  77. ResetPorts();
  78. m_Current = 0;
  79. m_Triggered = false;
  80. m_CurrentLevel = 1.0f;
  81. m_TriggerSamples = 0;
  82. }
  83. void FlipflopPlugin::Execute()
  84. {
  85. bool Triggered;
  86. if (m_Monostable)
  87. {
  88. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  89. {
  90. if (GetInput(0,n)>0)
  91. {
  92. if(!m_Triggered)
  93. {
  94. m_Triggered=true;
  95. m_CurrentLevel=1.0f;
  96. m_TriggerSamples=(int)(m_TriggerTime*m_HostInfo->SAMPLERATE)+1;
  97. }
  98. }
  99. else
  100. {
  101. m_Triggered=false;
  102. }
  103. if (m_TriggerSamples<=0)
  104. {
  105. m_CurrentLevel=-1.0f;
  106. }
  107. if (m_TriggerSamples>0) m_TriggerSamples--;
  108. SetOutput(0,n,m_CurrentLevel);
  109. }
  110. }
  111. else
  112. {
  113. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  114. {
  115. if (GetInput(0,n)>0)
  116. {
  117. if(!m_Triggered)
  118. {
  119. m_Triggered=true;
  120. m_CurrentLevel=-m_CurrentLevel;
  121. }
  122. }
  123. else
  124. {
  125. if (m_Triggered)
  126. {
  127. m_Triggered=false;
  128. }
  129. }
  130. SetOutput(0,n,m_CurrentLevel);
  131. }
  132. }
  133. }
  134. void FlipflopPlugin::ExecuteCommands()
  135. {
  136. }
  137. void FlipflopPlugin::StreamOut(ostream &s)
  138. {
  139. s<<m_Version<<" ";
  140. s<<m_TriggerTime<<" "<<m_Monostable<<" "<<endl;
  141. }
  142. void FlipflopPlugin::StreamIn(istream &s)
  143. {
  144. int version;
  145. s>>version;
  146. if (version>1)
  147. {
  148. s>>m_TriggerTime>>m_Monostable;
  149. }
  150. }