jack2 codebase
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.

175 lines
4.6KB

  1. /*
  2. Copyright (C) 2006 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #ifndef _asiosmpl_
  16. #define _asiosmpl_
  17. #include "asiosys.h"
  18. // Globals
  19. static int kBlockFrames = 256;
  20. static int kNumInputs = 4;
  21. static int kNumOutputs = 4;
  22. #if WINDOWS
  23. #include "jack.h"
  24. #include "rpc.h"
  25. #include "rpcndr.h"
  26. #ifndef COM_NO_WINDOWS_H
  27. #include <windows.h>
  28. #include "ole2.h"
  29. #endif
  30. #include "combase.h"
  31. #include "iasiodrv.h"
  32. #define MAX_PORTS 32
  33. #define LONG_SAMPLE 1
  34. #define PATH_SEP "\\"
  35. #include <list>
  36. #include <string>
  37. class JackRouter : public IASIO, public CUnknown
  38. {
  39. public:
  40. JackRouter(LPUNKNOWN pUnk, HRESULT *phr);
  41. ~JackRouter();
  42. DECLARE_IUNKNOWN
  43. //STDMETHODIMP QueryInterface(REFIID riid, void **ppv) { \
  44. // return GetOwner()->QueryInterface(riid,ppv); \
  45. //}; \
  46. //STDMETHODIMP_(ULONG) AddRef() { \
  47. // return GetOwner()->AddRef(); \
  48. //}; \
  49. //STDMETHODIMP_(ULONG) Release() { \
  50. // return GetOwner()->Release(); \
  51. //};
  52. // Factory method
  53. static CUnknown *CreateInstance(LPUNKNOWN pUnk, HRESULT *phr);
  54. // IUnknown
  55. virtual HRESULT STDMETHODCALLTYPE NonDelegatingQueryInterface(REFIID riid,void **ppvObject);
  56. #else
  57. #include "asiodrvr.h"
  58. //---------------------------------------------------------------------------------------------
  59. class JackRouter : public AsioDriver
  60. {
  61. public:
  62. JackRouter();
  63. ~JackRouter();
  64. #endif
  65. static int process(jack_nframes_t nframes, void* arg);
  66. static void shutdown(void* arg);
  67. ASIOBool init(void* sysRef);
  68. void getDriverName(char *name); // max 32 bytes incl. terminating zero
  69. long getDriverVersion();
  70. void getErrorMessage(char *string); // max 128 bytes incl.
  71. ASIOError start();
  72. ASIOError stop();
  73. ASIOError getChannels(long *numInputChannels, long *numOutputChannels);
  74. ASIOError getLatencies(long *inputLatency, long *outputLatency);
  75. ASIOError getBufferSize(long *minSize, long *maxSize,
  76. long *preferredSize, long *granularity);
  77. ASIOError canSampleRate(ASIOSampleRate sampleRate);
  78. ASIOError getSampleRate(ASIOSampleRate *sampleRate);
  79. ASIOError setSampleRate(ASIOSampleRate sampleRate);
  80. ASIOError getClockSources(ASIOClockSource *clocks, long *numSources);
  81. ASIOError setClockSource(long index);
  82. ASIOError getSamplePosition(ASIOSamples *sPos, ASIOTimeStamp *tStamp);
  83. ASIOError getChannelInfo(ASIOChannelInfo *info);
  84. ASIOError createBuffers(ASIOBufferInfo *bufferInfos, long numChannels,
  85. long bufferSize, ASIOCallbacks *callbacks);
  86. ASIOError disposeBuffers();
  87. ASIOError controlPanel();
  88. ASIOError future(long selector, void *opt);
  89. ASIOError outputReady();
  90. void bufferSwitch();
  91. long getMilliSeconds() {return fMilliSeconds;}
  92. static bool fFirstActivate;
  93. static std::list<std::pair<std::string, std::string> > fConnections; // Connections list
  94. private:
  95. void bufferSwitchX();
  96. double fSamplePosition;
  97. ASIOCallbacks* fCallbacks;
  98. ASIOTime fAsioTime;
  99. ASIOTimeStamp fTheSystemTime;
  100. #ifdef LONG_SAMPLE
  101. long* fInputBuffers[MAX_PORTS * 2];
  102. long* fOutputBuffers[MAX_PORTS * 2];
  103. #else
  104. float* fInputBuffers[MAX_PORTS * 2];
  105. float* fOutputBuffers[MAX_PORTS * 2];
  106. #endif
  107. long fInMap[MAX_PORTS];
  108. long fOutMap[MAX_PORTS];
  109. long fInputLatency;
  110. long fOutputLatency;
  111. long fActiveInputs;
  112. long fActiveOutputs;
  113. long fToggle;
  114. long fMilliSeconds;
  115. bool fActive, fStarted;
  116. bool fTimeInfoMode, fTcRead;
  117. char fErrorMessage[128];
  118. bool fAutoConnectIn;
  119. bool fAutoConnectOut;
  120. // Jack part
  121. jack_client_t* fClient;
  122. jack_port_t* fInputPorts[MAX_PORTS];
  123. jack_port_t* fOutputPorts[MAX_PORTS];
  124. long fBufferSize;
  125. ASIOSampleRate fSampleRate;
  126. void AutoConnect();
  127. void SaveConnections();
  128. void RestoreConnections();
  129. };
  130. #endif