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.

202 lines
4.4KB

  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 "SeqSelectorPlugin.h"
  19. #include "SeqSelectorPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include "SpiralIcon.xpm"
  22. #include "../../NoteTable.h"
  23. extern "C" {
  24. SpiralPlugin* CreateInstance()
  25. {
  26. return new SeqSelectorPlugin;
  27. }
  28. char** GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int GetID()
  33. {
  34. return 0x0015;
  35. }
  36. }
  37. ///////////////////////////////////////////////////////
  38. SeqSelectorPlugin::SeqSelectorPlugin()
  39. {
  40. m_PluginInfo.Name="SeqSelector";
  41. m_PluginInfo.Width=300;
  42. m_PluginInfo.Height=200;
  43. m_PluginInfo.NumInputs=1;
  44. m_PluginInfo.NumOutputs=8;
  45. m_PluginInfo.PortTips.push_back("Trigger");
  46. m_PluginInfo.PortTips.push_back("CV One");
  47. m_PluginInfo.PortTips.push_back("CV Two");
  48. m_PluginInfo.PortTips.push_back("CV Three");
  49. m_PluginInfo.PortTips.push_back("CV Four");
  50. m_PluginInfo.PortTips.push_back("CV Five");
  51. m_PluginInfo.PortTips.push_back("CV Six");
  52. m_PluginInfo.PortTips.push_back("CV Seven");
  53. m_PluginInfo.PortTips.push_back("CV Eight");
  54. m_Pos=0;
  55. m_Triggered=false;
  56. m_UseRange=false;
  57. m_AudioCH->Register("Num",&m_GUIArgs.Num);
  58. m_AudioCH->Register("Line",&m_GUIArgs.Line);
  59. m_AudioCH->Register("Val",&m_GUIArgs.Val);
  60. m_AudioCH->Register("Pos",(int*)&m_Pos,ChannelHandler::OUTPUT);
  61. }
  62. SeqSelectorPlugin::~SeqSelectorPlugin()
  63. {
  64. }
  65. PluginInfo &SeqSelectorPlugin::Initialise(const HostInfo *Host)
  66. {
  67. return SpiralPlugin::Initialise(Host);
  68. }
  69. SpiralGUIType *SeqSelectorPlugin::CreateGUI()
  70. {
  71. return new SeqSelectorPluginGUI(m_PluginInfo.Width,
  72. m_PluginInfo.Height,
  73. this,m_AudioCH,m_HostInfo);
  74. }
  75. void SeqSelectorPlugin::Execute()
  76. {
  77. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  78. {
  79. // Sends momentary spike of value when triggered,
  80. // works on the note off, rather than the first
  81. // detection of a trigger value
  82. if (GetInput(0,n)>0.1)
  83. {
  84. m_Triggered=true;
  85. }
  86. else
  87. {
  88. if (m_Triggered==true && m_Lines.size()>0)
  89. {
  90. m_Pos++;
  91. if (m_UseRange)
  92. {
  93. if (m_Pos>=m_End)
  94. {
  95. m_Pos=m_Begin;
  96. }
  97. }
  98. else
  99. {
  100. if (m_Pos>=m_Lines.size())
  101. {
  102. m_Pos=0;
  103. }
  104. }
  105. for(int i=0; i<8; i++)
  106. {
  107. SetOutputPitch(i,n,NoteTable[(int)m_Lines[m_Pos].Value[i]]);
  108. }
  109. }
  110. else
  111. {
  112. for(int i=0; i<8; i++)
  113. {
  114. // zero frequency
  115. SetOutputPitch(i,n,-1);
  116. }
  117. }
  118. m_Triggered=false;
  119. }
  120. }
  121. }
  122. void SeqSelectorPlugin::ExecuteCommands()
  123. {
  124. if (m_AudioCH->IsCommandWaiting())
  125. {
  126. switch (m_AudioCH->GetCommand())
  127. {
  128. case SET_BEGIN : m_Begin=m_GUIArgs.Line; break;
  129. case SET_END : m_End=m_GUIArgs.Line; break;
  130. case RANGE : m_UseRange=m_GUIArgs.Val; break;
  131. case ADD_LINE :
  132. {
  133. Line NewLine;
  134. if (m_Lines.size())
  135. {
  136. for (int n=0; n<NUM_VALUES; n++) NewLine.Value[n]=m_Lines[m_Lines.size()-1].Value[n];
  137. }
  138. else
  139. {
  140. for (int n=0; n<NUM_VALUES; n++) NewLine.Value[n]=0;
  141. }
  142. m_Lines.push_back(NewLine);
  143. } break;
  144. case REM_LINE : m_Lines.pop_back(); break;
  145. case SET_VAL : m_Lines[m_GUIArgs.Line].Value[m_GUIArgs.Num]=m_GUIArgs.Val; break;
  146. default: break;
  147. }
  148. }
  149. }
  150. void SeqSelectorPlugin::StreamOut(ostream &s)
  151. {
  152. s<<m_Version<<" ";
  153. s<<m_Lines.size()<<" ";
  154. if (m_Lines.size()>0)
  155. {
  156. for (vector<Line>::iterator i = m_Lines.begin();
  157. i!=m_Lines.end(); i++)
  158. {
  159. for (int n=0; n<NUM_VALUES; n++)
  160. {
  161. s<<i->Value[n]<<" ";
  162. }
  163. }
  164. }
  165. }
  166. void SeqSelectorPlugin::StreamIn(istream &s)
  167. {
  168. int version;
  169. s>>version;
  170. int Num;
  171. s>>Num;
  172. for (int i=0; i<Num; i++)
  173. {
  174. Line NewLine;
  175. for (int n=0; n<NUM_VALUES; n++)
  176. {
  177. s>>NewLine.Value[n];
  178. }
  179. m_Lines.push_back(NewLine);
  180. }
  181. }