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.

178 lines
5.0KB

  1. /*
  2. Copyright (C) 2006-2011 Grame
  3. Permission is hereby granted, free of charge, to any person obtaining
  4. a copy of this software and associated documentation files
  5. (the "Software"), to deal in the Software without restriction,
  6. including without limitation the rights to use, copy, modify, merge,
  7. publish, distribute, sublicense, and/or sell copies of the Software,
  8. and to permit persons to whom the Software is furnished to do so,
  9. subject to the following conditions:
  10. The above copyright notice and this permission notice shall be
  11. included in all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  15. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  16. ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  17. CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. */
  20. #ifndef _asiosmpl_
  21. #define _asiosmpl_
  22. #include "asiosys.h"
  23. // Globals
  24. static int kBlockFrames = 256;
  25. static int kNumInputs = 4;
  26. static int kNumOutputs = 4;
  27. #if WINDOWS
  28. #include "jack.h"
  29. #include "rpc.h"
  30. #include "rpcndr.h"
  31. #ifndef COM_NO_WINDOWS_H
  32. #ifdef __MINGW32__
  33. #include <winsock2.h>
  34. #endif
  35. #include <windows.h>
  36. #include "ole2.h"
  37. #endif
  38. #include "combase.h"
  39. #include "iasiodrv.h"
  40. #define PATH_SEP "\\"
  41. #include <list>
  42. #include <string>
  43. class JackRouter : public IASIO, public CUnknown
  44. {
  45. public:
  46. JackRouter(LPUNKNOWN pUnk, HRESULT *phr);
  47. ~JackRouter();
  48. DECLARE_IUNKNOWN
  49. //STDMETHODIMP QueryInterface(REFIID riid, void **ppv) { \
  50. // return GetOwner()->QueryInterface(riid,ppv); \
  51. //}; \
  52. //STDMETHODIMP_(ULONG) AddRef() { \
  53. // return GetOwner()->AddRef(); \
  54. //}; \
  55. //STDMETHODIMP_(ULONG) Release() { \
  56. // return GetOwner()->Release(); \
  57. //};
  58. // Factory method
  59. static CUnknown *CreateInstance(LPUNKNOWN pUnk, HRESULT *phr);
  60. // IUnknown
  61. virtual HRESULT STDMETHODCALLTYPE NonDelegatingQueryInterface(REFIID riid,void **ppvObject);
  62. #else
  63. #include "asiodrvr.h"
  64. //---------------------------------------------------------------------------------------------
  65. class JackRouter : public AsioDriver
  66. {
  67. public:
  68. JackRouter();
  69. ~JackRouter();
  70. #endif
  71. static int processCallback(jack_nframes_t nframes, void* arg);
  72. static void connectCallback(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
  73. static void shutdownCallback(void* arg);
  74. ASIOBool init(void* sysRef);
  75. void getDriverName(char *name); // max 32 bytes incl. terminating zero
  76. long getDriverVersion();
  77. void getErrorMessage(char *string); // max 128 bytes incl.
  78. ASIOError start();
  79. ASIOError stop();
  80. ASIOError getChannels(long *numInputChannels, long *numOutputChannels);
  81. ASIOError getLatencies(long *inputLatency, long *outputLatency);
  82. ASIOError getBufferSize(long *minSize, long *maxSize,
  83. long *preferredSize, long *granularity);
  84. ASIOError canSampleRate(ASIOSampleRate sampleRate);
  85. ASIOError getSampleRate(ASIOSampleRate *sampleRate);
  86. ASIOError setSampleRate(ASIOSampleRate sampleRate);
  87. ASIOError getClockSources(ASIOClockSource *clocks, long *numSources);
  88. ASIOError setClockSource(long index);
  89. ASIOError getSamplePosition(ASIOSamples *sPos, ASIOTimeStamp *tStamp);
  90. ASIOError getChannelInfo(ASIOChannelInfo *info);
  91. ASIOError createBuffers(ASIOBufferInfo *bufferInfos, long numChannels,
  92. long bufferSize, ASIOCallbacks *callbacks);
  93. ASIOError disposeBuffers();
  94. ASIOError controlPanel();
  95. ASIOError future(long selector, void *opt);
  96. ASIOError outputReady();
  97. void bufferSwitch();
  98. long getMilliSeconds() {return fMilliSeconds;}
  99. static std::list<std::pair<std::string, std::string> > fConnections; // Connections list
  100. private:
  101. void bufferSwitchX();
  102. double fSamplePosition;
  103. ASIOCallbacks* fCallbacks;
  104. ASIOTime fAsioTime;
  105. ASIOTimeStamp fTheSystemTime;
  106. void** fInputBuffers;
  107. void** fOutputBuffers;
  108. long* fInMap;
  109. long* fOutMap;
  110. long fInputLatency;
  111. long fOutputLatency;
  112. long fActiveInputs;
  113. long fActiveOutputs;
  114. long fToggle;
  115. long fMilliSeconds;
  116. bool fRunning;
  117. bool fFirstActivate;
  118. bool fFloatSample;
  119. bool fAliasSystem;
  120. bool fTimeInfoMode, fTcRead;
  121. char fErrorMessage[128];
  122. bool fAutoConnectIn;
  123. bool fAutoConnectOut;
  124. // Jack part
  125. jack_client_t* fClient;
  126. jack_port_t** fInputPorts;
  127. jack_port_t** fOutputPorts;
  128. long fBufferSize;
  129. ASIOSampleRate fSampleRate;
  130. void autoConnect();
  131. void saveConnections();
  132. void restoreConnections();
  133. void processInputs();
  134. void processOutputs();
  135. };
  136. #endif