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.

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