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.

171 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 "../SpiralPlugin.h"
  19. #include <FL/Fl_Pixmap.H>
  20. #ifndef SpiralLoopPLUGIN
  21. #define SpiralLoopPLUGIN
  22. static const int TRANSBUF_SIZE = 0x10000;
  23. static const int MAX_TRIGGERS = 8;
  24. struct SampleDesc
  25. {
  26. std::string Pathname;
  27. float Volume;
  28. float Pitch;
  29. float PitchMod;
  30. bool Loop;
  31. int Note;
  32. bool TriggerUp;
  33. float SamplePos;
  34. int SampleRate;
  35. bool Stereo;
  36. };
  37. class SpiralLoopPlugin : public SpiralPlugin
  38. {
  39. public:
  40. SpiralLoopPlugin();
  41. virtual ~SpiralLoopPlugin();
  42. struct TriggerInfo
  43. {
  44. int Channel;
  45. float Time;
  46. bool Triggered;
  47. };
  48. virtual PluginInfo &Initialise(const HostInfo *Host);
  49. virtual SpiralGUIType *CreateGUI();
  50. virtual void Execute();
  51. virtual void Reset();
  52. virtual void ExecuteCommands();
  53. virtual void StreamOut(std::ostream &s);
  54. virtual void StreamIn(std::istream &s);
  55. virtual bool SaveExternalFiles(const std::string &Dir);
  56. virtual void LoadExternalFiles(const std::string &Dir);
  57. enum GUICommands{NONE,START,STOP,RECORD,OVERDUB,ENDRECORD,LOAD,SAVE,CUT,
  58. COPY,PASTE,PASTEMIX,ZERO_RANGE,REVERSE_RANGE,SELECT_ALL,DOUBLE,HALF,
  59. MOVE,CROP,KEEPDUB,UNDODUB,CHANGE_LENGTH,NEW_TRIGGER,UPDATE_TRIGGER,
  60. GETSAMPLE};
  61. void LoadWav(const char *Filename);
  62. void SaveWav(const char *Filename);
  63. bool GetOutput(Sample &data);
  64. void AllocateMem(int Length);
  65. void Clear();
  66. void MixDub() { m_StoreBuffer.Mix(m_DubBuffer,0); ClearDub(); }
  67. void ClearDub() { m_DubBuffer.Zero(); }
  68. void Double();
  69. void MatchLength(int Len);
  70. void Crop();
  71. void SetId(int Id) { m_Id=Id; }
  72. void SetPos(int Pos) { m_Pos=Pos; }
  73. void SetLength(int Len) { m_LoopPoint=Len; }
  74. void SetSpeed(float Speed) { m_Speed=Speed; }
  75. void SetVolume(float Vol) { m_Volume=Vol; }
  76. void SetPlaying(bool Playing) { m_Playing=Playing; }
  77. void SetRecordingSource(const float *s) { m_RecordingSource=s; }
  78. void Record(bool r) { m_Recording=r; if (!r) EndRecordBuf(); }
  79. void DelMe() { m_DelMe=true; }
  80. void Trigger() { m_Pos=0; SetPlaying(true); }
  81. const bool IsPlaying() {return m_Playing;}
  82. const float *GetLoopPtr() {return m_StoreBuffer.GetBuffer();}
  83. const int GetId() {return m_Id;}
  84. const int GetLoopLength() {return m_LoopPoint;}
  85. float *GetPosPtr() {return &m_Pos;}
  86. const int GetTotalLength() {assert(m_StoreBuffer.GetLength()==m_DubBuffer.GetLength()); return m_StoreBuffer.GetLength();}
  87. const bool Delete() {return m_DelMe; }
  88. const float GetSpeed() {return m_Speed;}
  89. const float GetVolume() { return m_Volume; }
  90. const float GetCurrentAngle() { return m_LoopPoint?(m_Pos/m_LoopPoint)*360.0f:0; }
  91. const std::string& GetSampleName() { return m_Sample; }
  92. std::vector<TriggerInfo> *GetTriggerVec() { return &m_TriggerVec; }
  93. void Cut(int Start, int End);
  94. void Copy(int Start, int End);
  95. void Paste(int Start);
  96. void PasteMix(int Start);
  97. void ZeroRange(int Start, int End);
  98. void ReverseRange(int Start, int End);
  99. void Halve();
  100. void SelectAll();
  101. void Move(int Start);
  102. Sample *GetStoreBuffer() { return &m_StoreBuffer; }
  103. private:
  104. struct GUIArgs
  105. {
  106. long Start;
  107. long End;
  108. float Length;
  109. char Name[256];
  110. };
  111. GUIArgs m_GUIArgs;
  112. void RecordBuf(float Pos, int Length);
  113. void EndRecordBuf();
  114. int m_Id;
  115. float m_Pos;
  116. int m_IntPos;
  117. int m_PlayBufPos;
  118. bool m_Playing;
  119. bool m_Recording;
  120. bool m_DelMe;
  121. long int m_LoopPoint;
  122. float m_Speed;
  123. float m_Volume;
  124. const float *m_RecordingSource;
  125. Sample m_StoreBuffer;
  126. Sample m_DubBuffer;
  127. Sample m_RecBuffer;
  128. Sample m_CopyBuffer;
  129. int m_RecPos;
  130. bool m_FirstRecord;
  131. bool m_FixedRecord;
  132. int m_RecLength;
  133. int m_TickTime;
  134. int m_TickCurrent;
  135. int m_TicksPerLoop;
  136. float m_TickOutput;
  137. bool m_Triggered;
  138. char m_SampleBuffer[TRANSBUF_SIZE];
  139. long m_SampleSize;
  140. std::vector<TriggerInfo> m_TriggerVec;
  141. std::string m_Sample;
  142. };
  143. #endif