Browse Source

Apply shared audio changes without resetting saved preferences

master
evgeny 1 week ago
parent
commit
625846fa33
  1. 10
      tools/chatgui/src/radio_audio_engine.cpp
  2. 6
      tools/chatgui/src/radiopanel.cpp
  3. 1
      tools/chatgui/src/settingsdialog.cpp

10
tools/chatgui/src/radio_audio_engine.cpp

@ -96,8 +96,8 @@ bool RadioAudioEngine::applySettings(const QMap<QString, int>& values) {
}
next[index] = it.value();
}
if (next == m_settings) return true;
if (!m_configPath.isEmpty()) {
if (next == m_settings && !m_active) return true;
if (next != m_settings && !m_configPath.isEmpty()) {
QFile input(m_configPath);
if (!input.open(QIODevice::ReadOnly)) {
m_settingsError = QStringLiteral("Не удалось прочитать конфигурацию: %1").arg(input.errorString());
@ -154,7 +154,8 @@ void RadioAudioEngine::postSettings(const std::array<int, 6>& values, bool apply
}
auto* engine = request->engine;
auto snapshot = request->values;
QMetaObject::invokeMethod(engine, [engine, snapshot, success]() {
bool apply = request->apply;
QMetaObject::invokeMethod(engine, [engine, snapshot, success, apply]() {
bool changed = engine->m_settings != snapshot;
engine->m_settings = snapshot;
engine->m_settingsReady = true;
@ -162,7 +163,7 @@ void RadioAudioEngine::postSettings(const std::array<int, 6>& values, bool apply
if (!success) engine->m_settingsError = QStringLiteral("Ядро отклонило настройки рации");
DEBUG_INFO(DEBUG_CATEGORY_RADIO, "RadioAudio: settings applied=%d vad=%d threshold=%d hangover=%dms TX_AGC=%d "
"TX_gain=%ddB VAD_gain=%ddB", success, snapshot[0], snapshot[1], snapshot[2], snapshot[3], snapshot[4], snapshot[5]);
if (changed && engine->m_active) engine->reconfigureCapture();
if ((changed || apply) && engine->m_active) engine->reconfigureCapture();
emit engine->stateChanged();
}, Qt::QueuedConnection);
request->~SettingsRequest();
@ -176,6 +177,7 @@ void RadioAudioEngine::reconfigureCapture() {
m_capture.close();
m_voice.stopCapture();
radio_audio_capture_stop();
m_wantStereo = chat_setting_get_int(gui_bridge_get_inst(), "radio_capture_stereo", 0) != 0;
updateState();
m_capture.retryNow();
recoverDevices();

6
tools/chatgui/src/radiopanel.cpp

@ -14,6 +14,7 @@ extern "C" {
#include <QMenu>
#include <QActionGroup>
#include <QSignalBlocker>
#include <QStyle>
#include <cstring>
RadioPanel::RadioPanel(QWidget* parent) : QWidget(parent) {
@ -30,6 +31,8 @@ RadioPanel::RadioPanel(QWidget* parent) : QWidget(parent) {
for (auto* button : {m_input, m_output}) {
button->setPopupMode(QToolButton::InstantPopup);
button->setMenu(new QMenu(button));
auto* group = new QActionGroup(button->menu());
group->setExclusive(true);
row->addWidget(button);
connect(button->menu(), &QMenu::aboutToShow, this, [this, button]() { populateDevices(button, button == m_input); });
}
@ -95,8 +98,7 @@ void RadioPanel::updateState() {
void RadioPanel::populateDevices(QToolButton* button, bool capture) {
auto* menu = button->menu();
menu->clear();
auto* group = new QActionGroup(menu);
group->setExclusive(true);
auto* group = menu->findChild<QActionGroup*>();
QString selected = capture ? SoundManager::instance()->captureDevice() : SoundManager::instance()->playbackDevice();
auto add = [&](const QString& name, const QString& id) {
auto* action = menu->addAction(name);

1
tools/chatgui/src/settingsdialog.cpp

@ -148,6 +148,7 @@ SettingsDialog::SettingsDialog(const QString& configPath, DbManager* db, UtunNod
m_audioDevicePage = new AudioDeviceSettingsPage(db, recorder, m_pages);
m_audioDevicePage->setConfigPath(m_configPath);
m_audioDevicePage->loadFromDb();
m_pages->addWidget(m_audioDevicePage);
m_radioPage = new RadioSettingsPage(db, m_pages);

Loading…
Cancel
Save