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.

173 lines
3.9KB

  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 "SpiralLoopPlugin.h"
  19. #include "SpiralLoopPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include "SpiralIcon.xpm"
  22. #include "../../RiffWav.h"
  23. #include "../../NoteTable.h"
  24. static const float TRIG_THRESH = 0.1;
  25. static const int NOTETRIG = NUM_SAMPLES*2+1;
  26. extern "C" {
  27. SpiralPlugin* CreateInstance()
  28. {
  29. return new SpiralLoopPlugin;
  30. }
  31. char** GetIcon()
  32. {
  33. return SpiralIcon_xpm;
  34. }
  35. int GetID()
  36. {
  37. return 0x001a;
  38. }
  39. string GetGroupName()
  40. {
  41. return "SpiralSound";
  42. }
  43. }
  44. ///////////////////////////////////////////////////////
  45. SpiralLoopPlugin::SpiralLoopPlugin()
  46. {
  47. m_PluginInfo.Name="SpiralLoop";
  48. m_PluginInfo.Width=300;
  49. m_PluginInfo.Height=320;
  50. m_PluginInfo.NumInputs=2;
  51. m_PluginInfo.NumOutputs=9;
  52. m_PluginInfo.PortTips.push_back("Input");
  53. m_PluginInfo.PortTips.push_back("Play Trigger");
  54. m_PluginInfo.PortTips.push_back("Output");
  55. m_PluginInfo.PortTips.push_back("LoopTrigger 0");
  56. m_PluginInfo.PortTips.push_back("LoopTrigger 1");
  57. m_PluginInfo.PortTips.push_back("LoopTrigger 2");
  58. m_PluginInfo.PortTips.push_back("LoopTrigger 3");
  59. m_PluginInfo.PortTips.push_back("LoopTrigger 4");
  60. m_PluginInfo.PortTips.push_back("LoopTrigger 5");
  61. m_PluginInfo.PortTips.push_back("LoopTrigger 6");
  62. m_PluginInfo.PortTips.push_back("LoopTrigger 7");
  63. m_Loop = new Loop;
  64. m_Version=2;
  65. }
  66. SpiralLoopPlugin::~SpiralLoopPlugin()
  67. {
  68. }
  69. PluginInfo &SpiralLoopPlugin::Initialise(const HostInfo *Host)
  70. {
  71. return SpiralPlugin::Initialise(Host);
  72. }
  73. SpiralGUIType *SpiralLoopPlugin::CreateGUI()
  74. {
  75. m_GUI = new SpiralLoopPluginGUI(m_Loop, m_PluginInfo.Width,
  76. m_PluginInfo.Height,
  77. this,m_HostInfo);
  78. m_GUI->hide();
  79. return m_GUI;
  80. }
  81. void SpiralLoopPlugin::Execute()
  82. {
  83. if (InputExists(0)) m_Loop->SetRecordingSource(GetInput(0)->GetBuffer());
  84. else m_Loop->SetRecordingSource(NULL);
  85. for (int n=0; n<8; n++) GetOutputBuf(n+1)->Zero();
  86. // get the triggers active this frame
  87. vector<int> TriggerVec;
  88. ((SpiralLoopPluginGUI*)m_GUI)->GetGUI()->
  89. CheckTriggers(m_Loop->GetCurrentAngle(),TriggerVec);
  90. for (vector<int>::iterator i=TriggerVec.begin();
  91. i!=TriggerVec.end(); i++)
  92. {
  93. GetOutputBuf(*i+1)->Set(1);
  94. }
  95. m_Loop->GetOutput(*GetOutputBuf(0));
  96. static bool Triggered=false;
  97. if (GetInput(1,0)>TRIG_THRESH)
  98. {
  99. if (!Triggered)
  100. {
  101. m_Loop->Trigger();
  102. Triggered=true;
  103. }
  104. }
  105. else Triggered=false;
  106. }
  107. void SpiralLoopPlugin::StreamOut(ostream &s)
  108. {
  109. s<<m_Version<<" ";
  110. if (m_Version==1)
  111. {
  112. s<<*m_Loop<<" ";
  113. s<<*((SpiralLoopPluginGUI*)m_GUI)->GetGUI()<<" ";
  114. }
  115. else
  116. {
  117. m_Loop->StreamOut(s);
  118. s<<*((SpiralLoopPluginGUI*)m_GUI)->GetGUI()<<" ";
  119. }
  120. }
  121. void SpiralLoopPlugin::StreamIn(istream &s)
  122. {
  123. int version;
  124. s>>version;
  125. if (version==1)
  126. {
  127. s>>*m_Loop;
  128. s>>*((SpiralLoopPluginGUI*)m_GUI)->GetGUI();
  129. }
  130. else
  131. {
  132. m_Loop->StreamIn(s);
  133. s>>*((SpiralLoopPluginGUI*)m_GUI)->GetGUI();
  134. }
  135. }
  136. bool SpiralLoopPlugin::SaveExternalFiles(const string &Dir)
  137. {
  138. char temp[256];
  139. sprintf(temp,"%sSpiralLoopSample%d.wav",Dir.c_str(),GetID());
  140. m_Loop->SaveWav(temp);
  141. return true;
  142. }
  143. void SpiralLoopPlugin::LoadExternalFiles(const string &Dir)
  144. {
  145. char temp[256];
  146. sprintf(temp,"%sSpiralLoopSample%d.wav",Dir.c_str(),GetID());
  147. m_Loop->LoadWav(temp);
  148. }