MCPcopy Create free account
hub / github.com/davy7125/polyphone / getCurrentDeviceIndex

Method getCurrentDeviceIndex

sources/context/audiodevice.cpp:124–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124int AudioDevice::getCurrentDeviceIndex(QList<AudioDevice::HostInfo> hosts, QString config)
125{
126 if (config == "none")
127 return -1;
128
129 // Find the host identifier and device name
130 int api;
131 QString deviceName;
132 getApiAndDeviceNameFromConfig(config, api, deviceName);
133 QString hostIdentifier = QString::fromStdString(RtAudio::getApiName((RtAudio::Api)api).c_str());
134
135 int currentIndex = 0;
136 int exactMatch = -1;
137 int defaultMatch = -1;
138 HostInfo hostInfo;
139 DeviceInfo deviceInfo;
140 for (int i = 0; i < hosts.count(); i++)
141 {
142 hostInfo = hosts[i];
143 if (hostInfo.identifier == hostIdentifier)
144 {
145 for (int j = 0; j < hostInfo.devices.count(); j++)
146 {
147 deviceInfo = hostInfo.devices[j];
148 if (deviceInfo.name == deviceName)
149 {
150 exactMatch = currentIndex;
151 break;
152 }
153 if (deviceInfo.isDefault)
154 {
155 if (deviceName == "")
156 {
157 exactMatch = currentIndex;
158 break;
159 }
160 defaultMatch = currentIndex;
161 }
162 currentIndex++;
163 }
164 break;
165 }
166 else
167 currentIndex += hostInfo.devices.count();
168 }
169
170 return exactMatch != -1 ? exactMatch : defaultMatch;
171}
172
173void AudioDevice::getApiAndDeviceNameFromConfig(QString config, int &api, QString &deviceName)
174{

Callers

nothing calls this directly

Calls 1

countMethod · 0.45

Tested by

no test coverage detected