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.

221 lines
6.3KB

  1. /* SpiralSound
  2. * Copyleft (C) 2002 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. #ifndef SPIRALPLUGIN
  19. #define SPIRALPLUGIN
  20. #include <vector>
  21. #include <map>
  22. #include <string>
  23. #include <iostream>
  24. #include <math.h>
  25. #include <FL/Fl.h>
  26. #include <FL/Fl_Group.h>
  27. #include "../Sample.h"
  28. #include "../ChannelHandler.h"
  29. #include "../../GUI/Widgets/SpiralGUI.H"
  30. static const float MAX_FREQ = 13000;
  31. struct PluginInfo
  32. {
  33. std::string Name;
  34. int Width;
  35. int Height;
  36. int NumInputs;
  37. int NumOutputs;
  38. std::vector<std::string> PortTips;
  39. std::vector<int> PortTypes;
  40. char BitMap[40][40][3];
  41. };
  42. struct HostInfo
  43. {
  44. int BUFSIZE;
  45. int SAMPLERATE;
  46. /* obsolete - REMOVE SOON */
  47. int FRAGSIZE;
  48. int FRAGCOUNT;
  49. std::string OUTPUTFILE;
  50. std::string MIDIFILE;
  51. int POLY;
  52. unsigned GUI_COLOUR;
  53. unsigned SCOPE_BG_COLOUR;
  54. unsigned SCOPE_FG_COLOUR;
  55. unsigned SCOPE_SEL_COLOUR;
  56. unsigned SCOPE_IND_COLOUR;
  57. unsigned SCOPE_MRK_COLOUR;
  58. unsigned GUICOL_Device;
  59. unsigned GUIDEVICE_Box;
  60. bool PAUSED;
  61. };
  62. /////////////////////////////////////////////////////////////////////
  63. class ChannelHandler;
  64. class SpiralPlugin
  65. {
  66. public:
  67. SpiralPlugin();
  68. virtual ~SpiralPlugin();
  69. virtual PluginInfo& Initialise(const HostInfo *Host);
  70. // execute the audio
  71. virtual void Execute()=0;
  72. virtual bool Kill();
  73. virtual void Reset();
  74. // run the commands from the GUI
  75. virtual void ExecuteCommands() {}
  76. // create the GUI, do not store the pointer - it wont be threadsafe to use it
  77. virtual SpiralGUIType* CreateGUI()=0;
  78. // stream the plugins state
  79. virtual void StreamOut(std::ostream &s)=0;
  80. virtual void StreamIn(std::istream &s)=0;
  81. // stuff here gets saved in filename_files directory
  82. // you must return true if this feature is used.
  83. virtual bool SaveExternalFiles(const std::string &Dir) { return false; }
  84. virtual void LoadExternalFiles(const std::string &Dir, int withID=-1) {}
  85. const HostInfo* GetHostInfo() { return m_HostInfo; }
  86. bool GetOutput(unsigned int n, Sample **s);
  87. bool SetInput(unsigned int n, const Sample *s);
  88. const Sample* GetInput(unsigned int n) { return m_Input[n]; }
  89. std::string GetName() { return m_PluginInfo.Name; }
  90. void UpdatePluginInfoWithHost();
  91. void SetInPortType(PluginInfo &pinfo, int port, Sample::SampleType type);
  92. void SetOutPortType(PluginInfo &pinfo, int port, Sample::SampleType type);
  93. // Callbacks to main engine. Should only called by plugin hosts.
  94. void SetUpdateInfoCallback(int ID, void(*s)(int, void *));
  95. void SetUpdateCallback(void (*s)(void*,bool m)) { cb_Update=s; }
  96. void SetBlockingCallback(void (*s)(void*,bool m)) { cb_Blocking=s; }
  97. void SetParent(void *s) { m_Parent=s; }
  98. void UpdateChannelHandler();
  99. // is the plugin connected to an external device (oss/alsa/jack)
  100. bool IsTerminal() { return m_IsTerminal; }
  101. bool IsDead() { return m_IsDead; }
  102. ChannelHandler *GetChannelHandler() { return m_AudioCH; }
  103. virtual bool IsAudioDriver() { return false; }
  104. protected:
  105. ChannelHandler *m_AudioCH;
  106. void SetOutput(int n,int p, float s)
  107. { if (m_Output[n]) m_Output[n]->Set(p,s); }
  108. float GetInput(int n,int p)
  109. { if (m_Input[n]) return (*m_Input[n])[p]; else return 0.0; }
  110. void SetOutputPitch(int n,int p, float s)
  111. { if (m_Output[n]) m_Output[n]->Set(p,(s/MAX_FREQ*2)-1.0f); }
  112. float GetInputPitch(int n,int p)
  113. { if (m_Input[n]) return ((*m_Input[n])[p]+1.0f)*MAX_FREQ/2; else return 0.0; }
  114. void MixOutput(int n,int p, float s)
  115. { if (m_Output[n]) m_Output[n]->Set(p,s+(*m_Output[n])[p]); }
  116. bool InputExists(int n) { return m_Input[n]!=NULL; }
  117. bool OutputExists(int n) { return m_Output[n]!=NULL; }
  118. void AddOutput();
  119. void RemoveOutput();
  120. void RemoveAllOutputs();
  121. void AddInput();
  122. void RemoveInput();
  123. void RemoveAllInputs();
  124. void ResetPorts();
  125. // the ID number assigned to us by ssm
  126. int GetID() { return m_HostID; }
  127. Sample* GetOutputBuf(int n) { return m_Output[n]; }
  128. const HostInfo *m_HostInfo;
  129. PluginInfo m_PluginInfo;
  130. int m_Version;
  131. // needed for jack
  132. void (*cb_Update)(void*o ,bool m);
  133. void *m_Parent;
  134. // tell the engine that we are taking control of the
  135. // timing for output.
  136. void (*cb_Blocking)(void*o ,bool m);
  137. bool m_IsTerminal;
  138. bool m_IsDead;
  139. private:
  140. std::vector<const Sample*> m_Input;
  141. std::vector<Sample*> m_Output;
  142. void (*UpdateInfo)(int n,void *);
  143. int m_HostID;
  144. };
  145. class AudioDriver : public SpiralPlugin
  146. {
  147. public:
  148. /* if this is an ALWAYS process then ProcessAudio must
  149. always be called regardless whether it has something to
  150. process or not, so it is run along side GUI commands,
  151. ala ExecuteCommands, and is run even if paused.
  152. If its MANUAL we are the ones doing the pushing of data
  153. so we don't have to worry about it if we aren't hooked up,
  154. and we do have to worry about synchronization with other
  155. plugins, so ProcessAudio should be run along side of
  156. regular audio updates, ala Execute. This is eg. for
  157. a File Output driver.
  158. NEVER means we never need to run ProcessAudio, eg,
  159. a dummy audio driver.
  160. */
  161. enum AudioProcessType { ALWAYS, MANUAL, NEVER };
  162. virtual bool IsAudioDriver() { return true; }
  163. virtual void ProcessAudio()=0;
  164. virtual AudioProcessType ProcessType() { return NEVER; }
  165. // Callbacks to main engine. Should only called by plugin hosts.
  166. void SetChangeBufferAndSampleRateCallback(void(*s)(long unsigned int, long unsigned int, void *)) { ChangeBufferAndSampleRate = s; } ;
  167. protected:
  168. void (*ChangeBufferAndSampleRate)(long unsigned int BufferSize, long unsigned int SampleRate, void *);
  169. };
  170. #endif