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.

147 lines
3.6KB

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