Skip to content
Open
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
29 changes: 29 additions & 0 deletions src/plugin-sound/operation/sounddbusproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,35 @@
return qvariant_cast<bool>(m_audioInter->property("PausePlayer"));
}

bool SoundDBusProxy::aiReduceNoise()

Check warning on line 102 in src/plugin-sound/operation/sounddbusproxy.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'aiReduceNoise' is never used.
{
return qvariant_cast<bool>(m_audioInter->property("AiReduceNoise"));
}

void SoundDBusProxy::setAiReduceNoise(bool value)
{
m_audioInter->setProperty("AiReduceNoise", QVariant::fromValue(value));
}

QDBusObjectPath SoundDBusProxy::aiNoiseSourcePath()

Check warning on line 112 in src/plugin-sound/operation/sounddbusproxy.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'aiNoiseSourcePath' is never used.
{
return qvariant_cast<QDBusObjectPath>(m_audioInter->property("AiNoiseSourcePath"));
}

bool SoundDBusProxy::requestSetAiReduceNoise(bool value)

Check warning on line 117 in src/plugin-sound/operation/sounddbusproxy.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'requestSetAiReduceNoise' is never used.
{
QDBusMessage msg = QDBusMessage::createMethodCall(
AudioService, AudioPath,
QStringLiteral("org.freedesktop.DBus.Properties"),
QStringLiteral("Set"));
msg << AudioInterface
<< QStringLiteral("AiReduceNoise")
<< QVariant::fromValue(value);
QDBusPendingCall call = QDBusConnection::sessionBus().asyncCall(msg);
call.waitForFinished();
return !call.isError();
}

void SoundDBusProxy::setPausePlayer(bool value)
{
m_audioInter->setProperty("PausePlayer", QVariant::fromValue(value));
Expand Down
12 changes: 11 additions & 1 deletion src/plugin-sound/operation/sounddbusproxy.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef SOUNDDBUSPROXY_H
Expand Down Expand Up @@ -70,6 +70,14 @@ class SoundDBusProxy : public QObject
bool reduceNoise();
void setReduceNoise(bool value);

Q_PROPERTY(bool AiReduceNoise READ aiReduceNoise WRITE setAiReduceNoise NOTIFY AiReduceNoiseChanged)
bool aiReduceNoise();
void setAiReduceNoise(bool value);
bool requestSetAiReduceNoise(bool value);

Q_PROPERTY(QDBusObjectPath AiNoiseSourcePath READ aiNoiseSourcePath NOTIFY AiNoiseSourcePathChanged)
QDBusObjectPath aiNoiseSourcePath();

Q_PROPERTY(bool PausePlayer READ pausePlayer WRITE setPausePlayer NOTIFY PausePlayerChanged)
bool pausePlayer();
void setPausePlayer(bool value);
Expand Down Expand Up @@ -145,8 +153,10 @@ class SoundDBusProxy : public QObject
void CardsChanged(const QString &value) const;
void CardsWithoutUnavailableChanged(const QString &value) const;
void DefaultSinkChanged(const QDBusObjectPath &value) const;
void AiNoiseSourcePathChanged(const QDBusObjectPath &value) const;
void DefaultSourceChanged(const QDBusObjectPath &value) const;
void IncreaseVolumeChanged(bool value) const;
void AiReduceNoiseChanged(bool value) const;
void MaxUIVolumeChanged(double value) const;
void ReduceNoiseChanged(bool value) const;
void PausePlayerChanged(bool value) const;
Expand Down
21 changes: 21 additions & 0 deletions src/plugin-sound/operation/soundmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ void SoundModel::setReduceNoise(bool reduceNoise)
}
}

void SoundModel::setAiReduceNoise(bool aiReduceNoise)
{
if (aiReduceNoise != m_aiReduceNoise) {
m_aiReduceNoise = aiReduceNoise;
Q_EMIT aiReduceNoiseChanged(aiReduceNoise);
}
}

