Skip to content

Commit

Permalink
Refresh channel range when switching devices
Browse files Browse the repository at this point in the history
  • Loading branch information
sakertooth committed Mar 1, 2025
1 parent ebd1c7c commit b8914c5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/core/audio/AudioPortAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ class AudioPortAudioSetupWidget::DeviceSpecWidget : public QGroupBox
m_channelSpinBox->setModel(&m_channelModel);
layout->addRow(tr(rowHeader), m_deviceComboBox);
layout->addRow(tr("Channels"), m_channelSpinBox);

connect(m_deviceComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this, [&]{
refreshChannelRange();
});
}

void refreshFromConfig(PaHostApiIndex backendIndex)
Expand All @@ -291,18 +295,22 @@ class AudioPortAudioSetupWidget::DeviceSpecWidget : public QGroupBox
const auto selectedDeviceName = ConfigManager::inst()->value(tag(), deviceNameAttribute(m_direction));
const auto selectedDeviceIndex = std::max(0, m_deviceComboBox->findText(selectedDeviceName));
m_deviceComboBox->setCurrentIndex(selectedDeviceIndex);

refreshChannelRange();

const auto defaultNumChannels = QString::number(DEFAULT_CHANNELS);
const auto selectedNumChannels
= ConfigManager::inst()->value(tag(), channelsAttribute(m_direction), defaultNumChannels);
= ConfigManager::inst()->value(tag(), channelsAttribute(m_direction), defaultNumChannels);
m_channelModel.setValue(selectedNumChannels.toInt());
}

const auto deviceIndex = m_deviceComboBox->currentData().toInt();
void refreshChannelRange()
{
const auto deviceIndex = m_deviceComboBox->currentData().toInt();
const auto deviceSpec = DeviceSpec::loadFromIndex(deviceIndex, m_direction);

m_channelModel.setRange(1, deviceSpec.maxChannels());
m_channelSpinBox->setNumDigits(QString::number(deviceSpec.maxChannels()).length());
}
}

void saveToConfig()
{
Expand Down

0 comments on commit b8914c5

Please sign in to comment.