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.

163 lines
5.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() { return new MixerPlugin; }
  26. char** SpiralPlugin_GetIcon() { return SpiralIcon_xpm; }
  27. int SpiralPlugin_GetID() { return 0x0007; }
  28. string SpiralPlugin_GetGroupName() { return "Amps/Mixers"; }
  29. }
  30. ///////////////////////////////////////////////////////
  31. MixerPlugin::MixerPlugin() :
  32. m_NumChannels(4)
  33. {
  34. int c;
  35. m_Version = 2;
  36. m_PluginInfo.Name = "Mixer";
  37. m_PluginInfo.Width = 80;
  38. m_PluginInfo.Height = 150;
  39. for (c=0; c<MAX_CHANNELS; c++) {
  40. m_ChannelVal[c] = 1.0f;
  41. m_GUIArgs.inPeak[c] = false;
  42. }
  43. m_GUIArgs.Peak = false;
  44. m_PluginInfo.NumInputs = m_NumChannels;
  45. m_PluginInfo.NumOutputs = 1;
  46. for (c=1; c<=m_NumChannels; c++) AddInputTip (c);
  47. m_PluginInfo.PortTips.push_back ("Output");
  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. m_AudioCH->RegisterData ("inPeak", ChannelHandler::OUTPUT, m_GUIArgs.inPeak, MAX_CHANNELS * sizeof (bool));
  52. }
  53. MixerPlugin::~MixerPlugin() {
  54. }
  55. void MixerPlugin::AddInputTip (int Channel) {
  56. char t[256];
  57. sprintf (t, "Input %d", Channel);
  58. m_PluginInfo.PortTips.push_back (t);
  59. }
  60. PluginInfo &MixerPlugin::Initialise (const HostInfo *Host) {
  61. return SpiralPlugin::Initialise (Host);
  62. }
  63. SpiralGUIType *MixerPlugin::CreateGUI() {
  64. return new MixerPluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  65. }
  66. void MixerPlugin::Execute () {
  67. // Mix the inputs
  68. for (int n=0; n<m_HostInfo->BUFSIZE; n++) {
  69. float in, out = 0.0;
  70. for (int c=0; c<m_NumChannels; c++) {
  71. in = GetInput (c, n) * m_ChannelVal[c];
  72. m_GUIArgs.inPeak[c] = (in > 1.0);
  73. out += in;
  74. }
  75. SetOutput (0, n, out);
  76. m_GUIArgs.Peak = (out > 1.0);
  77. }
  78. }
  79. void MixerPlugin::ExecuteCommands() {
  80. if (m_AudioCH->IsCommandWaiting()) {
  81. switch (m_AudioCH->GetCommand()) {
  82. case SETMIX:
  83. m_ChannelVal[m_GUIArgs.Num] = m_GUIArgs.Value;
  84. break;
  85. case ADDCHAN:
  86. AddChannel ();
  87. break;
  88. case REMOVECHAN:
  89. RemoveChannel ();
  90. break;
  91. }
  92. }
  93. }
  94. void MixerPlugin::SetChannels (int num) {
  95. // This is only used on loading, so we don't care that it clears all the inputs first
  96. UpdatePluginInfoWithHost(); // once to clear the connections with the current info
  97. RemoveAllInputs();
  98. m_PluginInfo.PortTips.clear ();
  99. m_PluginInfo.NumInputs = num;
  100. m_NumChannels = num;
  101. for (int c=1; c<=m_NumChannels; c++) {
  102. AddInput ();
  103. AddInputTip (c);
  104. }
  105. m_PluginInfo.PortTips.push_back ("Output");
  106. UpdatePluginInfoWithHost (); // do the actual update
  107. }
  108. void MixerPlugin::AddChannel (void) {
  109. UpdatePluginInfoWithHost(); // once to clear the connections with the current info
  110. m_PluginInfo.NumInputs++;
  111. m_NumChannels++;
  112. AddInput ();
  113. vector<std::string>::iterator i = m_PluginInfo.PortTips.end();
  114. m_PluginInfo.PortTips.erase (--i);
  115. AddInputTip (m_NumChannels);
  116. m_PluginInfo.PortTips.push_back ("Output");
  117. UpdatePluginInfoWithHost (); // do the actual update
  118. }
  119. void MixerPlugin::RemoveChannel (void) {
  120. UpdatePluginInfoWithHost(); // once to clear the connections with the current info
  121. m_PluginInfo.NumInputs--;
  122. m_NumChannels--;
  123. vector<std::string>::iterator i = m_PluginInfo.PortTips.end();
  124. m_PluginInfo.PortTips.erase (--i);
  125. m_PluginInfo.PortTips.erase (--i);
  126. m_PluginInfo.PortTips.push_back ("Output");
  127. RemoveInput();
  128. UpdatePluginInfoWithHost (); // do the actual update
  129. }
  130. void MixerPlugin::StreamOut (ostream &s) {
  131. s << m_Version << " ";
  132. s << m_NumChannels << " ";
  133. for (int n=0; n<m_NumChannels; n++) s << m_ChannelVal[n] << " ";
  134. }
  135. void MixerPlugin::StreamIn (istream &s) {
  136. int version, chans;
  137. s >> version;
  138. switch (version) {
  139. case 1: // needs default number of channels
  140. break;
  141. case 2: s >> chans;
  142. SetChannels (chans);
  143. break;
  144. }
  145. for (int n=0; n<m_NumChannels; n++) s >> m_ChannelVal[n];
  146. }