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.3KB

  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 "MixSwitchPlugin.h"
  19. #include "MixSwitchPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include <stdio.h>
  22. #include "SpiralIcon.xpm"
  23. extern "C" {
  24. SpiralPlugin* SpiralPlugin_CreateInstance () { return new MixSwitchPlugin; }
  25. char** SpiralPlugin_GetIcon () { return SpiralIcon_xpm; }
  26. int SpiralPlugin_GetID () { return 126; }
  27. string SpiralPlugin_GetGroupName() { return "Maths/Logic"; }
  28. }
  29. ///////////////////////////////////////////////////////
  30. MixSwitchPlugin::MixSwitchPlugin () :
  31. m_SwitchPos (0),
  32. m_Triggered (false)
  33. {
  34. m_GUIArgs.Chans = 2;
  35. m_GUIArgs.Switch = 1;
  36. m_GUIArgs.Echo = 1;
  37. m_PluginInfo.Name = "MixSwitch";
  38. m_PluginInfo.Width = 80;
  39. m_PluginInfo.Height = 80;
  40. CreatePorts ();
  41. m_AudioCH->Register ("Chans", &m_GUIArgs.Chans);
  42. m_AudioCH->Register ("Switch", &m_GUIArgs.Switch);
  43. m_AudioCH->Register ("Echo", &m_GUIArgs.Echo, ChannelHandler::OUTPUT);
  44. }
  45. MixSwitchPlugin::~MixSwitchPlugin () {
  46. }
  47. PluginInfo &MixSwitchPlugin::Initialise (const HostInfo *Host) {
  48. return SpiralPlugin::Initialise (Host);
  49. }
  50. SpiralGUIType *MixSwitchPlugin::CreateGUI () {
  51. return new MixSwitchPluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  52. }
  53. void MixSwitchPlugin::ExecuteCommands () {
  54. if (m_AudioCH->IsCommandWaiting ()) {
  55. switch (m_AudioCH->GetCommand()) {
  56. case SETCHANS : SetChans (m_GUIArgs.Chans);
  57. break;
  58. }
  59. }
  60. }
  61. void MixSwitchPlugin::CreatePorts (int n, bool AddPorts) {
  62. int c;
  63. m_PluginInfo.NumInputs = 2 + n;
  64. m_PluginInfo.PortTips.push_back ("CV");
  65. m_PluginInfo.PortTips.push_back ("Clock");
  66. char t[256];
  67. for (c=1; c<=n; c++) {
  68. sprintf (t, "In %d", c);
  69. m_PluginInfo.PortTips.push_back (t);
  70. }
  71. m_PluginInfo.NumOutputs = 2;
  72. m_PluginInfo.PortTips.push_back ("CV");
  73. m_PluginInfo.PortTips.push_back ("Out");
  74. if (AddPorts) {
  75. for (c=0; c<m_PluginInfo.NumInputs; c++) AddInput();
  76. for (c=0; c<m_PluginInfo.NumOutputs; c++) AddOutput();
  77. }
  78. }
  79. void MixSwitchPlugin::SetChans (int n) {
  80. // once to clear the connections with the current info
  81. // do we need this????
  82. UpdatePluginInfoWithHost();
  83. // Things can get a bit confused deleting and adding inputs
  84. // so we just chuck away all the ports...
  85. RemoveAllInputs ();
  86. RemoveAllOutputs ();
  87. m_PluginInfo.NumInputs = 0;
  88. m_PluginInfo.NumOutputs = 0;
  89. m_PluginInfo.PortTips.clear ();
  90. // ... and then create some new ones
  91. CreatePorts (n, true);
  92. // do the actual update
  93. UpdatePluginInfoWithHost ();
  94. }
  95. void MixSwitchPlugin::Execute() {
  96. int n;
  97. float f;
  98. int NumChans = m_PluginInfo.NumInputs - 2;
  99. m_SwitchPos=(m_GUIArgs.Switch - 1) % (m_PluginInfo.NumInputs - 2);
  100. for (n=0; n<m_HostInfo->BUFSIZE; n++) {
  101. if (InputExists (0)) {
  102. // Check the Switch Pos CV Value
  103. m_SwitchPos = abs (int (GetInput (0, n) - 1)) % NumChans;
  104. }
  105. else if (InputExists (1)) {
  106. // Check the trigger CV value
  107. if (GetInput (1, n) < 0.01) {
  108. m_Triggered = false;
  109. }
  110. else {
  111. if (!m_Triggered) {
  112. m_Triggered = true;
  113. m_SwitchPos = (m_SwitchPos+1) % NumChans;
  114. }
  115. }
  116. }
  117. int o = m_SwitchPos+1;
  118. m_GUIArgs.Echo = o;
  119. SetOutput (0, n, o);
  120. o++;
  121. if (InputExists (o)) f=GetInput (o, n);
  122. else f=0.0;
  123. SetOutput (1, n, f);
  124. }
  125. }
  126. void MixSwitchPlugin::StreamOut (ostream &s) {
  127. s << m_Version << " " << m_PluginInfo.NumInputs - 2 << " " << m_SwitchPos << " ";
  128. }
  129. void MixSwitchPlugin::StreamIn (istream &s) {
  130. int Version, Chans, SwitchPos;
  131. s >> Version >> Chans >> SwitchPos;
  132. SetChans (Chans);
  133. m_SwitchPos = SwitchPos;
  134. }