diff --git a/.gitignore b/.gitignore index c532eba..549f74c 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/src/ConfigModel.cpp b/src/ConfigModel.cpp index a373f88..761c4a8 100644 --- a/src/ConfigModel.cpp +++ b/src/ConfigModel.cpp @@ -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; @@ -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(); @@ -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); @@ -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: @@ -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); diff --git a/src/ConfigModel.h b/src/ConfigModel.h index 51e1339..48653af 100644 --- a/src/ConfigModel.h +++ b/src/ConfigModel.h @@ -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, @@ -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); @@ -121,7 +125,8 @@ class ConfigModel std::array m_rows; std::array m_cols; - int m_volume; + int m_volumeLocal; + int m_volumeRemote; bool m_playbackLocal; bool m_muteMyselfDuringPb; int m_windowWidth; diff --git a/src/SoundInfo.h b/src/SoundInfo.h index aaf1e78..74797d4 100644 --- a/src/SoundInfo.h +++ b/src/SoundInfo.h @@ -12,6 +12,7 @@ #include #include +#include class SoundInfo { diff --git a/src/TalkStateManager.h b/src/TalkStateManager.h index 77c114b..f9e14fe 100644 --- a/src/TalkStateManager.h +++ b/src/TalkStateManager.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include "common.h" class TalkStateManager : public QObject diff --git a/src/config_qt.cpp b/src/config_qt.cpp index cd71507..cbb6689 100644 --- a/src/config_qt.cpp +++ b/src/config_qt.cpp @@ -95,7 +95,8 @@ 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, @@ -103,7 +104,8 @@ ConfigQt::ConfigQt( ConfigModel *model, QWidget *parent /*= 0*/ ) : 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))); @@ -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())); @@ -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); } @@ -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: " + @@ -964,7 +976,7 @@ 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) @@ -972,6 +984,29 @@ void ConfigQt::onVolumeSliderContextMenu(const QPoint &point) } +//--------------------------------------------------------------- +// 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: //--------------------------------------------------------------- @@ -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()) diff --git a/src/config_qt.h b/src/config_qt.h index 53e4097..d57774d 100644 --- a/src/config_qt.h +++ b/src/config_qt.h @@ -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); @@ -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(); diff --git a/src/config_qt.ui b/src/config_qt.ui index 251ebfd..fc00212 100644 --- a/src/config_qt.ui +++ b/src/config_qt.ui @@ -215,12 +215,12 @@ - Volume: + Volume Remote: - + 100 @@ -241,7 +241,34 @@ - + + + + + Volume Local: + + + + + + + 100 + + + 10 + + + Qt::Horizontal + + + QSlider::NoTicks + + + 0 + + + + diff --git a/src/main.cpp b/src/main.cpp index 8be8022..bc9c86a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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()); @@ -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)); } } diff --git a/src/samples.cpp b/src/samples.cpp index 0a0b84d..813ed27 100644 --- a/src/samples.cpp +++ b/src/samples.cpp @@ -59,7 +59,8 @@ Sampler::Sampler() : m_peakMeterCapture(0.01f, 0.00005f, 24000), m_peakMeterPlayback(0.01f, 0.00005f, 24000), m_volumeDivider(1), - m_globalDbSetting(-1.0), + m_globalDbSettingLocal(-1.0), + m_globalDbSettingRemote(-1.0), m_soundDbSetting(0.0), m_state(eSILENT), m_localPlayback(true) @@ -312,6 +313,7 @@ int Sampler::fetchInputSamples(short *samples, int count, int channels, bool *fi { std::lock_guard Lock(m_mutex); + setVolumeDb(m_globalDbSettingRemote + m_soundDbSetting); int written = fetchSamples(m_sbCapture, m_peakMeterCapture, samples, count, channels, true, 0, 1, m_muteMyself, m_muteMyself); if(m_state == ePLAYING && m_inputFile && m_inputFile->done()) @@ -338,6 +340,7 @@ int Sampler::fetchOutputSamples(short *samples, int count, int channels, const u const unsigned int bitMaskRight = SPEAKER_FRONT_RIGHT | SPEAKER_HEADPHONES_RIGHT; int ciLeft = findChannelId(bitMaskLeft, channelSpeakerArray, channels); int ciRight = findChannelId(bitMaskRight, channelSpeakerArray, channels); + setVolumeDb(m_globalDbSettingLocal + m_soundDbSetting); int written = fetchSamples(m_sbPlayback, m_peakMeterPlayback, samples, count, channels, true, ciLeft, ciRight, (*channelFillMask & bitMaskLeft) == 0, (*channelFillMask & bitMaskRight) == 0); @@ -388,12 +391,24 @@ void Sampler::stopPlayback() //--------------------------------------------------------------- // Purpose: //--------------------------------------------------------------- -void Sampler::setVolume( int vol ) +void Sampler::setVolumeRemote( int vol ) { double v = (double)vol / 100.0; double db = pow(1.0 - v, VOLUMESCALER_EXPONENT) * VOLUMESCALER_DB_MIN; - m_globalDbSetting = db; - setVolumeDb(m_globalDbSetting + m_soundDbSetting); + m_globalDbSettingRemote = db; + setVolumeDb(m_globalDbSettingRemote + m_soundDbSetting); +} + + +//--------------------------------------------------------------- +// Purpose: +//--------------------------------------------------------------- +void Sampler::setVolumeLocal( int vol ) +{ + double v = (double)vol / 100.0; + double db = pow(1.0 - v, VOLUMESCALER_EXPONENT) * VOLUMESCALER_DB_MIN; + m_globalDbSettingLocal = db; + setVolumeDb(m_globalDbSettingLocal + m_soundDbSetting); } @@ -470,7 +485,7 @@ bool Sampler::playSoundInternal( const SoundInfo &sound, bool preview ) } m_soundDbSetting = (double)sound.volume; - setVolumeDb(m_globalDbSetting + m_soundDbSetting); + setVolumeDb(m_globalDbSettingLocal + m_soundDbSetting); SampleBuffer::Lock sblc(m_sbCapture.getMutex()); SampleBuffer::Lock sblp(m_sbPlayback.getMutex()); diff --git a/src/samples.h b/src/samples.h index 56ba6ff..e84d1b4 100644 --- a/src/samples.h +++ b/src/samples.h @@ -46,7 +46,8 @@ class Sampler : public QObject bool playFile(const SoundInfo &sound); bool playPreview(const SoundInfo &sound); void stopPlayback(); - void setVolume(int vol); + void setVolumeLocal(int vol); + void setVolumeRemote(int vol); void setLocalPlayback(bool enabled); void setMuteMyself(bool enabled); void pausePlayback(); @@ -79,7 +80,8 @@ class Sampler : public QObject int m_volumeDivider; float m_volumeFactor; static const int volumeScaleExp = 12; - double m_globalDbSetting; + double m_globalDbSettingLocal; + double m_globalDbSettingRemote; double m_soundDbSetting; std::mutex m_mutex; std::atomic m_state;