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.

116 lines
3.6KB

  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. class JackClient
  30. {
  31. public:
  32. static JackClient *Get() { if(!m_Singleton) m_Singleton=new JackClient; return m_Singleton; }
  33. static void PackUpAndGoHome() { if(m_Singleton) { delete m_Singleton; m_Singleton=NULL; } }
  34. bool Attach();
  35. void Detach();
  36. bool IsAttached() { return m_Attached; }
  37. void SetCallback(void(*Run)(void*, bool m),void *Context) { RunCallback=Run; RunContext=Context; }
  38. void GetPortNames(vector<string> &InputNames,vector<string> &OutputNames);
  39. void ConnectInput(int n, const string &JackPort);
  40. void ConnectOutput(int n, const string &JackPort);
  41. string GetInputName(int ID) { return m_InputPortMap[ID]->Name; }
  42. string GetOutputName(int ID) { return m_OutputPortMap[ID]->Name; }
  43. void SetInputBuf(int ID, float* s);
  44. void SetOutputBuf(int ID, float* s);
  45. protected:
  46. JackClient();
  47. ~JackClient();
  48. static int Process(long unsigned int n, void *o);
  49. static int OnBufSizeChange(long unsigned int n, void *o);
  50. static int OnSRateChange(long unsigned int n, void *o);
  51. static void OnJackShutdown(void *o);
  52. private:
  53. class JackPort
  54. {
  55. public:
  56. JackPort::JackPort() :
  57. Connected(false),Buf(NULL),Port(NULL) {}
  58. string Name;
  59. bool Connected;
  60. float* Buf;
  61. jack_port_t* Port;
  62. string ConnectedTo;
  63. };
  64. static JackClient* m_Singleton;
  65. static jack_client_t* m_Client;
  66. static map<int,JackPort*> m_InputPortMap;
  67. static map<int,JackPort*> m_OutputPortMap;
  68. static long unsigned int m_BufferSize;
  69. static long unsigned int m_SampleRate;
  70. static bool m_Attached;
  71. static void(*RunCallback)(void*, bool m);
  72. static void *RunContext;
  73. };
  74. ///////////////////////////////////////////////////
  75. class JackPlugin : public SpiralPlugin
  76. {
  77. public:
  78. JackPlugin();
  79. virtual ~JackPlugin();
  80. virtual PluginInfo& Initialise(const HostInfo *Host);
  81. virtual SpiralGUIType* CreateGUI();
  82. virtual void Execute();
  83. virtual void StreamOut(ostream &s) {}
  84. virtual void StreamIn(istream &s) {}
  85. // has to be defined in the plugin
  86. virtual void UpdateGUI() { Fl::check(); }
  87. void Attach() { JackClient::Get()->Attach(); }
  88. void Detach() { JackClient::Get()->Detach(); }
  89. void GetPortNames(vector<string> &InputNames,vector<string> &OutputNames) { JackClient::Get()->GetPortNames(InputNames,OutputNames); }
  90. void ConnectInput(int n, const string &JackPort) { JackClient::Get()->ConnectInput(n,JackPort); }
  91. void ConnectOutput(int n, const string &JackPort) { JackClient::Get()->ConnectOutput(n,JackPort); }
  92. private:
  93. static int m_RefCount;
  94. static int m_NoExecuted;
  95. };
  96. #endif