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.

209 lines
4.5KB

  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::Execute()
  81. {
  82. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  83. {
  84. // Sends momentary spike of value when triggered,
  85. // works on the note off, rather than the first
  86. // detection of a trigger value
  87. if (GetInput(0,n)>0.1)
  88. {
  89. m_Triggered=true;
  90. }
  91. else
  92. {
  93. if (m_Triggered==true && m_Lines.size()>0)
  94. {
  95. m_Pos++;
  96. if (m_UseRange)
  97. {
  98. if (m_Pos>=m_End)
  99. {
  100. m_Pos=m_Begin;
  101. }
  102. }
  103. else
  104. {
  105. if (m_Pos>=m_Lines.size())
  106. {
  107. m_Pos=0;
  108. }
  109. }
  110. for(int i=0; i<8; i++)
  111. {
  112. SetOutputPitch(i,n,NoteTable[(int)m_Lines[m_Pos].Value[i]]);
  113. }
  114. }
  115. else
  116. {
  117. for(int i=0; i<8; i++)
  118. {
  119. // zero frequency
  120. SetOutputPitch(i,n,-1);
  121. }
  122. }
  123. m_Triggered=false;
  124. }
  125. }
  126. }
  127. void SeqSelectorPlugin::ExecuteCommands()
  128. {
  129. if (m_AudioCH->IsCommandWaiting())
  130. {
  131. switch (m_AudioCH->GetCommand())
  132. {
  133. case SET_BEGIN : m_Begin=m_GUIArgs.Line; break;
  134. case SET_END : m_End=m_GUIArgs.Line; break;
  135. case RANGE : m_UseRange=m_GUIArgs.Val; break;
  136. case ADD_LINE :
  137. {
  138. Line NewLine;
  139. if (m_Lines.size())
  140. {
  141. for (int n=0; n<NUM_VALUES; n++) NewLine.Value[n]=m_Lines[m_Lines.size()-1].Value[n];
  142. }
  143. else
  144. {
  145. for (int n=0; n<NUM_VALUES; n++) NewLine.Value[n]=0;
  146. }
  147. m_Lines.push_back(NewLine);
  148. } break;
  149. case REM_LINE : m_Lines.pop_back(); break;
  150. case SET_VAL : m_Lines[m_GUIArgs.Line].Value[m_GUIArgs.Num]=m_GUIArgs.Val; break;
  151. default: break;
  152. }
  153. }
  154. }
  155. void SeqSelectorPlugin::StreamOut(ostream &s)
  156. {
  157. s<<m_Version<<" ";
  158. s<<m_Lines.size()<<" ";
  159. if (m_Lines.size()>0)
  160. {
  161. for (vector<Line>::iterator i = m_Lines.begin();
  162. i!=m_Lines.end(); i++)
  163. {
  164. for (int n=0; n<NUM_VALUES; n++)
  165. {
  166. s<<i->Value[n]<<" ";
  167. }
  168. }
  169. }
  170. }
  171. void SeqSelectorPlugin::StreamIn(istream &s)
  172. {
  173. int version;
  174. s>>version;
  175. int Num;
  176. s>>Num;
  177. for (int i=0; i<Num; i++)
  178. {
  179. Line NewLine;
  180. for (int n=0; n<NUM_VALUES; n++)
  181. {
  182. s>>NewLine.Value[n];
  183. }
  184. m_Lines.push_back(NewLine);
  185. }
  186. }