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.

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