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.

152 lines
3.7KB

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