Skip to content

Commit

Permalink
Merge pull request #113 from RivinHD/master
Browse files Browse the repository at this point in the history
split volume slider into remote and local
  • Loading branch information
MGraefe authored Apr 3, 2023
2 parents a7653d6 + d3b9c3f commit 3e6d0ce
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ release/plugins/
build/
build32/
build64/
.vscode/

# we don't commit pre-compiled linux libraries since it's way easier to compile
# ffmpeg on linux compared to windows
Expand Down
27 changes: 20 additions & 7 deletions src/ConfigModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ ConfigModel::ConfigModel()
{
m_rows.fill(2);
m_cols.fill(5);
m_volume = 80;
m_volumeLocal = 80;
m_volumeRemote = 80;
m_playbackLocal = true;
m_muteMyselfDuringPb = false;
m_windowWidth = 600;
Expand Down Expand Up @@ -64,7 +65,9 @@ void ConfigModel::readConfig(const QString &file)
m_rows[i] = settings.value(i == 0 ? QString("num_rows") : QString("num_rows%1").arg(i + 1), i == 0 ? 2 : m_rows[0]).toInt();
m_cols[i] = settings.value(i == 0 ? QString("num_cols") : QString("num_cols%1").arg(i + 1), i == 0 ? 5 : m_cols[0]).toInt();
}
m_volume = settings.value("volume", 50).toInt();
int volume_old = settings.value("volume", 50).toInt();
m_volumeLocal = settings.value("volumeLocal", volume_old).toInt();
m_volumeLocal = settings.value("volumeRemote", volume_old).toInt();
m_playbackLocal = settings.value("playback_local", true).toBool();
m_muteMyselfDuringPb = settings.value("mute_myself_during_pb", false).toBool();
m_windowWidth = settings.value("window_width", 600).toInt();
Expand Down Expand Up @@ -93,7 +96,8 @@ void ConfigModel::writeConfig(const QString &file)
QSettings settings(path, QSettings::IniFormat);

settings.setValue("config_build", buildinfo_getBuildNumber());
settings.setValue("volume", m_volume);
settings.setValue("volumeLocal", m_volumeLocal);
settings.setValue("volumeRemote", m_volumeRemote);
settings.setValue("playback_local", m_playbackLocal);
settings.setValue("mute_myself_during_pb", m_muteMyselfDuringPb);
settings.setValue("window_width", m_windowWidth);
Expand Down Expand Up @@ -282,12 +286,20 @@ void ConfigModel::setCols( int n )
//---------------------------------------------------------------
// Purpose:
//---------------------------------------------------------------
void ConfigModel::setVolume( int val )
void ConfigModel::setVolumeLocal( int val )
{
m_volume = val;
notify(NOTIFY_SET_VOLUME, val);
m_volumeLocal = val;
notify(NOTIFY_SET_VOLUME_LOCAL, val);
}

//---------------------------------------------------------------
// Purpose:
//---------------------------------------------------------------
void ConfigModel::setVolumeRemote( int val )
{
m_volumeRemote = val;
notify(NOTIFY_SET_VOLUME_REMOTE, val);
}

//---------------------------------------------------------------
// Purpose:
Expand Down Expand Up @@ -459,7 +471,8 @@ void ConfigModel::notifyAllEvents()
notify(NOTIFY_SET_SOUND, i);
notify(NOTIFY_SET_COLS, getCols());
notify(NOTIFY_SET_ROWS, getRows());
notify(NOTIFY_SET_VOLUME, m_volume);
notify(NOTIFY_SET_VOLUME_LOCAL, m_volumeLocal);
notify(NOTIFY_SET_VOLUME_REMOTE, m_volumeRemote);
notify(NOTIFY_SET_PLAYBACK_LOCAL, m_playbackLocal);
notify(NOTIFY_SET_MUTE_MYSELF_DURING_PB, m_muteMyselfDuringPb);
notify(NOTIFY_SET_WINDOW_SIZE, 0);
Expand Down
13 changes: 9 additions & 4 deletions src/ConfigModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class ConfigModel
NOTIFY_SET_SOUND,
NOTIFY_SET_ROWS,
NOTIFY_SET_COLS,
NOTIFY_SET_VOLUME,
NOTIFY_SET_VOLUME_LOCAL,
NOTIFY_SET_VOLUME_REMOTE,
NOTIFY_SET_PLAYBACK_LOCAL,
NOTIFY_SET_MUTE_MYSELF_DURING_PB,
NOTIFY_SET_WINDOW_SIZE,
Expand Down Expand Up @@ -69,8 +70,11 @@ class ConfigModel
inline int getCols() const { return m_cols[m_activeConfig]; }
void setCols(int n);

