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.

270 lines
5.2KB

  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 "SequencerPlugin.h"
  19. #include "SequencerPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include "SpiralIcon.xpm"
  22. #include "../../RiffWav.h"
  23. #include "../../NoteTable.h"
  24. // for note on's
  25. static const float TRIGGER_LEV=0.1;
  26. extern "C" {
  27. SpiralPlugin* CreateInstance()
  28. {
  29. return new SequencerPlugin;
  30. }
  31. char** GetIcon()
  32. {
  33. return SpiralIcon_xpm;
  34. }
  35. int GetID()
  36. {
  37. return 0x0011;
  38. }
  39. }
  40. ///////////////////////////////////////////////////////
  41. SequencerPlugin::SequencerPlugin() :
  42. m_Time(0.0f),
  43. m_Length(10.0f),
  44. m_SpeedMod(1.0f),
  45. m_CurrentNoteCV(0),
  46. m_CurrentTriggerCV(0),
  47. m_InNoteDown(false),
  48. m_InNoteID(0),
  49. m_CurrentPattern(0),
  50. m_Triggered(false)
  51. {
  52. m_Version=2;
  53. m_PluginInfo.Name="Sequencer";
  54. m_PluginInfo.Width=540;
  55. m_PluginInfo.Height=290;
  56. m_PluginInfo.NumInputs=4;
  57. m_PluginInfo.NumOutputs=2;
  58. m_PluginInfo.PortTips.push_back("Play Trigger");
  59. m_PluginInfo.PortTips.push_back("Speed CV");
  60. m_PluginInfo.PortTips.push_back("Input Pitch CV");
  61. m_PluginInfo.PortTips.push_back("Input Trigger CV");
  62. m_PluginInfo.PortTips.push_back("Output Pitch");
  63. m_PluginInfo.PortTips.push_back("Output Trigger");
  64. }
  65. SequencerPlugin::~SequencerPlugin()
  66. {
  67. }
  68. PluginInfo &SequencerPlugin::Initialise(const HostInfo *Host)
  69. {
  70. return SpiralPlugin::Initialise(Host);
  71. }
  72. SpiralGUIType *SequencerPlugin::CreateGUI()
  73. {
  74. return new SequencerPluginGUI(m_PluginInfo.Width,
  75. m_PluginInfo.Height,
  76. this,m_AudioCH,m_HostInfo);
  77. }
  78. void SequencerPlugin::SetPattern(int s)
  79. {
  80. //m_Eventmap[m_CurrentPattern]->hide();
  81. m_CurrentPattern=s;
  82. //m_Eventmap[m_CurrentPattern]->show();
  83. }
  84. void SequencerPlugin::Execute()
  85. {
  86. float Speed;
  87. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  88. {
  89. if (GetInputPitch(0,n)>0)
  90. {
  91. if (!m_Triggered)
  92. {
  93. float Freq=GetInputPitch(0,n);
  94. // Notes 0 to 16 trigger patterns 0 to 16
  95. // No other notes catered for
  96. for (int i=0; i<NUM_PATTERNS; i++)
  97. {
  98. if (feq(Freq,NoteTable[i],0.01f))
  99. {
  100. SetPattern(i);
  101. break;
  102. }
  103. }
  104. m_Time=0;
  105. m_Triggered=true;
  106. }
  107. }
  108. else
  109. {
  110. m_Triggered=false;
  111. }
  112. if (InputExists(1))
  113. Speed =(1.1025f/m_HostInfo->SAMPLERATE) * (GetInput(1,n)+1.0f);
  114. else
  115. Speed =1.1025f/m_HostInfo->SAMPLERATE;
  116. if (!m_InNoteDown)
  117. {
  118. // Check trigger
  119. if (GetInput(3,n)>TRIGGER_LEV)
  120. {
  121. m_InNoteDown=true;
  122. float Freq=GetInputPitch(2,n);
  123. int NoteNum=0;
  124. for (int i=0; i<131; i++)
  125. {
  126. if (feq(Freq,NoteTable[i],0.01f))
  127. {
  128. NoteNum=i;
  129. break;
  130. }
  131. }
  132. /*cerr<<"note recieved ="<<NoteNum<<" f="<<Freq
  133. <<" t-1="<<NoteTable[NoteNum-1]
  134. <<" t="<<NoteTable[NoteNum]
  135. <<" t+1="<<NoteTable[NoteNum+1]<<endl;
  136. */
  137. //m_InNoteID=m_Eventmap[m_CurrentPattern]->AddEventTime(m_Time, NoteNum, 0.5, Fl_SEvent::MELODY, false);
  138. m_InNoteTime=m_Time;
  139. }
  140. }
  141. else
  142. {
  143. // Check trigger
  144. if (GetInput(3,n)<TRIGGER_LEV)
  145. {
  146. //m_Eventmap[m_CurrentPattern]->SetEventLength(m_InNoteID, m_Time-m_InNoteTime);
  147. m_InNoteDown=false;
  148. }
  149. }
  150. // Get the notes from the map
  151. /*vector<EventInfo> NoteVec=m_Eventmap[m_CurrentPattern]->GetEvents(m_Time);
  152. // play all the notes found
  153. for (vector<EventInfo>::iterator i=NoteVec.begin();
  154. i!=NoteVec.end(); i++)
  155. {
  156. if (i->m_Type==EventInfo::START)
  157. {
  158. m_CurrentNoteCV=NoteTable[i->m_Group];
  159. m_CurrentTriggerCV=1;
  160. }
  161. if (i->m_Type==EventInfo::END)
  162. {
  163. m_CurrentTriggerCV=0;
  164. if (m_NoteCut) m_CurrentNoteCV=0;
  165. }
  166. }
  167. */
  168. SetOutputPitch(0,n,m_CurrentNoteCV);
  169. SetOutput(1,n,m_CurrentTriggerCV);
  170. m_Time+=Speed*m_SpeedMod;
  171. if (m_Time>m_Length)
  172. {
  173. m_Time=0;
  174. }
  175. if (m_Time<0)
  176. {
  177. m_Time=m_Length;
  178. }
  179. }
  180. }
  181. void SequencerPlugin::ExecuteCommands()
  182. {
  183. }
  184. void SequencerPlugin::StreamOut(ostream &s)
  185. {
  186. s<<m_Version<<" ";
  187. switch (m_Version)
  188. {
  189. case 2:
  190. {
  191. s<<m_Time<<" ";
  192. s<<m_Length<<" ";
  193. s<<m_SpeedMod<<" ";
  194. s<<m_Loop<<" ";
  195. s<<m_NoteCut<<" ";
  196. s<<m_CurrentPattern<<" ";
  197. }
  198. // fallthrough
  199. case 1:
  200. {
  201. for(int n=0; n<NUM_PATTERNS; n++)
  202. {
  203. //s<<*m_Eventmap[n]<<" ";
  204. }
  205. } break;
  206. }
  207. }
  208. void SequencerPlugin::StreamIn(istream &s)
  209. {
  210. int version;
  211. s>>version;
  212. switch (version)
  213. {
  214. case 2:
  215. {
  216. s>>m_Time;
  217. s>>m_Length;
  218. s>>m_SpeedMod;
  219. s>>m_Loop;
  220. s>>m_NoteCut;
  221. s>>m_CurrentPattern;
  222. }
  223. // fallthrough
  224. case 1:
  225. {
  226. for(int n=0; n<NUM_PATTERNS; n++)
  227. {
  228. //s>>*m_Eventmap[n];
  229. }
  230. } break;
  231. }
  232. }