void SoundModel::setPausePlayer(bool pausePlayer)
{
if (pausePlayer != m_pausePlayer) {
Expand Down Expand Up @@ -356,6 +364,19 @@ void SoundModel::setDefaultSource(const QDBusObjectPath &defaultSource)
Q_EMIT defaultSourceChanged(m_defaultSource);
}

QDBusObjectPath SoundModel::aiNoiseSourcePath() const
{
return m_aiNoiseSourcePath;
}

void SoundModel::setAiNoiseSourcePath(const QDBusObjectPath &path)
{
if (path != m_aiNoiseSourcePath) {
m_aiNoiseSourcePath = path;
Q_EMIT aiNoiseSourcePathChanged(m_aiNoiseSourcePath);
}
}

QDBusObjectPath SoundModel::defaultSink() const
{
return m_defaultSink;
Expand Down
11 changes: 10 additions & 1 deletion src/plugin-sound/operation/soundmodel.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef DCC_SOUND_SOUNDMODEL_H
Expand Down Expand Up @@ -38,6 +38,7 @@ class SoundModel : public QObject

Q_PROPERTY(double microphoneVolume READ microphoneVolume NOTIFY microphoneVolumeChanged)
Q_PROPERTY(bool reduceNoise READ reduceNoise NOTIFY reduceNoiseChanged)
Q_PROPERTY(bool aiReduceNoise READ aiReduceNoise NOTIFY aiReduceNoiseChanged)
Q_PROPERTY(int outPutPortComboIndex READ outPutPortComboIndex NOTIFY outPutPortComboIndexChanged FINAL)
Q_PROPERTY(double microphoneFeedback READ microphoneFeedback NOTIFY microphoneFeedbackChanged)
Q_PROPERTY(bool enableSoundEffect READ enableSoundEffect NOTIFY enableSoundEffectChanged)
Expand Down Expand Up @@ -73,6 +74,8 @@ class SoundModel : public QObject

inline bool reduceNoise() const { return m_reduceNoise; }
void setReduceNoise(bool reduceNoise);
inline bool aiReduceNoise() const { return m_aiReduceNoise; }
void setAiReduceNoise(bool aiReduceNoise);

inline bool pausePlayer() const { return m_pausePlayer; }
void setPausePlayer(bool reduceNoise);
Expand Down Expand Up @@ -106,6 +109,8 @@ class SoundModel : public QObject

QDBusObjectPath defaultSource() const;
void setDefaultSource(const QDBusObjectPath &defaultSource);
QDBusObjectPath aiNoiseSourcePath() const;
void setAiNoiseSourcePath(const QDBusObjectPath &path);

QDBusObjectPath defaultSink() const;
void setDefaultSink(const QDBusObjectPath &defaultSink);
Expand Down Expand Up @@ -232,6 +237,8 @@ class SoundModel : public QObject
void maxUIVolumeChanged(double value) const;
void increaseVolumeChanged(bool value) const;
void reduceNoiseChanged(bool reduceNoise) const;
void aiReduceNoiseChanged(bool aiReduceNoise) const;
void aiNoiseSourcePathChanged(const QDBusObjectPath &path) const;
void pausePlayerChanged(bool pausePlayer) const;
void isPortEnableChanged(bool enable) const;
void bluetoothModeOptsChanged(const QStringList &modeOpts) const;
Expand Down Expand Up @@ -290,6 +297,7 @@ class SoundModel : public QObject
bool m_isLaptop;
bool m_increaseVolume{false};
bool m_reduceNoise{true};
bool m_aiReduceNoise{true};
bool m_pausePlayer{true};
bool m_portEnable{false};
double m_speakerVolume;
Expand All @@ -308,6 +316,7 @@ class SoundModel : public QObject

QDBusObjectPath m_defaultSource;
QDBusObjectPath m_defaultSink;
QDBusObjectPath m_aiNoiseSourcePath;
QString m_audioCards;
QStringList m_bluetoothModeOpts;
QString m_currentBluetoothMode;
Expand Down
52 changes: 52 additions & 0 deletions src/plugin-sound/operation/soundworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ void SoundWorker::initConnect()
connect(m_soundDBusInter, &SoundDBusProxy::IncreaseVolumeChanged, m_model, &SoundModel::setIncreaseVolume);
connect(m_soundDBusInter, &SoundDBusProxy::CardsWithoutUnavailableChanged, m_model, &SoundModel::setAudioCards);
connect(m_soundDBusInter, &SoundDBusProxy::ReduceNoiseChanged, m_model, &SoundModel::setReduceNoise);
connect(m_soundDBusInter, &SoundDBusProxy::AiReduceNoiseChanged, m_model, &SoundModel::setAiReduceNoise);
connect(m_soundDBusInter, &SoundDBusProxy::AiReduceNoiseChanged, this, &SoundWorker::aiReduceNoiseOrPathChanged);
connect(m_soundDBusInter, &SoundDBusProxy::AiNoiseSourcePathChanged, m_model, &SoundModel::setAiNoiseSourcePath);
connect(m_soundDBusInter, &SoundDBusProxy::AiNoiseSourcePathChanged, this, &SoundWorker::aiReduceNoiseOrPathChanged);
connect(m_soundDBusInter, &SoundDBusProxy::PausePlayerChanged, m_model, &SoundModel::setPausePlayer);
connect(m_soundDBusInter, &SoundDBusProxy::BluetoothAudioModeOptsChanged, m_model, &SoundModel::setBluetoothAudioModeOpts);
connect(m_soundDBusInter, &SoundDBusProxy::BluetoothAudioModeChanged, m_model, &SoundModel::setCurrentBluetoothAudioMode);
Expand Down Expand Up @@ -100,6 +104,8 @@ void SoundWorker::activate()
m_model->setMaxUIVolume(m_soundDBusInter->maxUIVolume());
m_model->setIncreaseVolume(m_soundDBusInter->increaseVolume());
m_model->setReduceNoise(m_soundDBusInter->reduceNoise());
m_model->setAiReduceNoise(m_soundDBusInter->aiReduceNoise());
m_model->setAiNoiseSourcePath(m_soundDBusInter->aiNoiseSourcePath());
m_model->setPausePlayer(m_soundDBusInter->pausePlayer());
m_model->setBluetoothAudioModeOpts(m_soundDBusInter->bluetoothAudioModeOpts());
m_model->setCurrentBluetoothAudioMode(m_soundDBusInter->bluetoothAudioMode());
Expand Down Expand Up @@ -238,6 +244,26 @@ void SoundWorker::setReduceNoise(bool value)
m_soundDBusInter->setReduceNoise(value);
}

void SoundWorker::setAiReduceNoise(bool value)
{
bool origin = m_model->aiReduceNoise();

bool ok = m_soundDBusInter->requestSetAiReduceNoise(value);
if (!ok) {
qCWarning(DdcSoundWorker) << "AiReduceNoise: failed to set" << value << ", restoring state";
m_model->setAiReduceNoise(origin);
QString msg = value ? tr("Failed to enable intelligent noise reduction. Try again later.")
: tr("Failed to disable intelligent noise reduction. Try again later.");
Dtk::Core::DUtil::DNotifySender(msg)
.appIcon("")
.appName("org.deepin.dde.control-center")
.timeOut(5000)
.call();
} else {
m_model->setAiReduceNoise(value);
}
}

void SoundWorker::setPausePlayer(bool value)
{
m_soundDBusInter->setPausePlayer(value);
Expand Down Expand Up @@ -336,9 +362,35 @@ void SoundWorker::defaultSinkChanged(const QDBusObjectPath &path)
void SoundWorker::defaultSourceChanged(const QDBusObjectPath &path)
{
qDebug() << "source default path:" << path.path();
rebindSource(effectiveSourcePath());
}

void SoundWorker::aiReduceNoiseOrPathChanged()
{
rebindSource(effectiveSourcePath());
}

QDBusObjectPath SoundWorker::effectiveSourcePath() const
{
if (m_model->aiReduceNoise()) {
const auto &path = m_model->aiNoiseSourcePath();
if (!path.path().isEmpty() && path.path() != "/") {
return path;
}
}
return m_model->defaultSource();
}

void SoundWorker::rebindSource(const QDBusObjectPath &path)
{
if (path.path().isEmpty() || path.path() == "/" ) return; //路径为空

m_soundDBusInter->setSourceDevicePath(path.path());
disconnect(m_soundDBusInter, &SoundDBusProxy::MuteSourceChanged, nullptr, nullptr);
disconnect(m_soundDBusInter, &SoundDBusProxy::VolumeSourceChanged, nullptr, nullptr);
disconnect(m_soundDBusInter, &SoundDBusProxy::ActivePortSourceChanged, nullptr, nullptr);
disconnect(m_soundDBusInter, &SoundDBusProxy::CardSourceChanged, nullptr, nullptr);
disconnect(m_soundDBusInter, &SoundDBusProxy::VolumeMeterChanged, nullptr, nullptr);

connect(m_soundDBusInter, &SoundDBusProxy::MuteSourceChanged, [this](bool mute) { m_model->setMicrophoneOn(mute); });
connect(m_soundDBusInter, &SoundDBusProxy::VolumeSourceChanged, m_model, &SoundModel::setMicrophoneVolume);
Expand Down
8 changes: 7 additions & 1 deletion src/plugin-sound/operation/soundworker.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef SOUNDWORKER_H
Expand All @@ -13,9 +13,10 @@
#include <DDesktopServices>
#include "qdbusconnectioninterface.h"
#include <QtQml/qqml.h>
#include <QTimer>

Check warning on line 16 in src/plugin-sound/operation/soundworker.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QSoundEffect>

Check warning on line 17 in src/plugin-sound/operation/soundworker.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSoundEffect> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMediaDevices>

Check warning on line 18 in src/plugin-sound/operation/soundworker.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMediaDevices> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DNotifySender>

Check warning on line 19 in src/plugin-sound/operation/soundworker.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DNotifySender> not found. Please note: Cppcheck does not need standard library headers to get proper results.

class SoundWorker : public QObject
{
Expand All @@ -31,6 +32,7 @@

Q_INVOKABLE void setSinkVolume(double volume);
Q_INVOKABLE void setReduceNoise(bool value);
Q_INVOKABLE void setAiReduceNoise(bool value);
Q_INVOKABLE void setPausePlayer(bool value);
Q_INVOKABLE void setIncreaseVolume(bool value);
Q_INVOKABLE void setSinkBalance(double balance);
Expand Down Expand Up @@ -62,6 +64,7 @@
private Q_SLOTS:
void defaultSinkChanged(const QDBusObjectPath &path);
void defaultSourceChanged(const QDBusObjectPath &path);
void aiReduceNoiseOrPathChanged();
void cardsChanged(const QString &cards);

void activeSinkPortChanged(const AudioPort &activeSinkPort);
Expand All @@ -83,6 +86,9 @@
void initConnect();
void updatePortActivity();
void initAudioServerData();
QDBusObjectPath effectiveSourcePath() const;
void rebindSource(const QDBusObjectPath &path);


private:
SoundModel *m_model;
Expand Down
10 changes: 5 additions & 5 deletions src/plugin-sound/qml/MicrophonePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,19 @@ DccObject {
}

DccObject {
name: "reduceNoise"
name: "aiReduceNoise"
parentName: "sound/inPut/inputGroup"
displayName: qsTr("Automatic Noise Suppression")
displayName: qsTr("Intelligent Noise Reduction")
weight: 30
pageType: DccObject.Editor
visible: !dccData.model().showInputBluetoothMode
page: Switch {
Layout.alignment: Qt.AlignRight | Qt.AlignTop

checked: dccData.model().reduceNoise
checked: dccData.model().aiReduceNoise
onCheckedChanged: {
if (dccData.model().reduceNoise !== checked) {
dccData.worker().setReduceNoise(checked)
if (dccData.model().aiReduceNoise !== checked) {
dccData.worker().setAiReduceNoise(checked)
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions translations/dde-control-center_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2394,6 +2394,18 @@ Sign in to %1 ID to get personalized features and services of Browser, App Store
<source>Automatic Noise Suppression</source>
<translation>噪音抑制</translation>
</message>
<message>
<source>Intelligent Noise Reduction</source>
<translation>智能降噪</translation>
</message>
<message>
<source>Failed to enable intelligent noise reduction. Try again later.</source>
<translation>智能降噪开启失败,请稍后重试</translation>
</message>
<message>
<source>Failed to disable intelligent noise reduction. Try again later.</source>
<translation>智能降噪关闭失败,请稍后重试</translation>
</message>
<message>
<source>Input Volume</source>
<translation>输入音量</translation>
Expand Down
Loading