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.

173 lines
4.7KB

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