Audio plugin host https://kx.studio/carla
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.

251 lines
7.0KB

  1. /*
  2. * Carla Tests
  3. * Copyright (C) 2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "CarlaLibUtils.hpp"
  18. // -----------------------------------------------------------------------
  19. struct OpenInfo {
  20. ulong size1; // ??
  21. ulong size2; // 12
  22. long sampleRate;
  23. long bufferSize;
  24. };
  25. struct DevInfo {
  26. ulong size; // 8288
  27. char name[32];
  28. long channelCount; // max limited to 255
  29. char channelNames[256][32];
  30. unsigned long defaultChannels[8];
  31. unsigned long stereoPairs[4];
  32. unsigned long eventBufferSize;
  33. long version;
  34. };
  35. struct AudioInfo {
  36. ulong size; // 12
  37. long sampleRate;
  38. long bufferSize;
  39. };
  40. struct BusInfo {
  41. ulong size; // 40
  42. ulong channel;
  43. char name[32];
  44. };
  45. struct EventInfo {
  46. ulong size; // 36
  47. ulong bus[32];
  48. };
  49. struct Event { // 24
  50. ushort type;
  51. uchar d1, d2;
  52. ulong s1, s2, s3, s4, s5;
  53. };
  54. struct EventBuffer {
  55. ulong size1; // 20
  56. ulong size2; // 24
  57. ulong count;
  58. ulong maxCount;
  59. Event* buf;
  60. };
  61. struct AudioInInfo {
  62. ulong size; // 1116
  63. EventBuffer evBuf;
  64. unsigned long channels[8];
  65. float* audioBuf[256];
  66. long tickStart;
  67. ulong frames;
  68. ulong playMode;
  69. ulong tempo; // bpm
  70. ulong signNumerator;
  71. ulong signDenominator;
  72. long loopStartPos;
  73. long loopEndPos;
  74. ulong loopOn;
  75. } ReWireDriveParams;
  76. struct AudioOutInfo {
  77. ulong size; // 56
  78. EventBuffer evBuf;
  79. ulong channels[8];
  80. };
  81. // -----------------------------------------------------------------------
  82. typedef void (*Fn_RWDEFCloseDevice)();
  83. typedef void (*Fn_RWDEFDriveAudio)(AudioInInfo* in, AudioOutInfo* out);
  84. typedef void (*Fn_RWDEFGetDeviceInfo)(DevInfo* info);
  85. typedef void (*Fn_RWDEFGetDeviceNameAndVersion)(long* version, char* name);
  86. typedef void (*Fn_RWDEFGetEventBusInfo)(ushort index, BusInfo* info);
  87. typedef void (*Fn_RWDEFGetEventChannelInfo)(void* v1, void* v2);
  88. typedef void (*Fn_RWDEFGetEventControllerInfo)(void* v1, ushort index, void* v2);
  89. typedef void (*Fn_RWDEFGetEventInfo)(EventInfo* info);
  90. typedef void (*Fn_RWDEFGetEventNoteInfo)(void* v1, ushort index, void* v2);
  91. typedef void (*Fn_RWDEFIdle)();
  92. typedef char (*Fn_RWDEFIsCloseOK)();
  93. typedef char (*Fn_RWDEFIsPanelAppLaunched)();
  94. typedef int (*Fn_RWDEFLaunchPanelApp)();
  95. typedef int (*Fn_RWDEFOpenDevice)(OpenInfo* info);
  96. typedef int (*Fn_RWDEFQuitPanelApp)();
  97. typedef void (*Fn_RWDEFSetAudioInfo)(AudioInfo* info);
  98. // -----------------------------------------------------------------------------
  99. struct RewireBridge {
  100. void* lib;
  101. Fn_RWDEFCloseDevice RWDEFCloseDevice;
  102. Fn_RWDEFDriveAudio RWDEFDriveAudio;
  103. Fn_RWDEFGetDeviceInfo RWDEFGetDeviceInfo;
  104. Fn_RWDEFGetDeviceNameAndVersion RWDEFGetDeviceNameAndVersion;
  105. Fn_RWDEFGetEventBusInfo RWDEFGetEventBusInfo;
  106. Fn_RWDEFGetEventChannelInfo RWDEFGetEventChannelInfo;
  107. Fn_RWDEFGetEventControllerInfo RWDEFGetEventControllerInfo;
  108. Fn_RWDEFGetEventInfo RWDEFGetEventInfo;
  109. Fn_RWDEFGetEventNoteInfo RWDEFGetEventNoteInfo;
  110. Fn_RWDEFIdle RWDEFIdle;
  111. Fn_RWDEFIsCloseOK RWDEFIsCloseOK;
  112. Fn_RWDEFIsPanelAppLaunched RWDEFIsPanelAppLaunched;
  113. Fn_RWDEFLaunchPanelApp RWDEFLaunchPanelApp;
  114. Fn_RWDEFOpenDevice RWDEFOpenDevice;
  115. Fn_RWDEFQuitPanelApp RWDEFQuitPanelApp;
  116. Fn_RWDEFSetAudioInfo RWDEFSetAudioInfo;
  117. RewireBridge(const char* const filename)
  118. : lib(nullptr),
  119. RWDEFCloseDevice(nullptr),
  120. RWDEFDriveAudio(nullptr),
  121. RWDEFGetDeviceInfo(nullptr),
  122. RWDEFGetDeviceNameAndVersion(nullptr),
  123. RWDEFGetEventBusInfo(nullptr),
  124. RWDEFGetEventChannelInfo(nullptr),
  125. RWDEFGetEventControllerInfo(nullptr),
  126. RWDEFGetEventInfo(nullptr),
  127. RWDEFGetEventNoteInfo(nullptr),
  128. RWDEFIdle(nullptr),
  129. RWDEFIsCloseOK(nullptr),
  130. RWDEFIsPanelAppLaunched(nullptr),
  131. RWDEFLaunchPanelApp(nullptr),
  132. RWDEFOpenDevice(nullptr),
  133. RWDEFQuitPanelApp(nullptr),
  134. RWDEFSetAudioInfo(nullptr)
  135. {
  136. lib = lib_open(filename);
  137. if (lib == nullptr)
  138. {
  139. fprintf(stderr, "Failed to load DLL, reason:\n%s\n", lib_error(filename));
  140. return;
  141. }
  142. else
  143. {
  144. fprintf(stdout, "loaded sucessfully!\n");
  145. }
  146. #define JOIN(a, b) a ## b
  147. #define LIB_SYMBOL(NAME) NAME = (Fn_##NAME)lib_symbol(lib, #NAME);
  148. LIB_SYMBOL(RWDEFCloseDevice)
  149. LIB_SYMBOL(RWDEFDriveAudio)
  150. LIB_SYMBOL(RWDEFGetDeviceInfo)
  151. LIB_SYMBOL(RWDEFGetDeviceNameAndVersion)
  152. LIB_SYMBOL(RWDEFGetEventBusInfo)
  153. LIB_SYMBOL(RWDEFGetEventChannelInfo)
  154. LIB_SYMBOL(RWDEFGetEventControllerInfo)
  155. LIB_SYMBOL(RWDEFGetEventInfo)
  156. LIB_SYMBOL(RWDEFGetEventNoteInfo)
  157. LIB_SYMBOL(RWDEFIdle)
  158. LIB_SYMBOL(RWDEFIsCloseOK)
  159. LIB_SYMBOL(RWDEFIsPanelAppLaunched)
  160. LIB_SYMBOL(RWDEFLaunchPanelApp)
  161. LIB_SYMBOL(RWDEFOpenDevice)
  162. LIB_SYMBOL(RWDEFQuitPanelApp)
  163. LIB_SYMBOL(RWDEFSetAudioInfo)
  164. #undef JOIN
  165. #undef LIB_SYMBOL
  166. }
  167. ~RewireBridge()
  168. {
  169. if (lib != nullptr)
  170. {
  171. lib_close(lib);
  172. lib = nullptr;
  173. }
  174. }
  175. };
  176. // -----------------------------------------------------------------------
  177. int main(/*int argc, char* argv[]*/)
  178. {
  179. static const char* const filename = "C:\\Program Files\\Waves\\ReWire\\WavesReWireDevice.dll";
  180. // static const char* const filename = "C:\\Program Files\\AudioGL\\AudioGL.dll";
  181. RewireBridge bridge(filename);
  182. DevInfo devInfo;
  183. carla_zeroStruct<DevInfo>(devInfo);
  184. devInfo.size = 8288;
  185. (bridge.RWDEFGetDeviceInfo)(&devInfo);
  186. carla_stdout("Ok, this is the info:");
  187. carla_stdout("\tVersion: %i", devInfo.version);
  188. carla_stdout("\tName: \"%s\"", devInfo.name);
  189. carla_stdout("\tChannels: %l", devInfo.channelCount);
  190. for (long i=0; i < devInfo.channelCount; ++i)
  191. carla_stdout("\t\t#%i: \"%s\"", i+1, devInfo.channelNames[i]);
  192. OpenInfo info;
  193. info.size1 = sizeof(OpenInfo);
  194. info.size2 = 12;
  195. info.sampleRate = 44100;
  196. info.bufferSize = 512;
  197. (bridge.RWDEFOpenDevice)(&info);
  198. #if 0
  199. carla_stdout("Starting panel...");
  200. (bridge.RWDEFLaunchPanelApp)();
  201. for (int i=0; i<500; ++i)
  202. //for (; (bridge.RWDEFIsPanelAppLaunched)() != 0;)
  203. {
  204. (bridge.RWDEFIdle)();
  205. carla_msleep(20);
  206. }
  207. (bridge.RWDEFQuitPanelApp)();
  208. #endif
  209. for (; (bridge.RWDEFIsCloseOK)() == 0;)
  210. carla_msleep(10);
  211. (bridge.RWDEFCloseDevice)();
  212. return 0;
  213. }