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.

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