diff --git a/src/avmodel.cpp b/src/avmodel.cpp index 65b83f78c907a056afcaaa44e1426125bb4d07fc..c597240e5c6a39b4204ff4b68b9f81ce13a9a400 100644 --- a/src/avmodel.cpp +++ b/src/avmodel.cpp @@ -721,10 +721,10 @@ AVModelPimpl::getDevice(int type) const std::string result = ""; std::vector<std::string> devices; switch (type) { - case 0: // INPUT + case 1: // INPUT devices = linked_.getAudioInputDevices(); break; - case 1: // OUTPUT + case 0: // OUTPUT case 2: // RINGTONE devices = linked_.getAudioOutputDevices(); break; @@ -734,17 +734,18 @@ AVModelPimpl::getDevice(int type) const QStringList currentDevicesIdx = ConfigurationManager::instance() .getCurrentAudioDevicesIndex(); try { - if (currentDevicesIdx.size() < 3 - || devices.size() != static_cast<size_t>(currentDevicesIdx.size())) { + if (currentDevicesIdx.size() < 3) { // Should not happen, but cannot retrieve current ringtone device return ""; } auto deviceIdx = currentDevicesIdx[type].toUInt(); - if (deviceIdx >= devices.size()) { - // Incorrect device index - result = devices[0]; + for (const auto& dev : devices) { + int idx = ConfigurationManager::instance().getAudioInputDeviceIndex(dev.c_str()); + if (idx == deviceIdx) { + return dev; + } } - result = devices[deviceIdx]; + return ""; } catch (std::bad_alloc& ba) { qWarning() << "bad_alloc caught: " << ba.what(); return "";