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.

175 lines
4.9KB

  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 FRAGSIZE;
  46. int FRAGCOUNT;
  47. int SAMPLERATE;
  48. std::string OUTPUTFILE;
  49. std::string MIDIFILE;
  50. int POLY;
  51. unsigned GUI_COLOUR;
  52. unsigned SCOPE_BG_COLOUR;
  53. unsigned SCOPE_FG_COLOUR;
  54. unsigned SCOPE_SEL_COLOUR;
  55. unsigned SCOPE_IND_COLOUR;
  56. unsigned SCOPE_MRK_COLOUR;
  57. unsigned GUICOL_Device;
  58. unsigned GUIDEVICE_Box;
  59. };
  60. /////////////////////////////////////////////////////////////////////
  61. class ChannelHandler;
  62. class SpiralPlugin
  63. {
  64. public:
  65. SpiralPlugin();
  66. virtual ~SpiralPlugin();
  67. virtual PluginInfo& Initialise(const HostInfo *Host);
  68. // execute the audio
  69. virtual void Execute()=0;
  70. // run the commands from the GUI
  71. virtual void ExecuteCommands() {}
  72. // create the GUI, do not store the pointer - it wont be threadsafe to use it
  73. virtual SpiralGUIType* CreateGUI()=0;
  74. // stream the plugins state
  75. virtual void StreamOut(std::ostream &s)=0;
  76. virtual void StreamIn(std::istream &s)=0;
  77. // stuff here gets saved in filename_files directory
  78. // you must return true if this feature is used.
  79. virtual bool SaveExternalFiles(const std::string &Dir) { return false; }
  80. virtual void LoadExternalFiles(const std::string &Dir) {}
  81. const HostInfo* GetHostInfo() { return m_HostInfo; }
  82. bool GetOutput(unsigned int n, Sample **s);
  83. bool SetInput(unsigned int n, const Sample *s);
  84. const Sample* GetInput(unsigned int n) { return m_Input[n]; }
  85. std::string GetName() { return m_PluginInfo.Name; }
  86. void UpdatePluginInfoWithHost();
  87. void SetInPortType(PluginInfo &pinfo, int port, Sample::SampleType type);
  88. void SetOutPortType(PluginInfo &pinfo, int port, Sample::SampleType type);
  89. // Callbacks to main engine. Should only called by plugin hosts.
  90. void SetUpdateInfoCallback(int ID, void(*s)(int, void *));
  91. void SetUpdateCallback(void (*s)(void*,bool m)) { cb_Update=s; }
  92. void SetBlockingCallback(void (*s)(void*,bool m)) { cb_Blocking=s; }
  93. void SetParent(void *s) { m_Parent=s; }
  94. void UpdateChannelHandler();
  95. // is the plugin connected to an external device (oss/alsa/jack)
  96. bool IsTerminal() { return m_IsTerminal; }
  97. ChannelHandler *GetChannelHandler() { return m_AudioCH; }
  98. protected:
  99. ChannelHandler *m_AudioCH;
  100. void SetOutput(int n,int p, float s)
  101. { if (m_Output[n]) m_Output[n]->Set(p,s); }
  102. float GetInput(int n,int p)
  103. { if (m_Input[n]) return (*m_Input[n])[p]; else return 0.0; }
  104. void SetOutputPitch(int n,int p, float s)
  105. { if (m_Output[n]) m_Output[n]->Set(p,(s/MAX_FREQ*2)-1.0f); }
  106. float GetInputPitch(int n,int p)
  107. { if (m_Input[n]) return ((*m_Input[n])[p]+1.0f)*MAX_FREQ/2; else return 0.0; }
  108. void MixOutput(int n,int p, float s)
  109. { if (m_Output[n]) m_Output[n]->Set(p,s+(*m_Output[n])[p]); }
  110. bool InputExists(int n) { return m_Input[n]!=NULL; }
  111. bool OutputExists(int n) { return m_Output[n]!=NULL; }
  112. void AddOutput();
  113. void RemoveOutput();
  114. void RemoveAllOutputs();
  115. void AddInput();
  116. void RemoveInput();
  117. void RemoveAllInputs();
  118. // the ID number assigned to us by ssm
  119. int GetID() { return m_HostID; }
  120. Sample* GetOutputBuf(int n) { return m_Output[n]; }
  121. const HostInfo *m_HostInfo;
  122. PluginInfo m_PluginInfo;
  123. int m_Version;
  124. // needed for jack
  125. void (*cb_Update)(void*o ,bool m);
  126. void *m_Parent;
  127. // tell the engine that we are taking control of the
  128. // timing for output.
  129. void (*cb_Blocking)(void*o ,bool m);
  130. bool m_IsTerminal;
  131. private:
  132. std::vector<const Sample*> m_Input;
  133. std::vector<Sample*> m_Output;
  134. void (*UpdateInfo)(int n,void *);
  135. int m_HostID;
  136. };
  137. #endif