Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Add ability to lock volume #2409

Merged
merged 1 commit into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UI/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Fullscreen="Fullscreen"
Windowed="Windowed"
Percent="Percent"
AspectRatio="Aspect Ratio <b>%1:%2</b>"
LockVolume="Lock Volume"

# warning if program already open
AlreadyRunning.Title="OBS is already running"
Expand Down
5 changes: 5 additions & 0 deletions UI/volume-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ VolControl::VolControl(OBSSource source_, bool showConfig, bool vertical)
VolumeChanged();
}

void VolControl::EnableSlider(bool enable)
{
slider->setEnabled(enable);
}

VolControl::~VolControl()
{
obs_fader_remove_callback(obs_fader, OBSVolumeChanged, this);
Expand Down
2 changes: 2 additions & 0 deletions UI/volume-control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,6 @@ private slots:

void SetMeterDecayRate(qreal q);
void setPeakMeterType(enum obs_peak_meter_type peakMeterType);

void EnableSlider(bool enable);
};
34 changes: 34 additions & 0 deletions UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2842,12 +2842,38 @@ void OBSBasic::MixerRenameSource()
}
}

static inline bool SourceVolumeLocked(obs_source_t *source)
{
obs_data_t *priv_settings = obs_source_get_private_settings(source);
bool lock = obs_data_get_bool(priv_settings, "volume_locked");
obs_data_release(priv_settings);

return lock;
}

void OBSBasic::LockVolumeControl(bool lock)
{
QAction *action = reinterpret_cast<QAction *>(sender());
VolControl *vol = action->property("volControl").value<VolControl *>();
obs_source_t *source = vol->GetSource();

obs_data_t *priv_settings = obs_source_get_private_settings(source);
obs_data_set_bool(priv_settings, "volume_locked", lock);
obs_data_release(priv_settings);

vol->EnableSlider(!lock);
}

void OBSBasic::VolControlContextMenu()
{
VolControl *vol = reinterpret_cast<VolControl *>(sender());

/* ------------------- */

QAction lockAction(QTStr("LockVolume"), this);
lockAction.setCheckable(true);
lockAction.setChecked(SourceVolumeLocked(vol->GetSource()));

QAction hideAction(QTStr("Hide"), this);
QAction unhideAllAction(QTStr("UnhideAll"), this);
QAction mixerRenameAction(QTStr("Rename"), this);
Expand All @@ -2870,6 +2896,8 @@ void OBSBasic::VolControlContextMenu()
&OBSBasic::HideAudioControl, Qt::DirectConnection);
connect(&unhideAllAction, &QAction::triggered, this,
&OBSBasic::UnhideAllAudioControls, Qt::DirectConnection);
connect(&lockAction, &QAction::toggled, this,
&OBSBasic::LockVolumeControl, Qt::DirectConnection);
connect(&mixerRenameAction, &QAction::triggered, this,
&OBSBasic::MixerRenameSource, Qt::DirectConnection);

Expand All @@ -2895,6 +2923,8 @@ void OBSBasic::VolControlContextMenu()

hideAction.setProperty("volControl",
QVariant::fromValue<VolControl *>(vol));
lockAction.setProperty("volControl",
QVariant::fromValue<VolControl *>(vol));
mixerRenameAction.setProperty("volControl",
QVariant::fromValue<VolControl *>(vol));

Expand All @@ -2916,6 +2946,8 @@ void OBSBasic::VolControlContextMenu()
pasteFiltersAction.setEnabled(true);

QMenu popup;
popup.addAction(&lockAction);
popup.addSeparator();
popup.addAction(&unhideAllAction);
popup.addAction(&hideAction);
popup.addAction(&mixerRenameAction);
Expand Down Expand Up @@ -3019,6 +3051,8 @@ void OBSBasic::ActivateAudioSource(OBSSource source)
"VerticalVolControl");
VolControl *vol = new VolControl(source, true, vertical);

vol->EnableSlider(!SourceVolumeLocked(source));

double meterDecayRate =
config_get_double(basicConfig, "Audio", "MeterDecayRate");
vol->SetMeterDecayRate(meterDecayRate);
Expand Down
2 changes: 2 additions & 0 deletions UI/window-basic-main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ private slots:
void TBarChanged(int value);
void TBarReleased();

void LockVolumeControl(bool lock);

private:
/* OBS Callbacks */
static void SceneReordered(void *data, calldata_t *params);
Expand Down