Cleanup
[carla.git] / source / modules / rtaudio / include / asiodrivers.cpp
blob5f56454c20efcae5f32291c51632ef7962c0e302
1 #include <string.h>
2 #include "asiodrivers.h"
4 AsioDrivers* asioDrivers = 0;
6 bool loadAsioDriver(char *name);
8 bool loadAsioDriver(char *name)
10 if(!asioDrivers)
11 asioDrivers = new AsioDrivers();
12 if(asioDrivers)
13 return asioDrivers->loadDriver(name);
14 return false;
17 //------------------------------------------------------------------------------------
19 #if MAC
21 bool resolveASIO(unsigned long aconnID);
23 AsioDrivers::AsioDrivers() : CodeFragments("ASIO Drivers", 'AsDr', 'Asio')
25 connID = -1;
26 curIndex = -1;
29 AsioDrivers::~AsioDrivers()
31 removeCurrentDriver();
34 bool AsioDrivers::getCurrentDriverName(char *name)
36 if(curIndex >= 0)
37 return getName(curIndex, name);
38 return false;
41 long AsioDrivers::getDriverNames(char **names, long maxDrivers)
43 for(long i = 0; i < getNumFragments() && i < maxDrivers; i++)
44 getName(i, names[i]);
45 return getNumFragments() < maxDrivers ? getNumFragments() : maxDrivers;
48 bool AsioDrivers::loadDriver(char *name)
50 char dname[64];
51 unsigned long newID;
53 for(long i = 0; i < getNumFragments(); i++)
55 if(getName(i, dname) && !strcmp(name, dname))
57 if(newInstance(i, &newID))
59 if(resolveASIO(newID))
61 if(connID != -1)
62 removeInstance(curIndex, connID);
63 curIndex = i;
64 connID = newID;
65 return true;
68 break;
71 return false;
74 void AsioDrivers::removeCurrentDriver()
76 if(connID != -1)
77 removeInstance(curIndex, connID);
78 connID = -1;
79 curIndex = -1;
82 //------------------------------------------------------------------------------------
84 #elif WINDOWS
86 #include "iasiodrv.h"
88 extern IASIO* theAsioDriver;
90 AsioDrivers::AsioDrivers() : AsioDriverList()
92 curIndex = -1;
95 AsioDrivers::~AsioDrivers()
99 bool AsioDrivers::getCurrentDriverName(char *name)
101 if(curIndex >= 0)
102 return asioGetDriverName(curIndex, name, 32) == 0 ? true : false;
103 name[0] = 0;
104 return false;
107 long AsioDrivers::getDriverNames(char **names, long maxDrivers)
109 for(long i = 0; i < asioGetNumDev() && i < maxDrivers; i++)
110 asioGetDriverName(i, names[i], 32);
111 return asioGetNumDev() < maxDrivers ? asioGetNumDev() : maxDrivers;
114 bool AsioDrivers::loadDriver(char *name)
116 char dname[64];
117 char curName[64];
119 for(long i = 0; i < asioGetNumDev(); i++)
121 if(!asioGetDriverName(i, dname, 32) && !strcmp(name, dname))
123 curName[0] = 0;
124 getCurrentDriverName(curName); // in case we fail...
125 removeCurrentDriver();
127 if(!asioOpenDriver(i, (void **)&theAsioDriver))
129 curIndex = i;
130 return true;
132 else
134 theAsioDriver = 0;
135 if(curName[0] && strcmp(dname, curName))
136 loadDriver(curName); // try restore
138 break;
141 return false;
144 void AsioDrivers::removeCurrentDriver()
146 if(curIndex != -1)
147 asioCloseDriver(curIndex);
148 curIndex = -1;
151 #elif SGI || BEOS
153 #include "asiolist.h"
155 AsioDrivers::AsioDrivers()
156 : AsioDriverList()
158 curIndex = -1;
161 AsioDrivers::~AsioDrivers()
165 bool AsioDrivers::getCurrentDriverName(char *name)
167 return false;
170 long AsioDrivers::getDriverNames(char **names, long maxDrivers)
172 return 0;
175 bool AsioDrivers::loadDriver(char *name)
177 return false;
180 void AsioDrivers::removeCurrentDriver()
184 #else
185 #error implement me
186 #endif