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.

141 lines
4.2KB

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