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.

154 lines
3.8KB

  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 "StereoMixerPlugin.h"
  19. #include "StereoMixerPluginGUI.h"
  20. #include <FL/Fl_Button.H>
  21. #include "SpiralIcon.xpm"
  22. using namespace std;
  23. extern "C" {
  24. SpiralPlugin* SpiralPlugin_CreateInstance()
  25. {
  26. return new StereoMixerPlugin;
  27. }
  28. char** SpiralPlugin_GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int SpiralPlugin_GetID()
  33. {
  34. return 0x0008;
  35. }
  36. string SpiralPlugin_GetGroupName()
  37. {
  38. return "Amps/Mixers";
  39. }
  40. }
  41. ///////////////////////////////////////////////////////
  42. StereoMixerPlugin::StereoMixerPlugin()
  43. {
  44. m_PluginInfo.Name="Stereo Mixer";
  45. m_PluginInfo.Width=190;
  46. m_PluginInfo.Height=175;
  47. m_PluginInfo.NumInputs=8;
  48. m_PluginInfo.NumOutputs=2;
  49. m_PluginInfo.PortTips.push_back("Input one");
  50. m_PluginInfo.PortTips.push_back("Input two");
  51. m_PluginInfo.PortTips.push_back("Input three");
  52. m_PluginInfo.PortTips.push_back("Input four");
  53. m_PluginInfo.PortTips.push_back("Pan CV one");
  54. m_PluginInfo.PortTips.push_back("Pan CV two");
  55. m_PluginInfo.PortTips.push_back("Pan CV three");
  56. m_PluginInfo.PortTips.push_back("Pan CV four");
  57. m_PluginInfo.PortTips.push_back("Output left");
  58. m_PluginInfo.PortTips.push_back("Output right");
  59. for (int n=0; n<NUM_CHANNELS; n++)
  60. {
  61. m_ChannelVal[n]=1.0f;
  62. m_Pan[n]=0.5f;
  63. }
  64. m_AudioCH->Register("Num",&m_GUIArgs.Num);
  65. m_AudioCH->Register("Value",&m_GUIArgs.Value);
  66. }
  67. StereoMixerPlugin::~StereoMixerPlugin()
  68. {
  69. }
  70. PluginInfo &StereoMixerPlugin::Initialise(const HostInfo *Host)
  71. {
  72. return SpiralPlugin::Initialise(Host);
  73. }
  74. SpiralGUIType *StereoMixerPlugin::CreateGUI()
  75. {
  76. return new StereoMixerPluginGUI(m_PluginInfo.Width,
  77. m_PluginInfo.Height,
  78. this,m_AudioCH,m_HostInfo);
  79. }
  80. void StereoMixerPlugin::Execute()
  81. {
  82. float Pan[4];
  83. // Mix the inputs
  84. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  85. {
  86. Pan[0]=m_Pan[0];
  87. Pan[1]=m_Pan[1];
  88. Pan[2]=m_Pan[2];
  89. Pan[3]=m_Pan[3];
  90. if (InputExists(0)) Pan[0]+=GetInput(4,n)*0.5;
  91. if (InputExists(1)) Pan[1]+=GetInput(5,n)*0.5;
  92. if (InputExists(2)) Pan[2]+=GetInput(6,n)*0.5;
  93. if (InputExists(3)) Pan[3]+=GetInput(7,n)*0.5;
  94. SetOutput(0,n,(GetInput(0,n)*m_ChannelVal[0])*Pan[0]+
  95. (GetInput(1,n)*m_ChannelVal[1])*Pan[1]+
  96. (GetInput(2,n)*m_ChannelVal[2])*Pan[2]+
  97. (GetInput(3,n)*m_ChannelVal[3])*Pan[3]);
  98. SetOutput(1,n,(GetInput(0,n)*m_ChannelVal[0])*(1-Pan[0])+
  99. (GetInput(1,n)*m_ChannelVal[1])*(1-Pan[1])+
  100. (GetInput(2,n)*m_ChannelVal[2])*(1-Pan[2])+
  101. (GetInput(3,n)*m_ChannelVal[3])*(1-Pan[3]));
  102. }
  103. }
  104. void StereoMixerPlugin::ExecuteCommands()
  105. {
  106. if (m_AudioCH->IsCommandWaiting())
  107. {
  108. switch (m_AudioCH->GetCommand())
  109. {
  110. case (SETCH) : SetChannel(m_GUIArgs.Num,m_GUIArgs.Value); break;
  111. case (SETPAN) : SetPan(m_GUIArgs.Num,m_GUIArgs.Value); break;
  112. }
  113. }
  114. }
  115. void StereoMixerPlugin::StreamOut(ostream &s)
  116. {
  117. s<<m_Version<<" ";
  118. for (int n=0; n<NUM_CHANNELS; n++)
  119. {
  120. s<<m_ChannelVal[n]<<" "<<m_Pan[n]<<" ";
  121. }
  122. }
  123. void StereoMixerPlugin::StreamIn(istream &s)
  124. {
  125. int version;
  126. s>>version;
  127. for (int n=0; n<NUM_CHANNELS; n++)
  128. {
  129. s>>m_ChannelVal[n]>>m_Pan[n];
  130. }
  131. }