refs #335, improved audio setup

* changed volume methods from QList<qint32> to qint32 (DBus compliance)
* methods for changed devices
* command parser for audio
* volume display in status bar (pseudo mute)
This commit is contained in:
Klaus Basan
2014-11-05 16:49:49 +01:00
committed by Roland Winklmeier
parent 3fd1f3c8c4
commit 1ea330cc06
11 changed files with 228 additions and 65 deletions

View File

@@ -83,11 +83,17 @@ namespace BlackCore
// KB: Is see some potential changes here, which we should do when we have the new 2.0 vatlib
// 1. volume integrated in voice room?
// 2. Value object for volumes CVolume / CVolumeList?
void changedAudioVolumes(QList<qint32> volumes);
void changedAudioVolumes(qint32 com1Volume, qint32 com2Volume);
//! Mute changed
void changedMute(bool muted);
//! Changed audio devices (e.g. device enabled/disable)
void changedAudioDevices(const BlackMisc::Audio::CAudioDeviceList &devices);
//! Changed slection of audio devices
void changedSelectedAudioDevices(const BlackMisc::Audio::CAudioDeviceList &devices);
public slots:
//! Get voice rooms for COM1, COM2:
virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const = 0;
@@ -182,6 +188,9 @@ namespace BlackCore
//! Enable audio loopback
virtual void enableAudioLoopback(bool enable = true) = 0;
//! Command line was entered
virtual bool parseCommandLine(const QString &commandLine) = 0;
};
}

View File

@@ -14,6 +14,7 @@
#include "blackmisc/voiceroomlist.h"
#include "blackmisc/hotkeyfunction.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/simplecommandparser.h"
#include <QTimer>
@@ -154,13 +155,27 @@ namespace BlackCore
Q_ASSERT(this->m_voice);
Q_ASSERT(audioDevice.getType() != CAudioDevice::Unknown);
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << audioDevice;
bool changed = false;
if (audioDevice.getType() == CAudioDevice::InputDevice)
{
this->m_voice->setInputDevice(audioDevice);
if (this->m_voice->getCurrentInputDevice() != audioDevice)
{
this->m_voice->setInputDevice(audioDevice);
changed = true;
}
}
else
{
this->m_voice->setOutputDevice(audioDevice);
if (this->m_voice->getCurrentOutputDevice() != audioDevice)
{
this->m_voice->setOutputDevice(audioDevice);
changed = true;
}
}
if (changed)
{
emit changedSelectedAudioDevices(this->getCurrentAudioDevices());
}
}
@@ -176,28 +191,45 @@ namespace BlackCore
qint32 vol1 = com1.getVolumeOutput();
qint32 vol2 = com2.getVolumeOutput();
this->setVolumes(vol1, vol2);
// enable / disable in the same step
m_channelCom1->switchAudioOutput(com1.isEnabled());
m_channelCom2->switchAudioOutput(com2.isEnabled());
}
void CContextAudio::setVolumes(qint32 com1Volume, qint32 com2Volume)
{
if (m_channelCom1->getVolume() == com1Volume && m_channelCom2->getVolume() == com2Volume) { return; }
m_channelCom1->setRoomOutputVolume(com1Volume);
m_channelCom2->setRoomOutputVolume(com2Volume);
m_channelCom1->switchAudioOutput(com1Volume < 1);
m_channelCom2->switchAudioOutput(com2Volume < 1);
emit changedAudioVolumes(QList<qint32>({com1Volume, com2Volume}));
bool enable1 = com1Volume > 0;
bool enable2 = com2Volume > 0;
bool muted = !enable1 && !enable2;
//! \todo m_channelCom1->setVolume here crashed, also what is correct setRoomOutputVolume or setVolume
m_channelCom1->setVolume(com1Volume);
m_channelCom2->setVolume(com2Volume);
this->setMute(muted);
emit changedAudioVolumes(com1Volume, com2Volume);
}
void CContextAudio::setMute(bool muted)
{
if (this->isMuted() == muted) { return; } // avoid roundtrips / unnecessary signals
m_channelCom1->switchAudioOutput(!muted);
m_channelCom2->switchAudioOutput(!muted);
m_channelCom1->setRoomOutputVolume(muted ? 0 : VoiceRoomEnabledVolume);
m_channelCom2->setRoomOutputVolume(muted ? 0 : VoiceRoomEnabledVolume);
// adjust volume when unmuted
if (!muted)
{
bool adjusted = false;
qint32 v1 = this->m_channelCom1->getVolume();
qint32 v2 = this->m_channelCom2->getVolume();
if (this->m_channelCom1->getVolume() < MinUnmuteVolume) { v1 = MinUnmuteVolume; adjusted = true; }
if (this->m_channelCom2->getVolume() < MinUnmuteVolume) { v2 = MinUnmuteVolume; adjusted = true; }
if (adjusted) { this->setVolumes(v1, v2); }
}
// signal
emit changedMute(muted);
}
@@ -385,6 +417,54 @@ namespace BlackCore
m_voice->enableAudioLoopback(enable);
}
bool CContextAudio::parseCommandLine(const QString &commandLine)
{
static CSimpleCommandParser parser(
{
".vol", ".volume", // all volumes
".vol1", ".volume1", // COM1 volume
".vol2", ".volume2", // COM2 volume
".mute", // mute
".unmute" // unmute
});
if (commandLine.isEmpty()) return false;
parser.parse(commandLine);
if (!parser.isKnownCommand()) return false;
if (parser.matchesCommand(".mute"))
{
this->setMute(true);
return true;
}
else if (parser.matchesCommand(".unmute"))
{
this->setMute(false);
return true;
}
else if (parser.commandStartsWith("vol") && parser.countParts() > 1)
{
qint32 v = parser.toInt(1);
if (v >= 0 && v <= 100)
{
qint32 v1 = this->m_channelCom1->getVolume();
qint32 v2 = this->m_channelCom2->getVolume();
if (parser.commandEndsWith("1"))
{
this->setVolumes(v, v2);
}
else if (parser.commandEndsWith("2"))
{
this->setVolumes(v1, v);
}
else
{
this->setVolumes(v, v);
}
}
}
return false;
}
/*
* Connection status changed
*/

