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.

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