inline int getVolume() const { return m_volume; }
void setVolume(int val);
inline int getVolumeLocal() const { return m_volumeLocal; }
void setVolumeLocal(int val);

inline int getVolumeRemote() const { return m_volumeRemote; }
void setVolumeRemote(int val);

inline bool getPlaybackLocal() const { return m_playbackLocal; }
void setPlaybackLocal(bool val);
Expand Down Expand Up @@ -121,7 +125,8 @@ class ConfigModel

std::array<int, NUM_CONFIGS> m_rows;
std::array<int, NUM_CONFIGS> m_cols;
int m_volume;
int m_volumeLocal;
int m_volumeRemote;
bool m_playbackLocal;
bool m_muteMyselfDuringPb;
int m_windowWidth;
Expand Down
1 change: 1 addition & 0 deletions src/SoundInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <QSettings>
#include <QColor>
#include <stdexcept>

class SoundInfo
{
Expand Down
1 change: 1 addition & 0 deletions src/TalkStateManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <QObject>
#include <stdexcept>
#include "common.h"

class TalkStateManager : public QObject
Expand Down
59 changes: 49 additions & 10 deletions src/config_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,17 @@ ConfigQt::ConfigQt( ConfigModel *model, QWidget *parent /*= 0*/ ) :
ui->b_pause->setContextMenuPolicy(Qt::CustomContextMenu);
ui->cb_mute_locally->setContextMenuPolicy(Qt::CustomContextMenu);
ui->cb_mute_myself->setContextMenuPolicy(Qt::CustomContextMenu);
ui->sl_volume->setContextMenuPolicy(Qt::CustomContextMenu);
ui->sl_volumeLocal->setContextMenuPolicy(Qt::CustomContextMenu);
ui->sl_volumeRemote->setContextMenuPolicy(Qt::CustomContextMenu);

connect(ui->b_stop, SIGNAL(clicked()), this, SLOT(onClickedStop()));
connect(ui->b_stop, SIGNAL(customContextMenuRequested(const QPoint&)), this,
SLOT(showStopButtonContextMenu(const QPoint&)));
connect(ui->b_pause, SIGNAL(clicked()), this, SLOT(onButtonPausePressed()));
connect(ui->b_pause, SIGNAL(customContextMenuRequested(const QPoint&)), this,
SLOT(showPauseButtonContextMenu(const QPoint&)));
connect(ui->sl_volume, SIGNAL(valueChanged(int)), this, SLOT(onUpdateVolume(int)));
connect(ui->sl_volumeLocal, SIGNAL(valueChanged(int)), this, SLOT(onUpdateVolumeLocal(int)));
connect(ui->sl_volumeRemote, SIGNAL(valueChanged(int)), this, SLOT(onUpdateVolumeRemote(int)));
connect(ui->cb_mute_locally, SIGNAL(clicked(bool)), this, SLOT(onUpdateMuteLocally(bool)));
connect(ui->sb_rows, SIGNAL(valueChanged(int)), this, SLOT(onUpdateRows(int)));
connect(ui->sb_cols, SIGNAL(valueChanged(int)), this, SLOT(onUpdateCols(int)));
Expand All @@ -115,7 +117,8 @@ ConfigQt::ConfigQt( ConfigModel *model, QWidget *parent /*= 0*/ ) :
[this](const QPoint &point) {this->showSetHotkeyMenu(HOTKEY_MUTE_ON_MY_CLIENT, ui->cb_mute_locally->mapToGlobal(point));});
connect(ui->cb_mute_myself, &QCheckBox::customContextMenuRequested,
[this](const QPoint &point) {this->showSetHotkeyMenu(HOTKEY_MUTE_MYSELF, ui->cb_mute_myself->mapToGlobal(point));});
connect(ui->sl_volume, &QSlider::customContextMenuRequested, this, &ConfigQt::onVolumeSliderContextMenu);
connect(ui->sl_volumeLocal, &QSlider::customContextMenuRequested, this, &ConfigQt::onVolumeSliderContextMenuLocal);
connect(ui->sl_volumeRemote, &QSlider::customContextMenuRequested, this, &ConfigQt::onVolumeSliderContextMenuRemote);

