MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / replaceDeviceList

Function replaceDeviceList

app/src/IO/Drivers/Audio.cpp:141–160  ·  view source on GitHub ↗

* @brief Replaces the device list and capabilities, remapping the selected index by device ID * so an insertion or removal earlier in the enumeration cannot silently retarget the * selection; a selection whose device disappeared becomes -1. */

Source from the content-addressed store, hash-verified

139 * selection; a selection whose device disappeared becomes -1.
140 */
141static void replaceDeviceList(ma_context* context,
142 ma_device_type type,
143 QVector<ma_device_info>& currentList,
144 const QVector<ma_device_info>& newList,
145 int& selectedIndex,
146 QVector<IO::Drivers::Audio::AudioDeviceInfo>& capabilities)
147{
148 ma_device_id selectedId = {};
149 const bool hadSelection = selectedIndex >= 0 && selectedIndex < currentList.size();
150 if (hadSelection)
151 selectedId = currentList[selectedIndex].id;
152
153 currentList = newList;
154 capabilities.clear();
155 for (const auto& info : std::as_const(currentList))
156 capabilities.append(extractCapabilities(context, info, type));
157
158 if (hadSelection)
159 selectedIndex = deviceIndexById(currentList, selectedId);
160}
161
162/**
163 * @brief Checks for changes in the audio device list and updates it if necessary.

Callers 1

checkAndUpdateDeviceListFunction · 0.85

Calls 5

extractCapabilitiesFunction · 0.85
deviceIndexByIdFunction · 0.85
sizeMethod · 0.45
clearMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected