| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2015 Edouard Griffiths, F4EXB                                   //
 | 
					
						
							|  |  |  | // Copyright (C) 2020 Jon Beniston, M7RCE                                        //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							|  |  |  | // (at your option) any later version.                                           //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QMessageBox>
 | 
					
						
							|  |  |  | #include <QFileDialog>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ui_audioinputgui.h"
 | 
					
						
							|  |  |  | #include "gui/colormapper.h"
 | 
					
						
							|  |  |  | #include "gui/glspectrum.h"
 | 
					
						
							|  |  |  | #include "gui/basicdevicesettingsdialog.h"
 | 
					
						
							| 
									
										
										
										
											2022-12-20 10:31:15 +00:00
										 |  |  | #include "gui/dialpopup.h"
 | 
					
						
							|  |  |  | #include "gui/dialogpositioner.h"
 | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | #include "dsp/dspengine.h"
 | 
					
						
							|  |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							|  |  |  | #include "audioinputgui.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "device/deviceapi.h"
 | 
					
						
							|  |  |  | #include "device/deviceuiset.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AudioInputGui::AudioInputGui(DeviceUISet *deviceUISet, QWidget* parent) : | 
					
						
							|  |  |  |     DeviceGUI(parent), | 
					
						
							|  |  |  |     ui(new Ui::AudioInputGui), | 
					
						
							|  |  |  |     m_forceSettings(true), | 
					
						
							|  |  |  |     m_settings(), | 
					
						
							| 
									
										
										
										
											2020-11-13 19:55:09 +01:00
										 |  |  |     m_sampleSource(nullptr), | 
					
						
							|  |  |  |     m_centerFrequency(0) | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  |     m_deviceUISet = deviceUISet; | 
					
						
							| 
									
										
										
										
											2022-04-07 16:32:03 +02:00
										 |  |  |     setAttribute(Qt::WA_DeleteOnClose, true); | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |     m_sampleSource = (AudioInput*) m_deviceUISet->m_deviceAPI->getSampleSource(); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-07 16:32:03 +02:00
										 |  |  |     ui->setupUi(getContents()); | 
					
						
							| 
									
										
										
										
											2022-11-09 15:53:44 +00:00
										 |  |  |     sizeToContents(); | 
					
						
							| 
									
										
										
										
											2022-04-24 02:13:18 +02:00
										 |  |  |     getContents()->setStyleSheet("#AudioInputGui { background-color: rgb(64, 64, 64); }"); | 
					
						
							| 
									
										
										
										
											2022-04-07 16:32:03 +02:00
										 |  |  |     m_helpURL = "plugins/samplesource/audioinput/readme.md"; | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware())); | 
					
						
							| 
									
										
										
										
											2022-04-17 01:31:50 +02:00
										 |  |  |     connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &))); | 
					
						
							| 
									
										
										
										
											2023-01-15 10:24:58 +00:00
										 |  |  |     connect(deviceUISet->m_deviceAPI, &DeviceAPI::stateChanged, this, &AudioInputGui::updateStatus); | 
					
						
							|  |  |  |     updateStatus(); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     displaySettings(); | 
					
						
							| 
									
										
										
										
											2022-04-07 16:32:03 +02:00
										 |  |  |     makeUIConnections(); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); | 
					
						
							|  |  |  |     m_sampleSource->setMessageQueueToGUI(&m_inputMessageQueue); | 
					
						
							| 
									
										
										
										
											2022-12-20 10:31:15 +00:00
										 |  |  |     DialPopup::addPopupsToChildDials(this); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AudioInputGui::~AudioInputGui() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-10-05 15:40:09 +01:00
										 |  |  |     m_updateTimer.stop(); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     delete ui; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::destroy() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::resetToDefaults() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.resetToDefaults(); | 
					
						
							|  |  |  |     displaySettings(); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |     m_forceSettings = true; | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray AudioInputGui::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_settings.serialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AudioInputGui::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if(m_settings.deserialize(data)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         displaySettings(); | 
					
						
							|  |  |  |         m_forceSettings = true; | 
					
						
							|  |  |  |         sendSettings(); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         resetToDefaults(); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AudioInputGui::handleMessage(const Message& message) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-07-10 12:23:53 +02:00
										 |  |  |     if (DSPSignalNotification::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         const DSPSignalNotification& notif = (DSPSignalNotification&) message; | 
					
						
							|  |  |  |         m_sampleRate = notif.getSampleRate(); | 
					
						
							|  |  |  |         m_centerFrequency = notif.getCenterFrequency(); | 
					
						
							|  |  |  |         qDebug("AudioInputGui::handleInputMessages: DSPSignalNotification: SampleRate: %d", notif.getSampleRate()); | 
					
						
							|  |  |  |         updateSampleRateAndFrequency(); | 
					
						
							|  |  |  |         updateSpectrum(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (AudioInput::MsgConfigureAudioInput::match(message)) | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |         const AudioInput::MsgConfigureAudioInput& cfg = (AudioInput::MsgConfigureAudioInput&) message; | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (cfg.getForce()) { | 
					
						
							|  |  |  |             m_settings = cfg.getSettings(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |         blockApplySettings(true); | 
					
						
							|  |  |  |         displaySettings(); | 
					
						
							|  |  |  |         blockApplySettings(false); | 
					
						
							| 
									
										
										
										
											2023-07-10 12:23:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |     else if (AudioInput::MsgStartStop::match(message)) | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |         AudioInput::MsgStartStop& notif = (AudioInput::MsgStartStop&) message; | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |         blockApplySettings(true); | 
					
						
							|  |  |  |         ui->startStop->setChecked(notif.getStartStop()); | 
					
						
							|  |  |  |         blockApplySettings(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::handleInputMessages() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Message* message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while ((message = m_inputMessageQueue.pop()) != 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("AudioInputGui::handleInputMessages: message: %s", message->getIdentifier()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-10 12:23:53 +02:00
										 |  |  |         if (handleMessage(*message)) { | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |             delete message; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::updateSampleRateAndFrequency() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |     // Can't seem to get main spectrum to only display real part for mono/I-channel only
 | 
					
						
							|  |  |  |     if (m_settings.m_iqMapping <= AudioInputSettings::IQMapping::R) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_deviceUISet->getSpectrum()->setSampleRate(m_sampleRate / 2); | 
					
						
							|  |  |  |         m_deviceUISet->getSpectrum()->setCenterFrequency(m_sampleRate / 4); | 
					
						
							|  |  |  |         m_deviceUISet->getSpectrum()->setSsbSpectrum(true); | 
					
						
							|  |  |  |         m_deviceUISet->getSpectrum()->setLsbDisplay(false); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_deviceUISet->getSpectrum()->setSampleRate(m_sampleRate); | 
					
						
							| 
									
										
										
										
											2020-11-13 19:55:09 +01:00
										 |  |  |         m_deviceUISet->getSpectrum()->setCenterFrequency(m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |         m_deviceUISet->getSpectrum()->setSsbSpectrum(false); | 
					
						
							|  |  |  |         m_deviceUISet->getSpectrum()->setLsbDisplay(false); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ui->deviceRateText->setText(tr("%1k").arg((float)m_sampleRate / 1000)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::refreshDeviceList() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ui->device->blockSignals(true); | 
					
						
							|  |  |  |     AudioDeviceManager *audioDeviceManager = DSPEngine::instance()->getAudioDeviceManager(); | 
					
						
							| 
									
										
										
										
											2022-11-17 14:36:12 +00:00
										 |  |  |     const QList<AudioDeviceInfo>& audioList = audioDeviceManager->getInputDevices(); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ui->device->clear(); | 
					
						
							|  |  |  |     for (const auto &itAudio : audioList) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ui->device->addItem(AudioInputSettings::getFullDeviceName(itAudio)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ui->device->blockSignals(false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::refreshSampleRates(QString deviceName) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ui->sampleRate->blockSignals(true); | 
					
						
							|  |  |  |     ui->sampleRate->clear(); | 
					
						
							| 
									
										
										
										
											2022-11-17 14:36:12 +00:00
										 |  |  |     const auto deviceInfos = AudioDeviceInfo::availableInputDevices(); | 
					
						
							|  |  |  |     for (const AudioDeviceInfo &deviceInfo : deviceInfos) | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         if (deviceName == AudioInputSettings::getFullDeviceName(deviceInfo)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             QList<int> sampleRates = deviceInfo.supportedSampleRates(); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             for (int i = 0; i < sampleRates.size(); ++i) { | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |                 ui->sampleRate->addItem(QString("%1").arg(sampleRates[i])); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ui->sampleRate->blockSignals(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int index = ui->sampleRate->findText(QString("%1").arg(m_settings.m_sampleRate)); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (index >= 0) { | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |         ui->sampleRate->setCurrentIndex(index); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |         ui->sampleRate->setCurrentIndex(0); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::displaySettings() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     refreshDeviceList(); | 
					
						
							|  |  |  |     int index = ui->device->findText(m_settings.m_deviceName); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (index >= 0) { | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |         ui->device->setCurrentIndex(index); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |         ui->device->setCurrentIndex(0); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-01-15 10:24:58 +00:00
										 |  |  |     // Make sure on_device_currentIndexChanged is called. Index may be the same for a different device
 | 
					
						
							|  |  |  |     on_device_currentIndexChanged(ui->device->currentIndex()); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     ui->decim->setCurrentIndex(m_settings.m_log2Decim); | 
					
						
							|  |  |  |     ui->volume->setValue((int)(m_settings.m_volume*10.0f)); | 
					
						
							|  |  |  |     ui->volumeText->setText(QString("%1").arg(m_settings.m_volume, 3, 'f', 1)); | 
					
						
							|  |  |  |     ui->channels->setCurrentIndex((int)m_settings.m_iqMapping); | 
					
						
							| 
									
										
										
										
											2023-03-11 05:05:58 +01:00
										 |  |  | 	ui->dcOffset->setChecked(m_settings.m_dcBlock); | 
					
						
							|  |  |  | 	ui->iqImbalance->setChecked(m_settings.m_iqImbalance); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     refreshSampleRates(ui->device->currentText()); | 
					
						
							| 
									
										
										
										
											2023-03-11 09:56:18 +01:00
										 |  |  |     displayFcTooltip(); | 
					
						
							| 
									
										
										
										
											2023-07-10 12:23:53 +02:00
										 |  |  |     updateSpectrum(); | 
					
						
							| 
									
										
										
										
											2023-03-11 09:56:18 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::displayFcTooltip() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int32_t fShift = DeviceSampleSource::calculateFrequencyShift( | 
					
						
							|  |  |  |         m_settings.m_log2Decim, | 
					
						
							|  |  |  |         (DeviceSampleSource::fcPos_t) m_settings.m_fcPos, | 
					
						
							|  |  |  |         m_settings.m_sampleRate, | 
					
						
							|  |  |  |         DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     ui->fcPos->setToolTip(tr("Relative position of device center frequency: %1 kHz").arg(QString::number(fShift / 1000.0f, 'g', 5))); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-10 12:23:53 +02:00
										 |  |  | void AudioInputGui::updateSpectrum() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     bool realElseComplex = (m_settings.m_iqMapping == AudioInputSettings::L) | 
					
						
							|  |  |  |         || (m_settings.m_iqMapping == AudioInputSettings::R); | 
					
						
							|  |  |  |     m_deviceUISet->getSpectrum()->setCenterFrequency(0); | 
					
						
							|  |  |  |     m_deviceUISet->getSpectrum()->setSampleRate(m_sampleRate); | 
					
						
							|  |  |  |     m_deviceUISet->getSpectrum()->setSsbSpectrum(realElseComplex); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | void AudioInputGui::on_device_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-14 11:13:32 +01:00
										 |  |  |     (void) index; | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     m_settings.m_deviceName = ui->device->currentText(); | 
					
						
							|  |  |  |     refreshSampleRates(m_settings.m_deviceName); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |     m_settingsKeys.append("deviceName"); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::on_sampleRate_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-14 11:13:32 +01:00
										 |  |  |     (void) index; | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     m_settings.m_sampleRate = ui->sampleRate->currentText().toInt(); | 
					
						
							| 
									
										
										
										
											2023-03-11 09:56:18 +01:00
										 |  |  |     displayFcTooltip(); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |     m_settingsKeys.append("sampleRate"); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::on_decim_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((index < 0) || (index > 6)) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_settings.m_log2Decim = index; | 
					
						
							| 
									
										
										
										
											2023-03-11 09:56:18 +01:00
										 |  |  |     displayFcTooltip(); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |     m_settingsKeys.append("log2Decim"); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::on_volume_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_volume = value/10.0f; | 
					
						
							|  |  |  |     ui->volumeText->setText(QString("%1").arg(m_settings.m_volume, 3, 'f', 1)); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |     m_settingsKeys.append("volume"); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::on_channels_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_iqMapping = (AudioInputSettings::IQMapping)index; | 
					
						
							|  |  |  |     updateSampleRateAndFrequency(); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |     m_settingsKeys.append("iqMapping"); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |     sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-11 05:05:58 +01:00
										 |  |  | void AudioInputGui::on_dcOffset_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_settings.m_dcBlock = checked; | 
					
						
							|  |  |  |     m_settingsKeys.append("dcBlock"); | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::on_iqImbalance_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_settings.m_iqImbalance = checked; | 
					
						
							|  |  |  |     m_settingsKeys.append("iqImbalance"); | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-11 09:56:18 +01:00
										 |  |  | void AudioInputGui::on_fcPos_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_fcPos = (AudioInputSettings::fcPos_t) (index < 0 ? 0 : index > 2 ? 2 : index); | 
					
						
							|  |  |  |     displayFcTooltip(); | 
					
						
							|  |  |  |     m_settingsKeys.append("fcPos"); | 
					
						
							|  |  |  |     sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | void AudioInputGui::on_startStop_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_doApplySettings) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |         AudioInput::MsgStartStop *message = AudioInput::MsgStartStop::create(checked); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |         m_sampleSource->getInputMessageQueue()->push(message); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::sendSettings() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if(!m_updateTimer.isActive()) | 
					
						
							|  |  |  |         m_updateTimer.start(100); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::updateHardware() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_doApplySettings) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |         AudioInput::MsgConfigureAudioInput* message = AudioInput::MsgConfigureAudioInput::create(m_settings, m_settingsKeys, m_forceSettings); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |         m_sampleSource->getInputMessageQueue()->push(message); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |         m_settingsKeys.clear(); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  |         m_forceSettings = false; | 
					
						
							|  |  |  |         m_updateTimer.stop(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-15 10:24:58 +00:00
										 |  |  | void AudioInputGui::updateStatus() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int state = m_deviceUISet->m_deviceAPI->state(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (state) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         case DeviceAPI::StNotStarted: | 
					
						
							|  |  |  |             ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case DeviceAPI::StIdle: | 
					
						
							|  |  |  |             ui->startStop->setStyleSheet("QToolButton { background-color : blue; }"); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case DeviceAPI::StRunning: | 
					
						
							|  |  |  |             ui->startStop->setStyleSheet("QToolButton { background-color : green; }"); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case DeviceAPI::StError: | 
					
						
							|  |  |  |             ui->startStop->setStyleSheet("QToolButton { background-color : red; }"); | 
					
						
							|  |  |  |             QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage()); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | void AudioInputGui::openDeviceSettingsDialog(const QPoint& p) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-04-17 01:31:50 +02:00
										 |  |  |     if (m_contextMenuType == ContextMenuDeviceSettings) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         BasicDeviceSettingsDialog dialog(this); | 
					
						
							|  |  |  |         dialog.setUseReverseAPI(m_settings.m_useReverseAPI); | 
					
						
							|  |  |  |         dialog.setReverseAPIAddress(m_settings.m_reverseAPIAddress); | 
					
						
							|  |  |  |         dialog.setReverseAPIPort(m_settings.m_reverseAPIPort); | 
					
						
							|  |  |  |         dialog.setReverseAPIDeviceIndex(m_settings.m_reverseAPIDeviceIndex); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-17 01:31:50 +02:00
										 |  |  |         dialog.move(p); | 
					
						
							| 
									
										
										
										
											2022-12-20 10:31:15 +00:00
										 |  |  |         new DialogPositioner(&dialog, false); | 
					
						
							| 
									
										
										
										
											2022-04-17 01:31:50 +02:00
										 |  |  |         dialog.exec(); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-17 01:31:50 +02:00
										 |  |  |         m_settings.m_useReverseAPI = dialog.useReverseAPI(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIPort = dialog.getReverseAPIPort(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex(); | 
					
						
							| 
									
										
										
										
											2022-10-22 12:28:24 +02:00
										 |  |  |         m_settingsKeys.append("useReverseAPI"); | 
					
						
							|  |  |  |         m_settingsKeys.append("reverseAPIAddress"); | 
					
						
							|  |  |  |         m_settingsKeys.append("reverseAPIPort"); | 
					
						
							|  |  |  |         m_settingsKeys.append("reverseAPIDeviceIndex"); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-17 01:31:50 +02:00
										 |  |  |         sendSettings(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resetContextMenuType(); | 
					
						
							| 
									
										
										
										
											2020-11-09 21:12:08 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-04-07 16:32:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void AudioInputGui::makeUIConnections() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QObject::connect(ui->device, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AudioInputGui::on_device_currentIndexChanged); | 
					
						
							|  |  |  |     QObject::connect(ui->sampleRate, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AudioInputGui::on_sampleRate_currentIndexChanged); | 
					
						
							|  |  |  |     QObject::connect(ui->decim, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AudioInputGui::on_decim_currentIndexChanged); | 
					
						
							|  |  |  |     QObject::connect(ui->volume, &QDial::valueChanged, this, &AudioInputGui::on_volume_valueChanged); | 
					
						
							|  |  |  |     QObject::connect(ui->channels, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AudioInputGui::on_channels_currentIndexChanged); | 
					
						
							| 
									
										
										
										
											2023-03-11 05:05:58 +01:00
										 |  |  |     QObject::connect(ui->dcOffset, &ButtonSwitch::toggled, this, &AudioInputGui::on_dcOffset_toggled); | 
					
						
							|  |  |  |     QObject::connect(ui->iqImbalance, &ButtonSwitch::toggled, this, &AudioInputGui::on_iqImbalance_toggled); | 
					
						
							| 
									
										
										
										
											2023-03-11 09:56:18 +01:00
										 |  |  |     QObject::connect(ui->fcPos, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AudioInputGui::on_fcPos_currentIndexChanged); | 
					
						
							| 
									
										
										
										
											2022-04-07 16:32:03 +02:00
										 |  |  |     QObject::connect(ui->startStop, &ButtonSwitch::toggled, this, &AudioInputGui::on_startStop_toggled); | 
					
						
							|  |  |  | } |