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.

160 lines
4.2KB

  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. #include <vector>
  19. #include <map>
  20. #include <string>
  21. #include <iostream>
  22. #include <math.h>
  23. #include <FL/Fl.h>
  24. #include <FL/Fl_Group.h>
  25. #include "../Sample.h"
  26. #include "../ChannelHandler.h"
  27. #ifndef SPIRALPLUGIN
  28. #define SPIRALPLUGIN
  29. #define SpiralGUIType Fl_Group
  30. static const float MAX_FREQ = 13000;
  31. class ChannelHander;
  32. struct PluginInfo
  33. {
  34. string Name;
  35. int Width;
  36. int Height;
  37. int NumInputs;
  38. int NumOutputs;
  39. vector<string> PortTips;
  40. vector<int> PortTypes;
  41. char BitMap[40][40][3];
  42. };
  43. struct HostInfo
  44. {
  45. int BUFSIZE;
  46. int FRAGSIZE;
  47. int FRAGCOUNT;
  48. int SAMPLERATE;
  49. string OUTPUTFILE;
  50. string MIDIFILE;
  51. int POLY;
  52. int GUI_COLOUR;
  53. };
  54. /////////////////////////////////////////////////////////////////////
  55. class ChannelHandler;
  56. class SpiralPlugin
  57. {
  58. public:
  59. SpiralPlugin();
  60. virtual ~SpiralPlugin();
  61. virtual PluginInfo& Initialise(const HostInfo *Host);
  62. // execute the audio
  63. virtual void Execute()=0;
  64. // run the commands from the GUI
  65. virtual void ExecuteCommands() {}
  66. // create the GUI, do not store the pointer - it wont be threadsafe to use it
  67. virtual SpiralGUIType* CreateGUI()=0;
  68. // stream the plugins state
  69. virtual void StreamOut(ostream &s)=0;
  70. virtual void StreamIn(istream &s)=0;
  71. // stuff here gets saved in filename_files directory
  72. // you must return true if this feature is used.
  73. virtual bool SaveExternalFiles(const string &Dir) { return false; }
  74. virtual void LoadExternalFiles(const string &Dir) {}
  75. const HostInfo* GetHostInfo() { return m_HostInfo; }
  76. bool GetOutput(unsigned int n, Sample **s);
  77. bool SetInput(unsigned int n, const Sample *s);
  78. const Sample* GetInput(unsigned int n) { return m_Input[n]; }
  79. string GetName() { return m_PluginInfo.Name; }
  80. void UpdatePluginInfoWithHost();
  81. void SetUpdateInfoCallback(int ID, void(*s)(int, void *));
  82. void SetUpdateCallback(void (*s)(void*,bool m)) { cb_Update=s; }
  83. void SetParent(void *s) { m_Parent=s; }
  84. void SetInPortType(PluginInfo &pinfo, int port, Sample::SampleType type);
  85. void SetOutPortType(PluginInfo &pinfo, int port, Sample::SampleType type);
  86. void UpdateChannelHandler();
  87. ChannelHandler *GetChannelHandler() { return m_AudioCH; }
  88. protected:
  89. ChannelHandler *m_AudioCH;
  90. void SetOutput(int n,int p, float s)
  91. { if (m_Output[n]) m_Output[n]->Set(p,s); }
  92. float GetInput(int n,int p)
  93. { if (m_Input[n]) return (*m_Input[n])[p]; else return 0.0; }
  94. void SetOutputPitch(int n,int p, float s)
  95. { if (m_Output[n]) m_Output[n]->Set(p,(s/MAX_FREQ*2)-1.0f); }
  96. float GetInputPitch(int n,int p)
  97. { if (m_Input[n]) return ((*m_Input[n])[p]+1.0f)*MAX_FREQ/2; else return 0.0; }
  98. void MixOutput(int n,int p, float s)
  99. { if (m_Output[n]) m_Output[n]->Set(p,s+(*m_Output[n])[p]); }
  100. bool InputExists(int n) { return m_Input[n]!=NULL; }
  101. bool OutputExists(int n) { return m_Output[n]!=NULL; }
  102. void AddOutput();
  103. void RemoveOutput();
  104. void RemoveAllOutputs();
  105. void AddInput();
  106. void RemoveInput();
  107. void RemoveAllInputs();
  108. // the ID number assigned to us by ssm
  109. int GetID() { return m_HostID; }
  110. Sample* GetOutputBuf(int n) { return m_Output[n]; }
  111. const HostInfo *m_HostInfo;
  112. PluginInfo m_PluginInfo;
  113. int m_Version;
  114. // needed for jack
  115. void (*cb_Update)(void*o ,bool m);
  116. void *m_Parent;
  117. private:
  118. vector<const Sample*> m_Input;
  119. vector<Sample*> m_Output;
  120. void (*UpdateInfo)(int n,void *);
  121. int m_HostID;
  122. };
  123. #endif