11 #include <QStringLiteral>
12 #include <QToolButton>
15 #include "ui_audiodevicevolumesetupcomponent.h"
29 using namespace swift::core::afv::audio;
30 using namespace swift::core::afv::clients;
31 using namespace swift::core::context;
33 using namespace swift::misc::aviation;
34 using namespace swift::misc::audio;
35 using namespace swift::misc::physical_quantities;
36 using namespace swift::misc::simulation;
40 CAudioDeviceVolumeSetupComponent::CAudioDeviceVolumeSetupComponent(
QWidget *parent)
45 &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged);
47 &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged);
49 &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged);
51 &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged);
76 ui->hs_VolumeIn->setMaximum(CSettings::InMax);
77 ui->hs_VolumeIn->setMinimum(CSettings::InMin);
78 ui->hs_VolumeOut->setMaximum(CSettings::OutMax);
79 ui->hs_VolumeOut->setMinimum(CSettings::OutMin);
80 ui->hs_VolumeOutCom1->setMaximum(CSettings::OutMax);
81 ui->hs_VolumeOutCom1->setMinimum(CSettings::OutMin);
82 ui->hs_VolumeOutCom2->setMaximum(CSettings::OutMax);
83 ui->hs_VolumeOutCom2->setMinimum(CSettings::OutMin);
90 ui->hs_VolumeIn->setValue(i);
91 ui->hs_VolumeOut->setValue(o);
92 ui->hs_VolumeOutCom1->setValue(o1);
93 ui->hs_VolumeOutCom2->setValue(o2);
94 ui->cb_SetupAudioLoopback->setChecked(
false);
97 ui->led_AudioConnected->setToolTips(
"Voice on and authenticated",
"Voice off");
98 ui->led_AudioConnected->setShape(CLedWidget::Rounded);
99 ui->led_Rx1->setToolTips(
"COM1 receiving",
"COM1 idle");
100 ui->led_Rx1->setShape(CLedWidget::Rounded);
101 ui->led_Rx2->setToolTips(
"COM2 receiving",
"COM2 idle");
102 ui->led_Rx2->setShape(CLedWidget::Rounded);
113 this->setCheckBoxesReadOnly(this->isComIntegrated());
114 this->setVolumeSlidersReadOnly(this->isComIntegrated());
117 void CAudioDeviceVolumeSetupComponent::init()
122 const bool audio = this->hasAudio();
124 this->reloadSettings();
127 &CAudioDeviceVolumeSetupComponent::onLoopbackToggled);
130 &CAudioDeviceVolumeSetupComponent::onDisableAudioEffectsToggled);
136 &CAudioDeviceVolumeSetupComponent::simulatorSettingsChanged);
142 this->initAudioDeviceLists();
166 this->initWithAfvClient();
172 void CAudioDeviceVolumeSetupComponent::initWithAfvClient()
174 if (!afvClient()) {
return; }
181 c =
connect(afv, &CAfvClient::outputVolumePeakVU,
this, &CAudioDeviceVolumeSetupComponent::onOutputVU, ct);
183 m_afvConnections.
append(c);
184 c =
connect(afv, &CAfvClient::inputVolumePeakVU,
this, &CAudioDeviceVolumeSetupComponent::onInputVU, ct);
186 m_afvConnections.
append(c);
187 c =
connect(afv, &CAfvClient::receivedCallsignsChanged,
this,
188 &CAudioDeviceVolumeSetupComponent::onReceivingCallsignsChanged, ct);
190 m_afvConnections.
append(c);
191 c =
connect(afv, &CAfvClient::updatedFromOwnAircraftCockpit,
this,
192 &CAudioDeviceVolumeSetupComponent::onUpdatedClientWithCockpitData, ct);
194 m_afvConnections.
append(c);
197 afv->
setRxTx(
true,
true,
true,
false);
201 afv, &CAfvClient::connectionStatusChanged,
this,
204 myself->setTransmitReceiveInUiFromVoiceClient();
209 m_afvConnections.
append(c);
211 this->setTransmitReceiveInUiFromVoiceClient();
218 const double r = ui->hs_VolumeIn->maximum() - ui->hs_VolumeIn->minimum();
219 const double tr = to - from;
220 return qRound(ui->hs_VolumeIn->value() / r *
tr);
225 const double r = ui->hs_VolumeOut->maximum() - ui->hs_VolumeOut->minimum();
226 const double tr = to - from;
227 return qRound(ui->hs_VolumeOut->value() / r *
tr);
232 const double r = ui->hs_VolumeOutCom1->maximum() - ui->hs_VolumeOutCom1->minimum();
233 const double tr = to - from;
234 return qRound(ui->hs_VolumeOutCom1->value() / r *
tr);
239 const double r = ui->hs_VolumeOutCom2->maximum() - ui->hs_VolumeOutCom2->minimum();
240 const double tr = to - from;
241 return qRound(ui->hs_VolumeOutCom2->value() / r *
tr);
246 if (value > to) { value = to; }
247 else if (value < from) { value = from; }
248 const double r = ui->hs_VolumeIn->maximum() - ui->hs_VolumeIn->minimum();
249 const double tr = to - from;
250 ui->hs_VolumeIn->setValue(qRound(value /
tr * r));
255 if (value > to) { value = to; }
256 else if (value < from) { value = from; }
257 const double r = ui->hs_VolumeOut->maximum() - ui->hs_VolumeOut->minimum();
258 const double tr = to - from;
259 ui->hs_VolumeOut->setValue(qRound(value /
tr * r));
264 if (value > to) { value = to; }
265 else if (value < from) { value = from; }
266 const double r = ui->hs_VolumeOutCom1->maximum() - ui->hs_VolumeOutCom1->minimum();
267 const double tr = to - from;
268 ui->hs_VolumeOutCom1->setValue(qRound(value /
tr * r));
273 if (value > to) { value = to; }
274 else if (value < from) { value = from; }
275 const double r = ui->hs_VolumeOutCom2->maximum() - ui->hs_VolumeOutCom2->minimum();
276 const double tr = to - from;
277 ui->hs_VolumeOutCom2->setValue(qRound(value /
tr * r));
282 if (value > 1.0) { value = 1.0; }
283 else if (value < 0.0) { value = 0.0; }
284 ui->wip_InLevelMeter->levelChanged(value);
289 if (value > 1.0) { value = 1.0; }
290 else if (value < 0.0) { value = 0.0; }
291 ui->wip_OutLevelMeter->levelChanged(value);
294 void CAudioDeviceVolumeSetupComponent::setTransmitReceiveInUi(
bool tx1,
bool rec1,
bool tx2,
bool rec2,
297 this->setRxTxCheckboxes(rec1, tx1, rec2, tx2);
298 this->setCheckBoxesReadOnly(integrated);
299 this->setVolumeSlidersReadOnly(integrated);
302 void CAudioDeviceVolumeSetupComponent::setTransmitReceiveInUiFromVoiceClient()
304 if (!this->hasAudio())
306 ui->led_AudioConnected->setOn(
false);
311 ui->led_AudioConnected->setOn(on);
320 const bool com1Rx = com1Enabled;
321 const bool com2Rx = com2Enabled;
323 const bool integrated = this->isComIntegrated();
324 this->setTransmitReceiveInUi(com1Tx, com1Rx, com2Tx, com2Rx, integrated);
331 ui->hs_VolumeOutCom1->setValue(vol1);
332 ui->hs_VolumeOutCom2->setValue(vol2);
336 void CAudioDeviceVolumeSetupComponent::setCheckBoxesReadOnly(
bool readonly)
345 void CAudioDeviceVolumeSetupComponent::setVolumeSlidersReadOnly(
bool readonly)
347 ui->hs_VolumeOutCom1->setDisabled(readonly);
348 ui->hs_VolumeOutCom2->setDisabled(readonly);
352 ui->hs_VolumeOutCom1->setStyleSheet(
"background: rgb(40,40,40)");
353 ui->hs_VolumeOutCom2->setStyleSheet(
"background: rgb(40,40,40)");
357 ui->hs_VolumeOutCom1->setStyleSheet(
"");
358 ui->hs_VolumeOutCom2->setStyleSheet(
"");
362 CAfvClient *CAudioDeviceVolumeSetupComponent::afvClient()
368 void CAudioDeviceVolumeSetupComponent::reloadSettings()
371 ui->cb_DisableAudioEffects->setChecked(!as.isAudioEffectsEnabled());
378 void CAudioDeviceVolumeSetupComponent::initAudioDeviceLists()
380 if (!this->hasAudio()) {
return; }
382 if (!changed) {
return; }
392 void CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged(
int v)
398 void CAudioDeviceVolumeSetupComponent::saveVolumes()
405 if (as.getInVolume() == i && o == as.getOutVolume() && as.getOutVolumeCom1() == o1 &&
406 as.getOutVolumeCom2() == o2)
412 as.setOutVolumeCom1(o1);
413 as.setOutVolumeCom2(o2);
417 void CAudioDeviceVolumeSetupComponent::onOutputVU(
double vu) { this->
setOutLevel(vu); }
419 void CAudioDeviceVolumeSetupComponent::onInputVU(
double vu) { this->
setInLevel(vu); }
421 void CAudioDeviceVolumeSetupComponent::onReloadDevices()
423 if (!hasAudio()) {
return; }
424 this->initAudioDeviceLists();
430 void CAudioDeviceVolumeSetupComponent::onResetVolumeIn()
432 ui->hs_VolumeIn->setValue((ui->hs_VolumeIn->maximum() - ui->hs_VolumeIn->minimum()) / 2);
435 void CAudioDeviceVolumeSetupComponent::onResetVolumeOut()
437 ui->hs_VolumeOut->setValue((ui->hs_VolumeOut->maximum() - ui->hs_VolumeOut->minimum()) / 2);
440 void CAudioDeviceVolumeSetupComponent::onResetVolumeOutCom1()
442 ui->hs_VolumeOutCom1->setValue(ui->hs_VolumeOutCom1->maximum());
445 void CAudioDeviceVolumeSetupComponent::onResetVolumeOutCom2()
447 ui->hs_VolumeOutCom2->setValue(ui->hs_VolumeOutCom2->maximum());
450 void CAudioDeviceVolumeSetupComponent::showAudioRunsWhereDialog()
452 if (!this->hasAudio()) {
return; }
457 void CAudioDeviceVolumeSetupComponent::simulatorSettingsChanged()
459 const bool integrated = this->isComIntegrated();
460 setCheckBoxesReadOnly(integrated);
461 setVolumeSlidersReadOnly(integrated);
464 bool CAudioDeviceVolumeSetupComponent::isComIntegrated()
const
466 if (!this->hasSimulator()) {
return false; }
472 void CAudioDeviceVolumeSetupComponent::onRxTxChanged(
bool checked)
474 if (!this->hasAudio()) {
return; }
475 if (this->isComIntegrated()) {
return; }
478 const bool rx1 = ui->cb_1Rec->isChecked();
479 const bool rx2 = ui->cb_2Rec->isChecked();
482 const bool tx1 = rx1 && ui->cb_1Tx->isChecked();
483 const bool tx2 = rx2 && ui->cb_2Tx->isChecked();
490 if (!myself) {
return; }
491 this->setRxTxCheckboxes(rx1, tx1, rx2, tx2);
495 void CAudioDeviceVolumeSetupComponent::setRxTxCheckboxes(
bool rx1,
bool tx1,
bool rx2,
bool tx2)
497 if (ui->cb_1Tx->isChecked() != tx1) { ui->cb_1Tx->setChecked(tx1); }
498 if (ui->cb_2Tx->isChecked() != tx2) { ui->cb_2Tx->setChecked(tx2); }
499 if (ui->cb_1Rec->isChecked() != rx1) { ui->cb_1Rec->setChecked(rx1); }
500 if (ui->cb_2Rec->isChecked() != rx2) { ui->cb_2Rec->setChecked(rx2); }
503 void CAudioDeviceVolumeSetupComponent::onReceivingCallsignsChanged(
const CCallsignSet &com1Callsigns,
506 if (!com1Callsigns.
empty())
512 if (!ui->le_Com1->text().isEmpty())
514 ui->le_Com1->setPlaceholderText(ui->le_Com1->text());
515 ui->le_Com1->clear();
519 if (!com2Callsigns.
empty())
525 if (!ui->le_Com2->text().isEmpty())
527 ui->le_Com2->setPlaceholderText(ui->le_Com2->text());
528 ui->le_Com2->clear();
533 void CAudioDeviceVolumeSetupComponent::onUpdatedClientWithCockpitData()
535 this->setTransmitReceiveInUiFromVoiceClient();
538 CAudioDeviceInfo CAudioDeviceVolumeSetupComponent::getSelectedInputDevice()
const
540 if (!hasAudio()) {
return {}; }
542 return devices.
findByName(ui->cb_SetupAudioInputDevice->currentText());
545 CAudioDeviceInfo CAudioDeviceVolumeSetupComponent::getSelectedOutputDevice()
const
547 if (!hasAudio()) {
return {}; }
549 return devices.
findByName(ui->cb_SetupAudioOutputDevice->currentText());
552 void CAudioDeviceVolumeSetupComponent::onAudioDeviceSelected(
int index)
555 if (index < 0) {
return; }
564 if (!afvClient()) {
return; }
565 if (m_afvConnections.
isEmpty() && m_init) { this->initWithAfvClient(); }
567 ui->cb_SetupAudioInputDevice->setCurrentText(input.
toQString(
true));
568 ui->cb_SetupAudioOutputDevice->setCurrentText(output.
toQString(
true));
571 void CAudioDeviceVolumeSetupComponent::onAudioStopped()
576 bool CAudioDeviceVolumeSetupComponent::onAudioDevicesChanged(
const CAudioDeviceInfoList &devices)
579 m_cbDevices = devices;
581 ui->cb_SetupAudioOutputDevice->clear();
582 ui->cb_SetupAudioInputDevice->clear();
584 const QString i = ui->cb_SetupAudioInputDevice->currentText();
585 const QString o = ui->cb_SetupAudioOutputDevice->currentText();
589 if (device.getType() == CAudioDeviceInfo::InputDevice)
591 ui->cb_SetupAudioInputDevice->addItem(device.toQString(
true));
593 else if (device.getType() == CAudioDeviceInfo::OutputDevice)
595 ui->cb_SetupAudioOutputDevice->addItem(device.toQString(
true));
599 if (!i.
isEmpty()) { ui->cb_SetupAudioInputDevice->setCurrentText(i); }
600 if (!o.
isEmpty()) { ui->cb_SetupAudioOutputDevice->setCurrentText(o); }
605 void CAudioDeviceVolumeSetupComponent::onLoopbackToggled(
bool loopback)
612 void CAudioDeviceVolumeSetupComponent::onDisableAudioEffectsToggled(
bool disabled)
616 const bool enabled = !disabled;
617 if (as.isAudioEffectsEnabled() ==
enabled) {
return; }
618 as.setAudioEffectsEnabled(
enabled);
const context::IContextAudio * getIContextAudio() const
Direct access to contexts if a CCoreFacade has been initialized.
bool isShuttingDown() const
Is application shutting down?
const context::IContextSimulator * getIContextSimulator() const
Direct access to contexts if a CCoreFacade has been initialized.
const context::CContextAudioBase * getCContextAudioBase() const
Direct access to contexts if a CCoreFacade has been initialized.
ConnectionStatus
Connection status.
void setRxTx(bool rx1, bool tx1, bool rx2, bool tx2)
Simplified enable/disable.
bool isAudioLoopbackEnabled() const
Loopback.
bool isAudioConnected() const
Is audio connected?
void enableAudioLoopback(bool enable=true)
Loopback.
swift::misc::audio::CAudioDeviceInfoList getAudioOutputDevices() const
Audio devices.
bool isTransmittingComUnit(swift::misc::aviation::CComSystem::ComUnit comUnit) const
Is COM unit transmitting?
swift::misc::audio::CAudioDeviceInfoList getAudioDevices() const
Audio devices.
void setCurrentAudioDevices(const swift::misc::audio::CAudioDeviceInfo &inputDevice, const swift::misc::audio::CAudioDeviceInfo &outputDevice)
Set current audio devices.
QString audioRunsWhereInfo() const
Info string about audio.
swift::misc::audio::CAudioDeviceInfoList getCurrentAudioDevices() const
Get current audio device.
int getComOutputVolume(swift::misc::aviation::CComSystem::ComUnit comUnit) const
Volume.
bool isEnabledComUnit(swift::misc::aviation::CComSystem::ComUnit comUnit) const
Is COM unit enabled?
void setRxTx(bool rx1, bool tx1, bool rx2, bool tx2)
Receive/transmit.
afv::clients::CAfvClient * afvClient() const
swift::misc::audio::CAudioDeviceInfoList getAudioInputDevices() const
Audio devices.
virtual swift::misc::simulation::settings::CSimulatorSettings getSimulatorSettings() const =0
Get the current simulator settings.
static void checkBoxReadOnly(QCheckBox *checkBox, bool readOnly)
Pseudo readonly state for checkbox.
Audio setup such as input / output devices.
void setOutValueCom1(int value, int from=swift::misc::audio::CSettings::OutMin, int to=swift::misc::audio::CSettings::OutMax)
Set input and output volume values.
int getInValue(int from=swift::misc::audio::CSettings::InMin, int to=swift::misc::audio::CSettings::InMax) const
Get input and output volume values.
~CAudioDeviceVolumeSetupComponent()
Destructor.
int getOutValueCom2(int from=swift::misc::audio::CSettings::OutMin, int to=swift::misc::audio::CSettings::OutMax) const
Get input and output volume values.
int getOutValue(int from=swift::misc::audio::CSettings::OutMin, int to=swift::misc::audio::CSettings::OutMax) const
Get input and output volume values.
int getOutValueCom1(int from=swift::misc::audio::CSettings::OutMin, int to=swift::misc::audio::CSettings::OutMax) const
Get input and output volume values.
void setOutValueCom2(int value, int from=swift::misc::audio::CSettings::OutMin, int to=swift::misc::audio::CSettings::OutMax)
Set input and output volume values.
void setInValue(int value, int from=swift::misc::audio::CSettings::InMin, int to=swift::misc::audio::CSettings::InMax)
Set input and output volume values.
void setInLevel(double value)
Set input and output level values 0..1.
void setOutLevel(double value)
Set input and output level values 0..1.
void setOutValue(int value, int from=swift::misc::audio::CSettings::InMin, int to=swift::misc::audio::CSettings::InMax)
Set input and output volume values.
CStatusMessage setAndSave(const T &value, qint64 timestamp=0)
Write and save in the same step. Must be called from the thread in which the owner lives.
const T & getThreadLocal() const
Read the current value.
bool empty() const
Returns true if the collection is empty.
bool append(const QMetaObject::Connection &connection)
Add connection.
int disconnectAll()
Disconnect all.
bool isEmpty() const
Empty.
void inputSignal()
Received input signal, or manually trigger.
const_reference frontOrDefault() const
Access the first element, or a default-initialized value if the sequence is empty.
Value object encapsulating information of a audio device.
Value object encapsulating a list of audio devices.
CAudioDeviceInfoList getOutputDevices() const
Get output devices in that list.
CAudioDeviceInfoList getInputDevices() const
Get output devices in that list.
bool hasSameDevices(const CAudioDeviceInfoList &compareDevices) const
Has same devices.
CAudioDeviceInfo findByName(const QString &name, bool strict=false) const
Find by name.
Value object encapsulating information of audio related settings.
bool isAudioEffectsEnabled() const
Audio effects enabled?
Value object for a set of callsigns.
QString getCallsignsAsString(bool sorted=false, const QString &separator=", ") const
Callsigns as string.
QString toQString(bool i18n=false) const
Cast as QString.
Settings for simulator Driver independent parts (such as directories), also used in model loaders.
bool isComIntegrated() const
COM unit integration.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Free functions in swift::misc.
void valueChanged(int value)
void currentIndexChanged(int index)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isEmpty() const const