Jelajahi Sumber

UI: Add unassigned indicator and warning to mixer

derrod 2 tahun lalu
induk
melakukan
dc84a8da20

+ 2 - 0
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"

+ 4 - 0
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);
 }

+ 4 - 0
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);
 }

+ 14 - 0
UI/data/themes/Dark/unassigned.svg

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg width="100%" height="100%" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
+    <g>
+        <path d="M7,1.008C6.703,1.004 6.422,1.133 6.23,1.359L3,5L2,5C0.906,5 0,5.844 0,7L0,9C0,10.09 0.91,11 2,11L3,11L6.23,14.641C6.441,14.895 6.723,15.004 7,15L7,1.008Z" style="fill:rgb(230,179,28);fill-rule:nonzero;"/>
+    </g>
+    <g transform="matrix(1.30638,0,0,1.30638,-2.74526,7.10116)">
+        <g id="Layer1">
+            <g transform="matrix(12,0,0,12,9.58198,4.86608)">
+                <path d="M0.203,-0.237L0.084,-0.237L0.059,-0.714L0.228,-0.714L0.203,-0.237ZM0.057,-0.07C0.057,-0.097 0.064,-0.118 0.079,-0.132C0.094,-0.146 0.115,-0.153 0.143,-0.153C0.17,-0.153 0.191,-0.146 0.206,-0.131C0.221,-0.117 0.228,-0.097 0.228,-0.07C0.228,-0.044 0.221,-0.024 0.206,-0.009C0.191,0.006 0.17,0.013 0.143,0.013C0.116,0.013 0.095,0.006 0.08,-0.009C0.065,-0.023 0.057,-0.043 0.057,-0.07Z" style="fill:rgb(230,179,28);fill-rule:nonzero;"/>
+            </g>
+        </g>
+    </g>
+</svg>

+ 4 - 0
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);
 }

+ 4 - 0
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);
 }

+ 4 - 0
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);
 }

+ 4 - 0
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);
 }

+ 4 - 0
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);
 }

+ 17 - 0
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);
+	}
 };

+ 84 - 8
UI/volume-control.cpp

@@ -25,6 +25,43 @@ using namespace std;
 
 QWeakPointer<VolumeMeterTimer> 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::OBSMixersChanged(void *data, calldata_t *calldata)
+{
+	VolControl *volControl = static_cast<VolControl *>(data);
+	bool unassigned = calldata_int(calldata, "mixers") == 0;
+
+	QMetaObject::invokeMethod(volControl, "AssignmentChanged",
+				  Q_ARG(bool, unassigned));
 }
 
-void VolControl::SetMuted(bool checked)
+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);

+ 2 - 0
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);