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.

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