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.

133 lines
4.0KB

  1. /* SpiralSound
  2. * Copyleft (C) 2001 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 "../SpiralPlugin.h"
  19. #include "../../RiffWav.h"
  20. #include <FL/Fl_Pixmap.H>
  21. #include <map>
  22. #include <glib.h>
  23. #include <jack/jack.h>
  24. typedef jack_default_audio_sample_t sample_t;
  25. #ifndef JackPLUGIN
  26. #define JackPLUGIN
  27. const int NUM_INPUTS = 8;
  28. const int NUM_OUTPUTS = 8;
  29. const int MAX_INPUTPORTS = 256;
  30. const int MAX_OUTPUTPORTS = 256;
  31. class JackClient
  32. {
  33. public:
  34. static JackClient *Get() { if(!m_Singleton) m_Singleton=new JackClient; return m_Singleton; }
  35. static void PackUpAndGoHome() { if(m_Singleton) { delete m_Singleton; m_Singleton=NULL; } }
  36. bool Attach();
  37. void Detach();
  38. bool IsAttached() { return m_Attached; }
  39. void SetCallback(void(*Run)(void*, bool m),void *Context) { RunCallback=Run; RunContext=Context; }
  40. void GetPortNames(vector<string> &InputNames,vector<string> &OutputNames);
  41. void ConnectInput(int n, const string &JackPort);
  42. void ConnectOutput(int n, const string &JackPort);
  43. string GetInputName(int ID) { return m_InputPortMap[ID]->Name; }
  44. string GetOutputName(int ID) { return m_OutputPortMap[ID]->Name; }
  45. void SetInputBuf(int ID, float* s);
  46. void SetOutputBuf(int ID, float* s);
  47. protected:
  48. JackClient();
  49. ~JackClient();
  50. static int Process(long unsigned int n, void *o);
  51. static int OnBufSizeChange(long unsigned int n, void *o);
  52. static int OnSRateChange(long unsigned int n, void *o);
  53. static void OnJackShutdown(void *o);
  54. private:
  55. class JackPort
  56. {
  57. public:
  58. JackPort::JackPort() :
  59. Connected(false),Buf(NULL),Port(NULL) {}
  60. string Name;
  61. bool Connected;
  62. float* Buf;
  63. jack_port_t* Port;
  64. string ConnectedTo;
  65. };
  66. static JackClient* m_Singleton;
  67. static jack_client_t* m_Client;
  68. static map<int,JackPort*> m_InputPortMap;
  69. static map<int,JackPort*> m_OutputPortMap;
  70. static long unsigned int m_BufferSize;
  71. static long unsigned int m_SampleRate;
  72. static bool m_Attached;
  73. static void(*RunCallback)(void*, bool m);
  74. static void *RunContext;
  75. };
  76. ///////////////////////////////////////////////////
  77. class JackPlugin : public SpiralPlugin
  78. {
  79. public:
  80. JackPlugin();
  81. virtual ~JackPlugin();
  82. virtual PluginInfo& Initialise(const HostInfo *Host);
  83. virtual SpiralGUIType* CreateGUI();
  84. virtual void Execute();
  85. virtual void StreamOut(ostream &s) {}
  86. virtual void StreamIn(istream &s) {}
  87. enum GUICommands{NONE,ATTACH,DETACH,CONNECTINPUT,CONNECTOUTPUT};
  88. struct GUIArgs
  89. {
  90. int Num;
  91. char Port[256];
  92. };
  93. private:
  94. GUIArgs m_GUIArgs;
  95. // slightly clumsy, but we have to share this data with the gui
  96. int m_NumInputPortNames;
  97. char m_InputPortNames[MAX_INPUTPORTS][256];
  98. int m_NumOutputPortNames;
  99. char m_OutputPortNames[MAX_OUTPUTPORTS][256];
  100. void Attach() { JackClient::Get()->Attach(); }
  101. void Detach() { JackClient::Get()->Detach(); }
  102. void GetPortNames(vector<string> &InputNames,vector<string> &OutputNames) { JackClient::Get()->GetPortNames(InputNames,OutputNames); }
  103. void ConnectInput(int n, const string &JackPort) { JackClient::Get()->ConnectInput(n,JackPort); }
  104. void ConnectOutput(int n, const string &JackPort) { JackClient::Get()->ConnectOutput(n,JackPort); }
  105. static int m_RefCount;
  106. static int m_NoExecuted;
  107. bool m_UpdateNames;
  108. bool m_Connected;
  109. };
  110. #endif