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.

120 lines
3.3KB

  1. /* SpiralSound
  2. * Copyleft (C) 2002 Andy Preston <andy@clublinux.co.uk>
  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 "MeterPlugin.h"
  19. #include "MeterPluginGUI.h"
  20. #include "SpiralIcon.xpm"
  21. #include <stdio.h>
  22. using namespace std;
  23. extern "C" {
  24. SpiralPlugin* SpiralPlugin_CreateInstance() { return new MeterPlugin; }
  25. char** SpiralPlugin_GetIcon() { return SpiralIcon_xpm; }
  26. int SpiralPlugin_GetID() { return 123; }
  27. string SpiralPlugin_GetGroupName() { return "InputOutput"; }
  28. }
  29. MeterPlugin::MeterPlugin():
  30. m_Data (NULL),
  31. m_DataSize (0),
  32. m_DataReady (false),
  33. m_VUMode (true)
  34. {
  35. m_PluginInfo.Name = "Meter";
  36. m_PluginInfo.Width = 230;
  37. m_PluginInfo.Height = 128;
  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. m_Version = 1;
  46. }
  47. MeterPlugin::~MeterPlugin() {
  48. if (m_Data != NULL) delete m_Data;
  49. }
  50. PluginInfo &MeterPlugin::Initialise (const HostInfo *Host) {
  51. PluginInfo& Info = SpiralPlugin::Initialise (Host);
  52. m_DataSize = Host->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 *MeterPlugin::CreateGUI() {
  58. return new MeterPluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  59. }
  60. void MeterPlugin::Reset()
  61. {
  62. ResetPorts();
  63. m_DataReady = false;
  64. delete m_Data;
  65. m_DataSize = m_HostInfo->BUFSIZE;
  66. m_Data = new float[m_DataSize];
  67. m_DataSizeChanged = true;
  68. }
  69. void MeterPlugin::Execute() {
  70. // Just copy the data through.
  71. m_DataReady = InputExists (0);
  72. if (GetOutputBuf (0)) GetOutputBuf (0)->Zero();
  73. if (m_DataReady) {
  74. GetOutputBuf (0)->Mix (*GetInput(0), 0);
  75. memcpy (m_Data, GetInput (0)->GetBuffer (), m_DataSize * sizeof (float));
  76. }
  77. }
  78. void MeterPlugin::ExecuteCommands () {
  79. if (m_AudioCH->IsCommandWaiting ()) {
  80. switch (m_AudioCH->GetCommand()) {
  81. case UPDATEDATASIZE :
  82. {
  83. m_AudioCH->ReplaceData("AudioData", m_Data, m_DataSize*sizeof(float));
  84. m_DataSizeChanged = false;
  85. }
  86. break;
  87. case (SETVU) : m_VUMode = true;
  88. break;
  89. case (SETMM) : m_VUMode = false;
  90. break;
  91. }
  92. }
  93. }
  94. void MeterPlugin::StreamOut (ostream &s) {
  95. s << m_Version << " " << m_VUMode << " ";
  96. }
  97. void MeterPlugin::StreamIn (istream &s) {
  98. int Version;
  99. s >> Version;
  100. s >> m_VUMode;
  101. }