/* Load/Save Model */
connect(ui->pushLoad, SIGNAL(released()), this, SLOT(onLoadModel()));
Expand Down Expand Up @@ -250,9 +253,18 @@ void ConfigQt::onClickedStop()
//---------------------------------------------------------------
// Purpose:
//---------------------------------------------------------------
void ConfigQt::onUpdateVolume(int val)
void ConfigQt::onUpdateVolumeLocal(int val)
{
m_model->setVolume(val);
m_model->setVolumeLocal(val);
}


//---------------------------------------------------------------
// Purpose:
//---------------------------------------------------------------
void ConfigQt::onUpdateVolumeRemote(int val)
{
m_model->setVolumeRemote(val);
}


Expand Down Expand Up @@ -951,7 +963,7 @@ void ConfigQt::onFilterEditTextChanged(const QString &text)
//---------------------------------------------------------------
// Purpose:
//---------------------------------------------------------------
void ConfigQt::onVolumeSliderContextMenu(const QPoint &point)
void ConfigQt::onVolumeSliderContextMenuLocal(const QPoint &point)
{
QString hotkeyStringIncr = getShortcutString(HOTKEY_VOLUME_INCREASE);
QString hotkeyTextIncr = "Set 'increase 20%' hotkey (Current: " +
Expand All @@ -964,14 +976,37 @@ void ConfigQt::onVolumeSliderContextMenu(const QPoint &point)
QMenu menu;
QAction *actIncr = menu.addAction(hotkeyTextIncr);
QAction *actDecr = menu.addAction(hotkeyTextDecr);
QAction *action = menu.exec(ui->sl_volume->mapToGlobal(point));
QAction *action = menu.exec(ui->sl_volumeLocal->mapToGlobal(point));
if (action == actIncr)
ts3Functions.requestHotkeyInputDialog(getPluginID(), HOTKEY_VOLUME_INCREASE, 0, this);
else if (action == actDecr)
ts3Functions.requestHotkeyInputDialog(getPluginID(), HOTKEY_VOLUME_DECREASE, 0, this);
}


//---------------------------------------------------------------
// Purpose:
//---------------------------------------------------------------
void ConfigQt::onVolumeSliderContextMenuRemote(const QPoint &point)
{
QString hotkeyStringIncr = getShortcutString(HOTKEY_VOLUME_INCREASE);
QString hotkeyTextIncr = "Set 'increase 20%' hotkey (Current: " +
(hotkeyStringIncr.isEmpty() ? QString("None") : hotkeyStringIncr) + ")";

QString hotkeyStringDecr = getShortcutString(HOTKEY_VOLUME_DECREASE);
QString hotkeyTextDecr = "Set 'decrease 20%' hotkey (Current: " +
(hotkeyStringDecr.isEmpty() ? QString("None") : hotkeyStringDecr) + ")";

QMenu menu;
QAction *actIncr = menu.addAction(hotkeyTextIncr);
QAction *actDecr = menu.addAction(hotkeyTextDecr);
QAction *action = menu.exec(ui->sl_volumeRemote->mapToGlobal(point));
if (action == actIncr)
ts3Functions.requestHotkeyInputDialog(getPluginID(), HOTKEY_VOLUME_INCREASE, 0, this);
else if (action == actDecr)
ts3Functions.requestHotkeyInputDialog(getPluginID(), HOTKEY_VOLUME_DECREASE, 0, this);
}

