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.

217 lines
4.6KB

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