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.

176 lines
4.8KB

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