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.

169 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 ExecuteCommands();
  52. virtual void StreamOut(std::ostream &s);
  53. virtual void StreamIn(std::istream &s);
  54. virtual bool SaveExternalFiles(const std::string &Dir);
  55. virtual void LoadExternalFiles(const std::string &Dir);
  56. enum GUICommands{NONE,START,STOP,RECORD,OVERDUB,ENDRECORD,LOAD,SAVE,CUT,
  57. COPY,PASTE,PASTEMIX,ZERO_RANGE,REVERSE_RANGE,SELECT_ALL,DOUBLE,HALF,
  58. MOVE,CROP,KEEPDUB,UNDODUB,CHANGE_LENGTH,NEW_TRIGGER,UPDATE_TRIGGER,
  59. GETSAMPLE};
  60. void LoadWav(const char *Filename);
  61. void SaveWav(const char *Filename);
  62. bool GetOutput(Sample &data);
  63. void AllocateMem(int Length);
  64. void Clear();
  65. void MixDub() { m_StoreBuffer.Mix(m_DubBuffer,0); ClearDub(); }
  66. void ClearDub() { m_DubBuffer.Zero(); }
  67. void Double();
  68. void MatchLength(int Len);
  69. void Crop();
  70. void SetId(int Id) { m_Id=Id; }
  71. void SetPos(int Pos) { m_Pos=Pos; }
  72. void SetLength(int Len) { m_LoopPoint=Len; }
  73. void SetSpeed(float Speed) { m_Speed=Speed; }
  74. void SetVolume(float Vol) { m_Volume=Vol; }
  75. void SetPlaying(bool Playing) { m_Playing=Playing; }
  76. void SetRecordingSource(const float *s) { m_RecordingSource=s; }
  77. void Record(bool r) { m_Recording=r; if (!r) EndRecordBuf(); }
  78. void DelMe() { m_DelMe=true; }
  79. void Trigger() { m_Pos=0; SetPlaying(true); }
  80. const bool IsPlaying() {return m_Playing;}
  81. const float *GetLoopPtr() {return m_StoreBuffer.GetBuffer();}
  82. const int GetId() {return m_Id;}
  83. const int GetLoopLength() {return m_LoopPoint;}
  84. float *GetPosPtr() {return &m_Pos;}
  85. const int GetTotalLength() {assert(m_StoreBuffer.GetLength()==m_DubBuffer.GetLength()); return m_StoreBuffer.GetLength();}
  86. const bool Delete() {return m_DelMe; }
  87. const float GetSpeed() {return m_Speed;}
  88. const float GetVolume() { return m_Volume; }
  89. const float GetCurrentAngle() { return m_LoopPoint?(m_Pos/m_LoopPoint)*360.0f:0; }
  90. const std::string& GetSampleName() { return m_Sample; }
  91. std::vector<TriggerInfo> *GetTriggerVec() { return &m_TriggerVec; }
  92. void Cut(int Start, int End);
  93. void Copy(int Start, int End);
  94. void Paste(int Start);
  95. void PasteMix(int Start);
  96. void ZeroRange(int Start, int End);
  97. void ReverseRange(int Start, int End);
  98. void Halve();
  99. void SelectAll();
  100. void Move(int Start);
  101. Sample *GetStoreBuffer() { return &m_StoreBuffer; }
  102. private:
  103. struct GUIArgs
  104. {
  105. long Start;
  106. long End;
  107. float Length;
  108. char Name[256];
  109. };
  110. GUIArgs m_GUIArgs;
  111. void RecordBuf(float Pos, int Length);
  112. void EndRecordBuf();
  113. int m_Id;
  114. float m_Pos;
  115. int m_IntPos;
  116. int m_PlayBufPos;
  117. bool m_Playing;
  118. bool m_Recording;
  119. bool m_DelMe;
  120. long int m_LoopPoint;
  121. float m_Speed;
  122. float m_Volume;
  123. const float *m_RecordingSource;
  124. Sample m_StoreBuffer;
  125. Sample m_DubBuffer;
  126. Sample m_RecBuffer;
  127. Sample m_CopyBuffer;
  128. int m_RecPos;
  129. bool m_FirstRecord;
  130. bool m_FixedRecord;
  131. int m_RecLength;
  132. int m_TickTime;
  133. int m_TickCurrent;
  134. int m_TicksPerLoop;
  135. float m_TickOutput;
  136. bool m_Triggered;
  137. char m_SampleBuffer[TRANSBUF_SIZE];
  138. long m_SampleSize;
  139. std::vector<TriggerInfo> m_TriggerVec;
  140. std::string m_Sample;
  141. };
  142. #endif