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.

187 lines
3.3KB

  1. #include <string.h>
  2. #include "asiodrivers.h"
  3. AsioDrivers* asioDrivers = 0;
  4. bool loadAsioDriver(char *name);
  5. bool loadAsioDriver(char *name)
  6. {
  7. if(!asioDrivers)
  8. asioDrivers = new AsioDrivers();
  9. if(asioDrivers)
  10. return asioDrivers->loadDriver(name);
  11. return false;
  12. }
  13. //------------------------------------------------------------------------------------
  14. #if MAC
  15. bool resolveASIO(unsigned long aconnID);
  16. AsioDrivers::AsioDrivers() : CodeFragments("ASIO Drivers", 'AsDr', 'Asio')
  17. {
  18. connID = -1;
  19. curIndex = -1;
  20. }
  21. AsioDrivers::~AsioDrivers()
  22. {
  23. removeCurrentDriver();
  24. }
  25. bool AsioDrivers::getCurrentDriverName(char *name)
  26. {
  27. if(curIndex >= 0)
  28. return getName(curIndex, name);
  29. return false;
  30. }
  31. long AsioDrivers::getDriverNames(char **names, long maxDrivers)
  32. {
  33. for(long i = 0; i < getNumFragments() && i < maxDrivers; i++)
  34. getName(i, names[i]);
  35. return getNumFragments() < maxDrivers ? getNumFragments() : maxDrivers;
  36. }
  37. bool AsioDrivers::loadDriver(char *name)
  38. {
  39. char dname[64];
  40. unsigned long newID;
  41. for(long i = 0; i < getNumFragments(); i++)
  42. {
  43. if(getName(i, dname) && !strcmp(name, dname))
  44. {
  45. if(newInstance(i, &newID))
  46. {
  47. if(resolveASIO(newID))
  48. {
  49. if(connID != -1)
  50. removeInstance(curIndex, connID);
  51. curIndex = i;
  52. connID = newID;
  53. return true;
  54. }
  55. }
  56. break;
  57. }
  58. }
  59. return false;
  60. }
  61. void AsioDrivers::removeCurrentDriver()
  62. {
  63. if(connID != -1)
  64. removeInstance(curIndex, connID);
  65. connID = -1;
  66. curIndex = -1;
  67. }
  68. //------------------------------------------------------------------------------------
  69. #elif WINDOWS
  70. #include "iasiodrv.h"
  71. extern IASIO* theAsioDriver;
  72. AsioDrivers::AsioDrivers() : AsioDriverList()
  73. {
  74. curIndex = -1;
  75. }
  76. AsioDrivers::~AsioDrivers()
  77. {
  78. }
  79. bool AsioDrivers::getCurrentDriverName(char *name)
  80. {
  81. if(curIndex >= 0)
  82. return asioGetDriverName(curIndex, name, 32) == 0 ? true : false;
  83. name[0] = 0;
  84. return false;
  85. }
  86. long AsioDrivers::getDriverNames(char **names, long maxDrivers)
  87. {
  88. for(long i = 0; i < asioGetNumDev() && i < maxDrivers; i++)
  89. asioGetDriverName(i, names[i], 32);
  90. return asioGetNumDev() < maxDrivers ? asioGetNumDev() : maxDrivers;
  91. }
  92. bool AsioDrivers::loadDriver(char *name)
  93. {
  94. char dname[64];
  95. char curName[64];
  96. for(long i = 0; i < asioGetNumDev(); i++)
  97. {
  98. if(!asioGetDriverName(i, dname, 32) && !strcmp(name, dname))
  99. {
  100. curName[0] = 0;
  101. getCurrentDriverName(curName); // in case we fail...
  102. removeCurrentDriver();
  103. if(!asioOpenDriver(i, (void **)&theAsioDriver))
  104. {
  105. curIndex = i;
  106. return true;
  107. }
  108. else
  109. {
  110. theAsioDriver = 0;
  111. if(curName[0] && strcmp(dname, curName))
  112. loadDriver(curName); // try restore
  113. }
  114. break;
  115. }
  116. }
  117. return false;
  118. }
  119. void AsioDrivers::removeCurrentDriver()
  120. {
  121. if(curIndex != -1)
  122. asioCloseDriver(curIndex);
  123. curIndex = -1;
  124. }
  125. #elif SGI || BEOS
  126. #include "asiolist.h"
  127. AsioDrivers::AsioDrivers()
  128. : AsioDriverList()
  129. {
  130. curIndex = -1;
  131. }
  132. AsioDrivers::~AsioDrivers()
  133. {
  134. }
  135. bool AsioDrivers::getCurrentDriverName(char *name)
  136. {
  137. return false;
  138. }
  139. long AsioDrivers::getDriverNames(char **names, long maxDrivers)
  140. {
  141. return 0;
  142. }
  143. bool AsioDrivers::loadDriver(char *name)
  144. {
  145. return false;
  146. }
  147. void AsioDrivers::removeCurrentDriver()
  148. {
  149. }
  150. #else
  151. #error implement me
  152. #endif