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.

152 lines
3.9KB

  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 <stdio.h>
  19. #include "MixerPlugin.h"
  20. #include "MixerPluginGUI.h"
  21. #include <FL/Fl_Button.h>
  22. #include "SpiralIcon.xpm"
  23. extern "C" {
  24. SpiralPlugin* CreateInstance()
  25. {
  26. return new MixerPlugin;
  27. }
  28. char** GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int GetID()
  33. {
  34. return 0x0007;
  35. }
  36. string GetGroupName()
  37. {
  38. return "SpiralSound";
  39. }
  40. }
  41. ///////////////////////////////////////////////////////
  42. MixerPlugin::MixerPlugin() :
  43. m_NumChannels(0)
  44. {
  45. m_Version = 2;
  46. m_PluginInfo.Name="Mixer";
  47. m_PluginInfo.Width=80;
  48. m_PluginInfo.Height=145;
  49. CreatePorts ();
  50. for (int n=0; n<MAX_CHANNELS; n++) m_ChannelVal[n]=1.0f;
  51. m_AudioCH->Register("Value", &m_GUIArgs.Value);
  52. m_AudioCH->Register("Num", &m_GUIArgs.Num);
  53. }
  54. MixerPlugin::~MixerPlugin()
  55. {
  56. }
  57. PluginInfo &MixerPlugin::Initialise(const HostInfo *Host)
  58. {
  59. return SpiralPlugin::Initialise(Host);
  60. }
  61. SpiralGUIType *MixerPlugin::CreateGUI()
  62. {
  63. return new MixerPluginGUI(m_PluginInfo.Width,
  64. m_PluginInfo.Height,
  65. this,m_AudioCH,m_HostInfo);
  66. }
  67. void MixerPlugin::Execute () {
  68. // Mix the inputs
  69. for (int n=0; n<m_HostInfo->BUFSIZE; n++) {
  70. float out = 0.0;
  71. for (int c=0; c<m_NumChannels; c++) out += (GetInput (c, n) * m_ChannelVal[c]);
  72. SetOutput (0, n, out);
  73. }
  74. }
  75. void MixerPlugin::ExecuteCommands() {
  76. if (m_AudioCH->IsCommandWaiting()) {
  77. switch (m_AudioCH->GetCommand()) {
  78. case SETCH:
  79. SetChannel (m_GUIArgs.Num, m_GUIArgs.Value);
  80. break;
  81. case SETNUM:
  82. SetChannels (m_GUIArgs.Num);
  83. break;
  84. }
  85. }
  86. }
  87. void MixerPlugin::SetChannels (int n) {
  88. // once to clear the connections with the current info
  89. // do we need this????
  90. UpdatePluginInfoWithHost();
  91. // Things can get a bit confused deleting and adding inputs
  92. // so we just chuck away all the ports...
  93. RemoveAllInputs ();
  94. RemoveAllOutputs ();
  95. m_PluginInfo.NumInputs = 0;
  96. m_PluginInfo.NumOutputs = 0;
  97. m_PluginInfo.PortTips.clear ();
  98. // ... and then create some new ones
  99. CreatePorts (n, true);
  100. // do the actual update
  101. UpdatePluginInfoWithHost ();
  102. }
  103. void MixerPlugin::CreatePorts (int n, bool AddPorts) {
  104. int c;
  105. m_PluginInfo.NumInputs = n;
  106. m_NumChannels = n;
  107. char t[256];
  108. for (c=1; c<=n; c++) {
  109. sprintf (t, "Input %d", c);
  110. m_PluginInfo.PortTips.push_back (t);
  111. }
  112. m_PluginInfo.NumOutputs = 1;
  113. m_PluginInfo.PortTips.push_back ("Output");
  114. if (AddPorts) {
  115. for (c=0; c<m_PluginInfo.NumInputs; c++) AddInput();
  116. for (c=0; c<m_PluginInfo.NumOutputs; c++) AddOutput();
  117. }
  118. }
  119. void MixerPlugin::StreamOut (ostream &s) {
  120. s << m_Version << " ";
  121. s << m_NumChannels << " ";
  122. for (int n=0; n<m_NumChannels; n++) s << m_ChannelVal[n] << " ";
  123. }
  124. void MixerPlugin::StreamIn (istream &s) {
  125. int version, chans;
  126. s >> version;
  127. switch (version) {
  128. case 1: SetChannels (4);
  129. break;
  130. case 2: s >> chans;
  131. SetChannels (chans);
  132. break;
  133. }
  134. for (int n=0; n<m_NumChannels; n++) s >> m_ChannelVal[n];
  135. }