From dc84a8da207c862f5815a8414b2ef0a7ccb03210 Mon Sep 17 00:00:00 2001 From: derrod Date: Fri, 24 Mar 2023 14:51:06 +0100 Subject: [PATCH] UI: Add unassigned indicator and warning to mixer --- UI/data/locale/en-US.ini | 2 + UI/data/themes/Acri.qss | 4 ++ UI/data/themes/Dark.qss | 4 ++ UI/data/themes/Dark/unassigned.svg | 14 +++++ UI/data/themes/Grey.qss | 4 ++ UI/data/themes/Light.qss | 4 ++ UI/data/themes/Rachni.qss | 4 ++ UI/data/themes/System.qss | 4 ++ UI/data/themes/Yami.qss | 4 ++ UI/mute-checkbox.hpp | 17 ++++++ UI/volume-control.cpp | 92 +++++++++++++++++++++++++++--- UI/volume-control.hpp | 2 + 12 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 UI/data/themes/Dark/unassigned.svg diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index f08a95b1d..806a073c7 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -559,6 +559,8 @@ VolControl.SliderUnmuted="Volume slider for '%1':" VolControl.SliderMuted="Volume slider for '%1': (currently muted)" VolControl.Mute="Mute '%1'" VolControl.Properties="Properties for '%1'" +VolControl.UnassignedWarning.Title="Unassigned Audio Source" +VolControl.UnassignedWarning.Text="\"%1\" is not assigned to any audio tracks and it will not be audible in streams or recordings.\n\nTo assign an audio source to a track, open the Advanced Audio Properties via the right-click menu or the cog button in the mixer dock toolbar." # add scene dialog Basic.Main.AddSceneDlg.Title="Add Scene" diff --git a/UI/data/themes/Acri.qss b/UI/data/themes/Acri.qss index ef1f2d221..a525bbebe 100644 --- a/UI/data/themes/Acri.qss +++ b/UI/data/themes/Acri.qss @@ -986,6 +986,10 @@ MuteCheckBox::indicator:checked { image: url(./Dark/mute.svg); } +MuteCheckBox::indicator:indeterminate { + image: url(./Dark/unassigned.svg); +} + MuteCheckBox::indicator:unchecked { image: url(./Dark/settings/audio.svg); } diff --git a/UI/data/themes/Dark.qss b/UI/data/themes/Dark.qss index e6794d469..2b56359d3 100644 --- a/UI/data/themes/Dark.qss +++ b/UI/data/themes/Dark.qss @@ -667,6 +667,10 @@ MuteCheckBox::indicator:checked { image: url(./Dark/mute.svg); } +MuteCheckBox::indicator:indeterminate { + image: url(./Dark/unassigned.svg); +} + MuteCheckBox::indicator:unchecked { image: url(./Dark/settings/audio.svg); } diff --git a/UI/data/themes/Dark/unassigned.svg b/UI/data/themes/Dark/unassigned.svg new file mode 100644 index 000000000..61c6d63ac --- /dev/null +++ b/UI/data/themes/Dark/unassigned.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/UI/data/themes/Grey.qss b/UI/data/themes/Grey.qss index 1f17a021c..6c4df993c 100644 --- a/UI/data/themes/Grey.qss +++ b/UI/data/themes/Grey.qss @@ -974,6 +974,10 @@ MuteCheckBox::indicator:checked { image: url(./Dark/mute.svg); } +MuteCheckBox::indicator:indeterminate { + image: url(./Dark/unassigned.svg); +} + MuteCheckBox::indicator:unchecked { image: url(./Dark/settings/audio.svg); } diff --git a/UI/data/themes/Light.qss b/UI/data/themes/Light.qss index d8a64f9d2..cb55f2c66 100644 --- a/UI/data/themes/Light.qss +++ b/UI/data/themes/Light.qss @@ -974,6 +974,10 @@ MuteCheckBox::indicator:checked { image: url(./Light/mute.svg); } +MuteCheckBox::indicator:indeterminate { + image: url(./Dark/unassigned.svg); +} + MuteCheckBox::indicator:unchecked { image: url(./Light/settings/audio.svg); } diff --git a/UI/data/themes/Rachni.qss b/UI/data/themes/Rachni.qss index 2f3669451..d376fb109 100644 --- a/UI/data/themes/Rachni.qss +++ b/UI/data/themes/Rachni.qss @@ -978,6 +978,10 @@ MuteCheckBox::indicator:checked { image: url(./Dark/mute.svg); } +MuteCheckBox::indicator:indeterminate { + image: url(./Dark/unassigned.svg); +} + MuteCheckBox::indicator:unchecked { image: url(./Dark/settings/audio.svg); } diff --git a/UI/data/themes/System.qss b/UI/data/themes/System.qss index 1871ec6e5..2a96cacd4 100644 --- a/UI/data/themes/System.qss +++ b/UI/data/themes/System.qss @@ -70,6 +70,10 @@ MuteCheckBox::indicator:checked { image: url(:/res/images/mute.svg); } +MuteCheckBox::indicator:indeterminate { + image: url(./Dark/unassigned.svg); +} + MuteCheckBox::indicator:unchecked { image: url(:/settings/images/settings/audio.svg); } diff --git a/UI/data/themes/Yami.qss b/UI/data/themes/Yami.qss index 269b532e9..21eefbd34 100644 --- a/UI/data/themes/Yami.qss +++ b/UI/data/themes/Yami.qss @@ -978,6 +978,10 @@ MuteCheckBox::indicator:checked { image: url(./Dark/mute.svg); } +MuteCheckBox::indicator:indeterminate { + image: url(./Dark/unassigned.svg); +} + MuteCheckBox::indicator:unchecked { image: url(./Dark/settings/audio.svg); } diff --git a/UI/mute-checkbox.hpp b/UI/mute-checkbox.hpp index 058361870..a0c3c63f5 100644 --- a/UI/mute-checkbox.hpp +++ b/UI/mute-checkbox.hpp @@ -4,4 +4,21 @@ class MuteCheckBox : public QCheckBox { Q_OBJECT + +public: + MuteCheckBox(QWidget *parent = nullptr) : QCheckBox(parent) + { + setTristate(true); + } + +protected: + /* While we need it to be tristate internally, we don't want a user being + * able to manually get into the partial state. */ + void nextCheckState() override + { + if (checkState() != Qt::Checked) + setCheckState(Qt::Checked); + else + setCheckState(Qt::Unchecked); + } }; diff --git a/UI/volume-control.cpp b/UI/volume-control.cpp index 51af38c06..37ce328d7 100644 --- a/UI/volume-control.cpp +++ b/UI/volume-control.cpp @@ -25,6 +25,43 @@ using namespace std; QWeakPointer VolumeMeter::updateTimer; +static inline Qt::CheckState GetCheckState(bool muted, bool unassigned) +{ + if (muted) + return Qt::Checked; + else if (unassigned) + return Qt::PartiallyChecked; + else + return Qt::Unchecked; +} + +static void ShowUnassignedWarning(const char *name) +{ + auto msgBox = [=]() { + QMessageBox msgbox(App()->GetMainWindow()); + msgbox.setWindowTitle( + QTStr("VolControl.UnassignedWarning.Title")); + msgbox.setText( + QTStr("VolControl.UnassignedWarning.Text").arg(name)); + msgbox.setIcon(QMessageBox::Icon::Information); + msgbox.addButton(QMessageBox::Ok); + + QCheckBox *cb = new QCheckBox(QTStr("DoNotShowAgain")); + msgbox.setCheckBox(cb); + + msgbox.exec(); + + if (cb->isChecked()) { + config_set_bool(App()->GlobalConfig(), "General", + "WarnedAboutUnassignedSources", true); + config_save_safe(App()->GlobalConfig(), "tmp", nullptr); + } + }; + + QMetaObject::invokeMethod(App(), "Exec", Qt::QueuedConnection, + Q_ARG(VoidFunc, msgBox)); +} + void VolControl::OBSVolumeChanged(void *data, float db) { Q_UNUSED(db); @@ -64,16 +101,50 @@ void VolControl::VolumeChanged() void VolControl::VolumeMuted(bool muted) { - if (mute->isChecked() != muted) - mute->setChecked(muted); + bool unassigned = obs_source_get_audio_mixers(source) == 0; - volMeter->muted = muted; + auto newState = GetCheckState(muted, unassigned); + if (mute->checkState() != newState) + mute->setCheckState(newState); + + volMeter->muted = muted || unassigned; } -void VolControl::SetMuted(bool checked) +void VolControl::OBSMixersChanged(void *data, calldata_t *calldata) { + VolControl *volControl = static_cast(data); + bool unassigned = calldata_int(calldata, "mixers") == 0; + + QMetaObject::invokeMethod(volControl, "AssignmentChanged", + Q_ARG(bool, unassigned)); +} + +void VolControl::AssignmentChanged(bool unassigned) +{ + bool muted = obs_source_muted(source); + auto newState = GetCheckState(muted, unassigned); + if (mute->checkState() != newState) + mute->setCheckState(newState); + + volMeter->muted = muted || unassigned; +} + +void VolControl::SetMuted(bool) +{ + bool checked = mute->checkState() == Qt::Checked; bool prev = obs_source_muted(source); obs_source_set_muted(source, checked); + bool unassigned = obs_source_get_audio_mixers(source) == 0; + + if (!checked && unassigned) { + mute->setCheckState(Qt::PartiallyChecked); + /* Show notice about the source no being assigned to any tracks */ + bool has_shown_warning = + config_get_bool(App()->GlobalConfig(), "General", + "WarnedAboutUnassignedSources"); + if (!has_shown_warning) + ShowUnassignedWarning(obs_source_get_name(source)); + } auto undo_redo = [](const std::string &name, bool val) { OBSSourceAutoRelease source = @@ -289,19 +360,22 @@ VolControl::VolControl(OBSSource source_, bool showConfig, bool vertical) slider->setMaximum(int(FADER_PRECISION)); bool muted = obs_source_muted(source); - mute->setChecked(muted); - volMeter->muted = muted; + bool unassigned = obs_source_get_audio_mixers(source) == 0; + mute->setCheckState(GetCheckState(muted, unassigned)); + volMeter->muted = muted || unassigned; mute->setAccessibleName(QTStr("VolControl.Mute").arg(sourceName)); obs_fader_add_callback(obs_fader, OBSVolumeChanged, this); obs_volmeter_add_callback(obs_volmeter, OBSVolumeLevel, this); signal_handler_connect(obs_source_get_signal_handler(source), "mute", OBSVolumeMuted, this); + signal_handler_connect(obs_source_get_signal_handler(source), + "audio_mixers", OBSMixersChanged, this); QWidget::connect(slider, SIGNAL(valueChanged(int)), this, SLOT(SliderChanged(int))); - QWidget::connect(mute, SIGNAL(clicked(bool)), this, - SLOT(SetMuted(bool))); + QWidget::connect(mute, &MuteCheckBox::clicked, this, + &VolControl::SetMuted); obs_fader_attach_source(obs_fader, source); obs_volmeter_attach_source(obs_volmeter, source); @@ -334,6 +408,8 @@ VolControl::~VolControl() signal_handler_disconnect(obs_source_get_signal_handler(source), "mute", OBSVolumeMuted, this); + signal_handler_disconnect(obs_source_get_signal_handler(source), + "audio_mixers", OBSMixersChanged, this); obs_fader_destroy(obs_fader); obs_volmeter_destroy(obs_volmeter); diff --git a/UI/volume-control.hpp b/UI/volume-control.hpp index 1792d97c2..cb31bcb12 100644 --- a/UI/volume-control.hpp +++ b/UI/volume-control.hpp @@ -301,12 +301,14 @@ private: const float peak[MAX_AUDIO_CHANNELS], const float inputPeak[MAX_AUDIO_CHANNELS]); static void OBSVolumeMuted(void *data, calldata_t *calldata); + static void OBSMixersChanged(void *data, calldata_t *alldata); void EmitConfigClicked(); private slots: void VolumeChanged(); void VolumeMuted(bool muted); + void AssignmentChanged(bool unassigned); void SetMuted(bool checked); void SliderChanged(int vol);