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.

132 lines
2.6KB

  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 "TrigPlugin.h"
  19. #include "TrigPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include "SpiralIcon.xpm"
  22. #include "../../NoteTable.h"
  23. using namespace std;
  24. static const float PI=3.141592654;
  25. static const float RAD=(PI/180)*360;
  26. extern "C" {
  27. SpiralPlugin* SpiralPlugin_CreateInstance()
  28. {
  29. return new TrigPlugin;
  30. }
  31. char** SpiralPlugin_GetIcon()
  32. {
  33. return SpiralIcon_xpm;
  34. }
  35. int SpiralPlugin_GetID()
  36. {
  37. return 53;
  38. }
  39. string SpiralPlugin_GetGroupName()
  40. {
  41. return "Maths/Logic";
  42. }
  43. }
  44. ///////////////////////////////////////////////////////
  45. TrigPlugin::TrigPlugin() :
  46. m_Operator(SIN)
  47. {
  48. m_Version=1;
  49. m_PluginInfo.Name="Trig";
  50. m_PluginInfo.Width=80;
  51. m_PluginInfo.Height=80;
  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("Operator",(int*)&m_Operator);
  57. }
  58. TrigPlugin::~TrigPlugin()
  59. {
  60. }
  61. PluginInfo &TrigPlugin::Initialise(const HostInfo *Host)
  62. {
  63. return SpiralPlugin::Initialise(Host);
  64. }
  65. SpiralGUIType *TrigPlugin::CreateGUI()
  66. {
  67. return new TrigPluginGUI(m_PluginInfo.Width,
  68. m_PluginInfo.Height,
  69. this,m_AudioCH,m_HostInfo);
  70. }
  71. void TrigPlugin::Execute()
  72. {
  73. float Freq=0, OldFreq=0;
  74. switch (m_Operator)
  75. {
  76. case SIN :
  77. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  78. {
  79. SetOutput(0,n,sin(GetInput(0,n)*RAD));
  80. }
  81. break;
  82. case COS :
  83. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  84. {
  85. SetOutput(0,n,cos(GetInput(0,n)*RAD));
  86. }
  87. break;
  88. case TAN :
  89. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  90. {
  91. SetOutput(0,n,tan(GetInput(0,n)*RAD));
  92. }
  93. break;
  94. default: break;
  95. }
  96. }
  97. void TrigPlugin::ExecuteCommands()
  98. {
  99. }
  100. void TrigPlugin::StreamOut(ostream &s)
  101. {
  102. s<<m_Version<<endl;
  103. s<<(int)m_Operator<<" ";
  104. }
  105. void TrigPlugin::StreamIn(istream &s)
  106. {
  107. int version;
  108. s>>version;
  109. int t;
  110. s>>t;
  111. m_Operator=(OperatorType)t;
  112. }