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.

110 lines
3.0KB

  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 "ScopePlugin.h"
  19. #include "ScopePluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include "SpiralIcon.xpm"
  22. using namespace std;
  23. extern "C"
  24. {
  25. SpiralPlugin* SpiralPlugin_CreateInstance() { return new ScopePlugin; }
  26. char** SpiralPlugin_GetIcon() { return SpiralIcon_xpm; }
  27. int SpiralPlugin_GetID() { return 0x0001; }
  28. string SpiralPlugin_GetGroupName() { return "InputOutput"; }
  29. }
  30. ///////////////////////////////////////////////////////
  31. ScopePlugin::ScopePlugin():
  32. m_DataReady(false),
  33. m_DataSize(0)
  34. {
  35. m_PluginInfo.Name = "Scope";
  36. m_PluginInfo.Width = 260;
  37. m_PluginInfo.Height = 115;
  38. m_PluginInfo.NumInputs = 1;
  39. m_PluginInfo.NumOutputs = 1;
  40. m_PluginInfo.PortTips.push_back("Input");
  41. m_PluginInfo.PortTips.push_back("Output");
  42. m_AudioCH->Register ("DataReady", &m_DataReady, ChannelHandler::OUTPUT);
  43. m_AudioCH->Register ("DataSizeChanged", &m_DataSizeChanged, ChannelHandler::OUTPUT);
  44. m_AudioCH->Register ("DataSize", &m_DataSize, ChannelHandler::OUTPUT);
  45. }
  46. ScopePlugin::~ScopePlugin()
  47. {
  48. }
  49. PluginInfo &ScopePlugin::Initialise(const HostInfo *Host)
  50. {
  51. PluginInfo& Info = SpiralPlugin::Initialise(Host);
  52. m_DataSize = m_HostInfo->BUFSIZE;
  53. m_Data = new float[m_DataSize];
  54. m_AudioCH->RegisterData("AudioData",ChannelHandler::OUTPUT,m_Data,m_DataSize*sizeof(float));
  55. return Info;
  56. }
  57. SpiralGUIType *ScopePlugin::CreateGUI()
  58. {
  59. return new ScopePluginGUI(m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  60. }
  61. void ScopePlugin::Reset()
  62. {
  63. ResetPorts();
  64. m_DataReady = false;
  65. delete m_Data;
  66. m_DataSize = m_HostInfo->BUFSIZE;
  67. m_Data = new float[m_DataSize];
  68. m_DataSizeChanged = true;
  69. }
  70. void ScopePlugin::Execute() {
  71. // Just copy the data through.
  72. m_DataReady = InputExists (0);
  73. if (GetOutputBuf (0)) GetOutputBuf (0)->Zero();
  74. if (m_DataReady) {
  75. GetOutputBuf (0)->Mix (*GetInput(0), 0);
  76. memcpy (m_Data, GetInput (0)->GetBuffer (), m_DataSize * sizeof (float));
  77. }
  78. }
  79. void ScopePlugin::ExecuteCommands()
  80. {
  81. if (m_AudioCH->IsCommandWaiting())
  82. {
  83. switch (m_AudioCH->GetCommand()) {
  84. case UPDATEDATASIZE :
  85. {
  86. m_AudioCH->ReplaceData("AudioData", m_Data, m_DataSize*sizeof(float));
  87. m_DataSizeChanged = false;
  88. }
  89. break;
  90. default:
  91. {
  92. }
  93. }
  94. }
  95. }