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.

164 lines
4.8KB

  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. using namespace std;
  24. extern "C" {
  25. SpiralPlugin* SpiralPlugin_CreateInstance () { return new MixSwitchPlugin; }
  26. char** SpiralPlugin_GetIcon () { return SpiralIcon_xpm; }
  27. int SpiralPlugin_GetID () { return 126; }
  28. string SpiralPlugin_GetGroupName() { return "Maths/Logic"; }
  29. }
  30. ///////////////////////////////////////////////////////
  31. MixSwitchPlugin::MixSwitchPlugin () :
  32. m_SwitchPos (1),
  33. m_Triggered (false)
  34. {
  35. m_GUIArgs.Chans = 2;
  36. m_GUIArgs.Switch = 1;
  37. m_GUIArgs.Echo = 1;
  38. m_GUIArgs.Auto = false;
  39. m_PluginInfo.Name = "MixSwitch";
  40. m_PluginInfo.Width = 80;
  41. m_PluginInfo.Height = 80;
  42. CreatePorts ();
  43. // Number of channels <- GUI
  44. m_AudioCH->Register ("Chans", &m_GUIArgs.Chans);
  45. // Switch Position <- GUI
  46. m_AudioCH->Register ("Switch", &m_GUIArgs.Switch);
  47. // Switch Position -> GUI
  48. m_AudioCH->Register ("Echo", &m_GUIArgs.Echo, ChannelHandler::OUTPUT);
  49. // Auto Mode (Switch position is controlled by CV or Clock = True, Switch Position controlled by GUI = False
  50. m_AudioCH->Register ("Auto", &m_GUIArgs.Auto, ChannelHandler::OUTPUT);
  51. }
  52. MixSwitchPlugin::~MixSwitchPlugin () {
  53. }
  54. PluginInfo &MixSwitchPlugin::Initialise (const HostInfo *Host) {
  55. return SpiralPlugin::Initialise (Host);
  56. }
  57. SpiralGUIType *MixSwitchPlugin::CreateGUI () {
  58. return new MixSwitchPluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  59. }
  60. void MixSwitchPlugin::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 MixSwitchPlugin::CreatePorts (int n, bool AddPorts) {
  69. int c;
  70. m_PluginInfo.NumInputs = 2 + n;
  71. m_PluginInfo.PortTips.push_back ("CV");
  72. m_PluginInfo.PortTips.push_back ("Clock");
  73. char t[256];
  74. for (c=1; c<=n; c++) {
  75. sprintf (t, "In %d", c);
  76. m_PluginInfo.PortTips.push_back (t);
  77. }
  78. m_PluginInfo.NumOutputs = 2;
  79. m_PluginInfo.PortTips.push_back ("CV");
  80. m_PluginInfo.PortTips.push_back ("Out");
  81. if (AddPorts) {
  82. for (c=0; c<m_PluginInfo.NumInputs; c++) AddInput();
  83. for (c=0; c<m_PluginInfo.NumOutputs; c++) AddOutput();
  84. }
  85. }
  86. void MixSwitchPlugin::SetChans (int n) {
  87. // once to clear the connections with the current info
  88. // do we need this????
  89. UpdatePluginInfoWithHost();
  90. // Things can get a bit confused deleting and adding inputs
  91. // so we just chuck away all the ports...
  92. RemoveAllInputs ();
  93. RemoveAllOutputs ();
  94. m_PluginInfo.NumInputs = 0;
  95. m_PluginInfo.NumOutputs = 0;
  96. m_PluginInfo.PortTips.clear ();
  97. // ... and then create some new ones
  98. CreatePorts (n, true);
  99. // do the actual update
  100. UpdatePluginInfoWithHost ();
  101. }
  102. void MixSwitchPlugin::Execute() {
  103. float f;
  104. int p;
  105. int NumChans = m_PluginInfo.NumInputs - 2;
  106. for (int n=0; n<m_HostInfo->BUFSIZE; n++) {
  107. if (InputExists (0)) {
  108. m_GUIArgs.Auto = true;
  109. // Check the Switch Pos CV Value
  110. m_SwitchPos = int (GetInput (0, n));
  111. }
  112. else if (InputExists (1)) {
  113. m_GUIArgs.Auto = true;
  114. // Check the trigger CV value
  115. if (GetInput (1, n) < 0.01) {
  116. m_Triggered = false;
  117. }
  118. else {
  119. if (!m_Triggered) {
  120. m_Triggered = true;
  121. m_SwitchPos = m_SwitchPos + 1;
  122. }
  123. }
  124. }
  125. else {
  126. m_GUIArgs.Auto = false;
  127. m_SwitchPos = m_GUIArgs.Switch;
  128. }
  129. if (m_SwitchPos > NumChans) m_SwitchPos = 1;
  130. m_GUIArgs.Echo = m_SwitchPos;
  131. SetOutput (0, n, m_SwitchPos);
  132. p = m_SwitchPos + 1; // SwitchPos 1 = Port 2, and so on
  133. if (InputExists (p)) f=GetInput (p, n);
  134. else f=0.0;
  135. SetOutput (1, n, f);
  136. }
  137. }
  138. void MixSwitchPlugin::StreamOut (ostream &s) {
  139. s << m_Version << " " << m_PluginInfo.NumInputs - 2 << " " << m_SwitchPos << " ";
  140. }
  141. void MixSwitchPlugin::StreamIn (istream &s) {
  142. int Version, Chans, SwitchPos;
  143. s >> Version >> Chans >> SwitchPos;
  144. SetChans (Chans);
  145. m_SwitchPos = SwitchPos;
  146. }