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.

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