* @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. */
| 139 | * selection; a selection whose device disappeared becomes -1. |
| 140 | */ |
| 141 | static 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. |
no test coverage detected