//---------------------------------------------------------------
// Purpose:
//---------------------------------------------------------------
Expand All @@ -989,9 +1024,13 @@ void ConfigQt::ModelObserver::notify(ConfigModel &model, ConfigModel::notificati
p.ui->sb_cols->setValue(model.getCols());
p.createButtons();
break;
case ConfigModel::NOTIFY_SET_VOLUME:
if (p.ui->sl_volume->value() != model.getVolume())
p.ui->sl_volume->setValue(model.getVolume());
case ConfigModel::NOTIFY_SET_VOLUME_LOCAL:
if (p.ui->sl_volumeLocal->value() != model.getVolumeLocal())
p.ui->sl_volumeLocal->setValue(model.getVolumeLocal());
break;
case ConfigModel::NOTIFY_SET_VOLUME_REMOTE:
if (p.ui->sl_volumeRemote->value() != model.getVolumeRemote())
p.ui->sl_volumeRemote->setValue(model.getVolumeRemote());
break;
case ConfigModel::NOTIFY_SET_PLAYBACK_LOCAL:
if (p.ui->cb_mute_locally->isChecked() != !model.getPlaybackLocal())
Expand Down
6 changes: 4 additions & 2 deletions src/config_qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class ConfigQt : public QWidget
private slots:
void onClickedPlay();
void onClickedStop();
void onUpdateVolume(int val);
void onUpdateVolumeLocal(int val);
void onUpdateVolumeRemote(int val);
void onUpdateMuteLocally(bool val);
void onUpdateCols(int val);
void onUpdateRows(int val);
Expand All @@ -83,7 +84,8 @@ private slots:
void onButtonPausePressed();
void onButtonDroppedOnButton(SoundButton *button);
void onFilterEditTextChanged(const QString &filter);
void onVolumeSliderContextMenu(const QPoint &point);
void onVolumeSliderContextMenuLocal(const QPoint &point);
void onVolumeSliderContextMenuRemote(const QPoint &point);

void onSetConfig();
void onConfigHotkey();
Expand Down
33 changes: 30 additions & 3 deletions src/config_qt.ui
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Volume:</string>
<string>Volume Remote:</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="sl_volume">
<widget class="QSlider" name="sl_volumeRemote">
<property name="maximum">
<number>100</number>
</property>
Expand All @@ -241,7 +241,34 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5"/>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Volume Local:</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="sl_volumeLocal">
<property name="maximum">
<number>100</number>
</property>
<property name="pageStep">
<number>10</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
<property name="tickInterval">
<number>0</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
Expand Down
13 changes: 9 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ void ModelObserver_Prog::notify(ConfigModel &model, ConfigModel::notifications_e
{
switch(what)
{
case ConfigModel::NOTIFY_SET_VOLUME:
sampler->setVolume(data);
case ConfigModel::NOTIFY_SET_VOLUME_LOCAL:
sampler->setVolumeLocal(data);
break;
case ConfigModel::NOTIFY_SET_VOLUME_REMOTE:
sampler->setVolumeRemote(data);
break;
case ConfigModel::NOTIFY_SET_PLAYBACK_LOCAL:
sampler->setLocalPlayback(model.getPlaybackLocal());
Expand Down Expand Up @@ -385,11 +388,13 @@ CAPI void sb_onHotkeyPressed(const char * keyword)
}
else if (strcmp(keyword, HOTKEY_VOLUME_INCREASE) == 0)
{
configModel->setVolume(std::min(configModel->getVolume() + 20, 100));
configModel->setVolumeRemote(std::min(configModel->getVolumeRemote() + 20, 100));
configModel->setVolumeLocal(std::min(configModel->getVolumeLocal() + 20, 100));
}
else if (strcmp(keyword, HOTKEY_VOLUME_DECREASE) == 0)
{
configModel->setVolume(std::max(configModel->getVolume() - 20, 0));
configModel->setVolumeRemote(std::max(configModel->getVolumeRemote() - 20, 0));
configModel->setVolumeLocal(std::min(configModel->getVolumeLocal() - 20, 0));
}
}

Expand Down
Loading

0 comments on commit 3e6d0ce

Please sign in to comment.