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.

153 lines
4.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 "SplitSwitchPlugin.h"
  19. #include "SplitSwitchPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include <stdio.h>
  22. #include "SpiralIcon.xpm"
  23. using namespace std;
  24. extern "C" {
  25. SpiralPlugin* SpiralPlugin_CreateInstance () { return new SplitSwitchPlugin; }
  26. char** SpiralPlugin_GetIcon () { return SpiralIcon_xpm; }
  27. int SpiralPlugin_GetID () { return 125; }
  28. string SpiralPlugin_GetGroupName() { return "Maths/Logic"; }
  29. }
  30. ///////////////////////////////////////////////////////
  31. SplitSwitchPlugin::SplitSwitchPlugin () :
  32. m_SwitchPos (0),
  33. m_Triggered (false)
  34. {
  35. m_GUIArgs.Chans = 2;
  36. m_GUIArgs.Switch = 1;
  37. m_GUIArgs.Echo = 1;
  38. m_PluginInfo.Name = "SplitSwitch";
  39. m_PluginInfo.Width = 80;
  40. m_PluginInfo.Height = 80;
  41. m_PluginInfo.NumInputs = 3;
  42. m_PluginInfo.NumOutputs = 3;
  43. m_PluginInfo.PortTips.push_back ("CV");
  44. m_PluginInfo.PortTips.push_back ("Clock");
  45. m_PluginInfo.PortTips.push_back ("In");
  46. m_PluginInfo.PortTips.push_back ("CV");
  47. m_PluginInfo.PortTips.push_back ("Out 1");
  48. m_PluginInfo.PortTips.push_back ("Out 2");
  49. // Number of channels <- GUI
  50. m_AudioCH->Register ("Chans", &m_GUIArgs.Chans);
  51. // Switch Position <- GUI
  52. m_AudioCH->Register ("Switch", &m_GUIArgs.Switch);
  53. // Switch Position -> GUI
  54. m_AudioCH->Register ("Echo", &m_GUIArgs.Echo, ChannelHandler::OUTPUT);
  55. // Auto Mode (Switch position is controlled by CV or Clock = True, Switch Position controlled by GUI = False
  56. m_AudioCH->Register ("Auto", &m_GUIArgs.Auto, ChannelHandler::OUTPUT);
  57. }
  58. SplitSwitchPlugin::~SplitSwitchPlugin () {
  59. }
  60. PluginInfo &SplitSwitchPlugin::Initialise (const HostInfo *Host) {
  61. return SpiralPlugin::Initialise (Host);
  62. }
  63. SpiralGUIType *SplitSwitchPlugin::CreateGUI () {
  64. return new SplitSwitchPluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  65. }
  66. void SplitSwitchPlugin::ExecuteCommands () {
  67. if (m_AudioCH->IsCommandWaiting ()) {
  68. switch (m_AudioCH->GetCommand()) {
  69. case (SETCHANS) : SetChans (m_GUIArgs.Chans);
  70. break;
  71. }
  72. }
  73. }
  74. void SplitSwitchPlugin::SetChans (int n) {
  75. // once to clear the connections with the current info
  76. UpdatePluginInfoWithHost();
  77. while (n > m_PluginInfo.NumOutputs - 1) {
  78. m_PluginInfo.NumOutputs++;
  79. char t[256];
  80. sprintf (t, "Out %d", n);
  81. m_PluginInfo.PortTips.push_back (t);
  82. AddOutput ();
  83. }
  84. while (n < m_PluginInfo.NumOutputs - 1) {
  85. vector<string>::iterator i = m_PluginInfo.PortTips.end ();
  86. m_PluginInfo.PortTips.erase (i--);
  87. RemoveOutput();
  88. m_PluginInfo.NumOutputs--;
  89. }
  90. // do the actual update
  91. UpdatePluginInfoWithHost ();
  92. }
  93. void SplitSwitchPlugin::Execute() {
  94. int n;
  95. int NumChans = m_PluginInfo.NumOutputs - 1;
  96. for (n=1; n<m_PluginInfo.NumOutputs; n++) GetOutputBuf(n)->Zero();
  97. if (InputExists (2)) {
  98. for (n=0; n<m_HostInfo->BUFSIZE; n++) {
  99. if (InputExists (0)) {
  100. m_GUIArgs.Auto = true;
  101. // Check the Switch Pos CV Value
  102. m_SwitchPos = int (GetInput (0, n));
  103. }
  104. else if (InputExists (1)) {
  105. m_GUIArgs.Auto = true;
  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);
  114. }
  115. }
  116. }
  117. else {
  118. m_GUIArgs.Auto = false;
  119. m_SwitchPos=(m_GUIArgs.Switch);
  120. }
  121. if (m_SwitchPos > NumChans) m_SwitchPos = 1;
  122. m_GUIArgs.Echo = m_SwitchPos;
  123. SetOutput (0, n, m_SwitchPos);
  124. SetOutput (m_SwitchPos, n, GetInput (2, n));
  125. }
  126. }
  127. }
  128. void SplitSwitchPlugin::StreamOut (ostream &s) {
  129. s << m_Version << " " << m_PluginInfo.NumOutputs - 1 << " " << m_SwitchPos << " ";
  130. }
  131. void SplitSwitchPlugin::StreamIn (istream &s) {
  132. int Version, Chans, SwitchPos;
  133. s >> Version >> Chans >> SwitchPos;
  134. SetChans (Chans);
  135. m_SwitchPos = SwitchPos;
  136. }