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.

222 lines
5.9KB

  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 "../SpiralPlugin.h"
  19. #include <FL/Fl_Pixmap.H>
  20. #include "../Widgets/Fl_EventMap.h"
  21. #include <list>
  22. #ifndef SequencerPLUGIN
  23. #define SequencerPLUGIN
  24. const int NUM_PATTERNS = 8;
  25. const int NUM_CHANNELS = 8;
  26. //////////////////////////////////////////////////////////////////////////
  27. // base sequencing stuff
  28. class Note
  29. {
  30. public:
  31. Note(float t, float l, int n, float v);
  32. virtual ~Note();
  33. float Time;
  34. float Length;
  35. int MidiNote;
  36. float Vol;
  37. friend istream &operator>>(istream &s, Note &o);
  38. friend ostream &operator<<(ostream &s, Note &o);
  39. };
  40. istream &operator>>(istream &s, Note &o);
  41. ostream &operator<<(ostream &s, Note &o);
  42. class Pattern
  43. {
  44. public:
  45. Pattern();
  46. virtual ~Pattern();
  47. void Copy(const Pattern *o);
  48. void AddNote(int ID, float t, float l, int n, float v);
  49. void RemoveNote(int ID);
  50. Note *GetNote(int ID);
  51. int GetNoteCount() { return m_NoteMap.size(); }
  52. map<int,Note> m_NoteMap;
  53. friend istream &operator>>(istream &s, Pattern &o);
  54. friend ostream &operator<<(ostream &s, Pattern &o);
  55. };
  56. istream &operator>>(istream &s, Pattern &o);
  57. ostream &operator<<(ostream &s, Pattern &o);
  58. class Sequence
  59. {
  60. public:
  61. Sequence(float st=0, int pat=0);
  62. virtual ~Sequence();
  63. void SetStartTime(float t) { m_StartTime=t; }
  64. float GetStartTime() { return m_StartTime; }
  65. void SetPatternID(int p) { m_Pattern=p; }
  66. int GetPatternID() { return m_Pattern; }
  67. void SetName(string s) { m_Name=s; }
  68. string GetName() { return m_Name; }
  69. void SetColour(int s) { m_Colour=s; }
  70. int GetColour() { return m_Colour; }
  71. void SetYPos(int s) { m_YPos=s; }
  72. int GetYPos() { return m_YPos; }
  73. void SetLength(float t) { m_Length=t; }
  74. float GetLength() { return m_Length; }
  75. void SetChannel(int s) { m_Channel=s; }
  76. int GetChannel() { return m_Channel; }
  77. private:
  78. float m_StartTime;
  79. int m_Pattern;
  80. string m_Name;
  81. int m_Colour;
  82. int m_YPos;
  83. float m_Length;
  84. int m_Channel;
  85. friend istream &operator>>(istream &s, Sequence &o);
  86. friend ostream &operator<<(ostream &s, Sequence &o);
  87. };
  88. istream &operator>>(istream &s, Sequence &o);
  89. ostream &operator<<(ostream &s, Sequence &o);
  90. class Track
  91. {
  92. public:
  93. Track();
  94. virtual ~Track();
  95. void AddSequence(int ID);
  96. void CloneSequence(int ID, int nID);
  97. void CopySequence(int ID, int nID);
  98. void InstanceSequence(int ID);
  99. void RemoveSequence(int ID);
  100. Sequence *GetSequence(int ID);
  101. void AddNote(int ID, int Sequence, float t, float l, int n, float v);
  102. void RemoveNote(int ID, int Sequence);
  103. void ChangeNote(int ID, int Sequence, float t, float l, int n, float v);
  104. void ReadTrack(float t, int channel, vector<Note> &NoteVec);
  105. Pattern *GetPattern(int ID);
  106. map<int,Sequence> *GetSequenceMap() { return &m_SequenceMap; }
  107. private:
  108. void AddPattern(int ID);
  109. void RemovePattern(int ID);
  110. map<int,Pattern> m_PatternMap;
  111. map<int,Sequence> m_SequenceMap;
  112. int m_NextPatternID;
  113. friend istream &operator>>(istream &s, Track &o);
  114. friend ostream &operator<<(ostream &s, Track &o);
  115. };
  116. istream &operator>>(istream &s, Track &o);
  117. ostream &operator<<(ostream &s, Track &o);
  118. ///////////////////////////////////////////////////////////////////////////
  119. class SequencerPlugin : public SpiralPlugin
  120. {
  121. public:
  122. SequencerPlugin();
  123. virtual ~SequencerPlugin();
  124. virtual PluginInfo &Initialise(const HostInfo *Host);
  125. virtual SpiralGUIType *CreateGUI();
  126. virtual void Execute();
  127. virtual void ExecuteCommands();
  128. virtual void StreamOut(ostream &s);
  129. virtual void StreamIn(istream &s);
  130. bool GetNoteCut() { return m_NoteCut; }
  131. void ClearAll() { /*m_Eventmap[m_CurrentPattern]->RemoveAllEvents();*/ }
  132. int GetCurrentPattern() { return m_CurrentPattern; }
  133. Track *GetTrack() { return &m_Track; }
  134. enum GUICommands {NONE,NEW_NOTE,REM_NOTE,CHG_NOTE,NEW_SEQ,CHG_SEQ,COPY_SEQ,
  135. INST_SEQ,CLONE_SEQ,REM_SEQ,GET_PATTERN};
  136. struct GUIArgs
  137. {
  138. int Num,Num2;
  139. int Sequence;
  140. float t,l,v;
  141. int n;
  142. char Name[256];
  143. int Channel;
  144. };
  145. private:
  146. GUIArgs m_GUIArgs;
  147. Track m_Track;
  148. int m_TransferPattern;
  149. //int m_TransferNote;
  150. map<int,Note>::iterator m_TransferNote;
  151. int m_TransferCount;
  152. Note m_Transfer;
  153. void SetEventMap(int n, Fl_EventMap* s) { /*m_Eventmap[n]=s;*/ }
  154. void SetUpdate(bool s) { /*m_Eventmap[m_CurrentPattern]->SetUpdate(s);*/ }
  155. void SetZoom(float s) { /*m_Eventmap[m_CurrentPattern]->SetZoomLevel(s);*/ }
  156. void SetNoteCut(bool s) { m_NoteCut=s; }
  157. //void SetEndTime(float s) { /*m_Eventmap[m_CurrentPattern]->SetEndTime(s);*/ m_Length=s; }
  158. void SetSpeed(float s) { m_SpeedMod=s; }
  159. void SetPattern(int s);
  160. float m_Time;
  161. int m_Length; // in bars
  162. float m_BarLength;
  163. int m_BeatsPerBar;
  164. float m_NextBeatTime;
  165. float m_BeatLevel;
  166. int m_BeatCount;
  167. int m_BarCount;
  168. bool m_Loop;
  169. bool m_NoteCut;
  170. float m_SpeedMod;
  171. float m_CurrentNoteCV[NUM_CHANNELS];
  172. float m_CurrentTriggerCV[NUM_CHANNELS];
  173. bool m_InNoteDown;
  174. int m_InNoteID;
  175. float m_InNoteTime;
  176. int m_CurrentPattern;
  177. bool m_Triggered;
  178. };
  179. #endif