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.7KB

  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 SetBalance(float s) { m_Balance=s; m_LeftVol=(2-s)/2; m_RightVol=(1+s-1.0f)/2;}
  74. void Trigger() { m_Pos=0; SetPlaying(true); }
  75. const float GetBalance() {return m_Balance;}
  76. const bool IsPlaying() {return m_Playing;}
  77. const float *GetLoopPtr() {return m_StoreBuffer.GetBuffer();}
  78. const int GetId() {return m_Id;}
  79. const int GetLoopLength() {return m_LoopPoint;}
  80. float *GetPosPtr() {return &m_Pos;}
  81. const int GetTotalLength() {assert(m_StoreBuffer.GetLength()==m_DubBuffer.GetLength()); return m_StoreBuffer.GetLength();}
  82. const bool Delete() {return m_DelMe; }
  83. const float GetSpeed() {return m_Speed;}
  84. const float GetLeftVol() { return m_LeftVol; }
  85. const float GetRightVol() { return m_RightVol; }
  86. const float GetCurrentAngle() { return m_LoopPoint?(m_Pos/m_LoopPoint)*360.0f:0; }
  87. const string& GetSampleName() { return m_Sample; }
  88. void Cut(int Start, int End);
  89. void Copy(int Start, int End);
  90. void Paste(int Start);
  91. void PasteMix(int Start);
  92. void ZeroRange(int Start, int End);
  93. void ReverseRange(int Start, int End);
  94. void Halve();
  95. void SelectAll();
  96. void Move(int Start);
  97. private:
  98. struct GUIArgs
  99. {
  100. long Start;
  101. long End;
  102. float Length;
  103. char Name[256];
  104. };
  105. GUIArgs m_GUIArgs;
  106. void RecordBuf(float Pos, int Length);
  107. void EndRecordBuf();
  108. int m_Id;
  109. float m_Pos;
  110. int m_IntPos;
  111. int m_PlayBufPos;
  112. bool m_Playing;
  113. bool m_Recording;
  114. bool m_DelMe;
  115. long int m_LoopPoint;
  116. float m_Speed;
  117. float m_Volume;
  118. const float *m_RecordingSource;
  119. Sample m_StoreBuffer;
  120. Sample m_DubBuffer;
  121. Sample m_RecBuffer;
  122. Sample m_CopyBuffer;
  123. int m_RecPos;
  124. float m_Balance;
  125. float m_LeftVol,m_RightVol;
  126. bool m_FirstRecord;
  127. bool m_FixedRecord;
  128. int m_RecLength;
  129. int m_TickTime;
  130. int m_TickCurrent;
  131. int m_TicksPerLoop;
  132. float m_TickOutput;
  133. bool m_Triggered;
  134. char m_SampleBuffer[TRANSBUF_SIZE];
  135. long m_SampleSize;
  136. struct TriggerInfo
  137. {
  138. int Channel;
  139. float Time;
  140. bool Triggered;
  141. };
  142. vector<TriggerInfo> m_TriggerVec;
  143. string m_Sample;
  144. };
  145. #endif