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.

149 lines
4.2KB

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