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.

143 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. // 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. }
  68. }
  69. }
  70. void SplitSwitchPlugin::SetChans (int n) {
  71. // once to clear the connections with the current info
  72. UpdatePluginInfoWithHost();
  73. while (n > m_PluginInfo.NumOutputs - 1) {
  74. m_PluginInfo.NumOutputs++;
  75. char t[256];
  76. sprintf (t, "Out %d", n);
  77. m_PluginInfo.PortTips.push_back (t);
  78. AddOutput ();
  79. }
  80. while (n < m_PluginInfo.NumOutputs - 1) {
  81. vector<string>::iterator i = m_PluginInfo.PortTips.end ();
  82. m_PluginInfo.PortTips.erase (i--);
  83. RemoveOutput();
  84. m_PluginInfo.NumOutputs--;
  85. }
  86. // do the actual update
  87. UpdatePluginInfoWithHost ();
  88. }
  89. void SplitSwitchPlugin::Execute() {
  90. int n;
  91. int NumChans = m_PluginInfo.NumOutputs - 1;
  92. m_SwitchPos=(m_GUIArgs.Switch - 1) % (m_PluginInfo.NumOutputs - 1);
  93. for (n=1; n<m_PluginInfo.NumOutputs; n++) GetOutputBuf(n)->Zero();
  94. if (InputExists (2)) {
  95. for (n=0; n<m_HostInfo->BUFSIZE; n++) {
  96. if (InputExists (0)) {
  97. // Check the Switch Pos CV Value
  98. m_SwitchPos = int (GetInput (0, n)-1) % NumChans;
  99. }
  100. else if (InputExists (1)) {
  101. // Check the trigger CV value
  102. if (GetInput (1, n) < 0.01) {
  103. m_Triggered = false;
  104. }
  105. else {
  106. if (!m_Triggered) {
  107. m_Triggered = true;
  108. m_SwitchPos = (m_SwitchPos+1) % NumChans;
  109. }
  110. }
  111. }
  112. int o = m_SwitchPos+1;
  113. m_GUIArgs.Echo = o;
  114. SetOutput (0, n, o);
  115. SetOutput (o, n, GetInput (2, n));
  116. }
  117. }
  118. }
  119. void SplitSwitchPlugin::StreamOut (ostream &s) {
  120. s << m_Version << " " << m_PluginInfo.NumOutputs - 1 << " " << m_SwitchPos << " ";
  121. }
  122. void SplitSwitchPlugin::StreamIn (istream &s) {
  123. int Version, Chans, SwitchPos;
  124. s >> Version >> Chans >> SwitchPos;
  125. SetChans (Chans);
  126. m_SwitchPos = SwitchPos;
  127. }