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.

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