View File

@@ -118,6 +118,19 @@ namespace BlackCore
//! \copydoc IContextAudio::enableAudioLoopback()
virtual void enableAudioLoopback(bool enable = true) override;
//! \addtogroup commandline
//! @{
//! <pre>
//! .mute mute CContextAudio
//! .unmute unmute CContextAudio
//! .vol .volume volume 0..100 set volume CContextAudio
//! .vol1 .volume1 volume 0..100 set volume COM1 CContextAudio
//! .vol2 .volume2 volume 0..100 set volume COM2 CContextAudio
//! </pre>
//! @}
//! \copydoc IContextAudio::parseCommandLine
virtual bool parseCommandLine(const QString &commandLine) override;
protected:
//! Constructor
CContextAudio(CRuntimeConfig::ContextMode mode, CRuntime *runtime);
@@ -144,6 +157,9 @@ namespace BlackCore
void ps_initNotificationSounds();
private:
const qint32 MinUnmuteVolume = 20; //!< minimum volume when unmuted
const qint32 VoiceRoomEnabledVolume = 95; //!< voice room volume when enabled
//! Connection in transition
bool inTransitionState() const;
@@ -156,6 +172,6 @@ namespace BlackCore
QPointer<IVoiceChannel> m_channelCom1;
QPointer<IVoiceChannel> m_channelCom2;
};
}
} // namespace
#endif // guard

View File

@@ -39,7 +39,13 @@ namespace BlackCore
"changedVoiceRooms", this, SIGNAL(changedVoiceRooms(BlackMisc::Audio::CVoiceRoomList, bool)));
Q_ASSERT(s);
s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(),
"changedAudioVolumes", this, SIGNAL(changedAudioVolumes(QList<qint32>)));
"changedAudioVolumes", this, SIGNAL(changedAudioVolumes(qint32, qint32)));
Q_ASSERT(s);
s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(),
"changedAudioDevices", this, SIGNAL(changedAudioDevices(BlackMisc::Audio::CAudioDeviceList)));
Q_ASSERT(s);
s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(),
"changedSelectedAudioDevices", this, SIGNAL(changedSelectedAudioDevices(BlackMisc::Audio::CAudioDeviceList)));
Q_ASSERT(s);
s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(),
"changedMute", this, SIGNAL(changedMute(bool)));
@@ -239,4 +245,12 @@ namespace BlackCore
return this->m_dBusInterface->callDBus(QLatin1Literal("enableAudioLoopback"), enable);
}
/*
* Parse command line
*/
bool CContextAudioProxy::parseCommandLine(const QString &commandLine)
{
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("parseCommandLine"), commandLine);
}
} // namespace

View File

@@ -122,6 +122,10 @@ namespace BlackCore
//! \copydoc IContextAudio::enableAudioLoopback()
virtual void enableAudioLoopback(bool enable = true) override;
//! \copydoc IContextOwnAircraft::parseCommandLine
virtual bool parseCommandLine(const QString &commandLine) override;
};
}