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.

157 lines
4.4KB

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