Commit 8bcf9255 authored by Jonathan Marten's avatar Jonathan Marten
Browse files

Mixer_PULSE: Eliminate "use of old-style cast" warnings

Volume::ChannelMask changed to a QFlags to allow use of
standard operators without casting.
parent e20ad13f
......@@ -108,7 +108,7 @@ static void translateMasksAndMaps(devinfo& dev)
}
if (1 == dev.channel_map.channels && PA_CHANNEL_POSITION_MONO == dev.channel_map.map[0]) {
// We just use the left channel to represent this.
dev.chanMask = (Volume::ChannelMask)( dev.chanMask | Volume::MLEFT);
dev.chanMask |= Volume::MLEFT;
dev.chanIDs[0] = Volume::LEFT;
} else {
for (uint8_t i = 0; i < dev.channel_map.channels; ++i) {
......@@ -118,39 +118,39 @@ static void translateMasksAndMaps(devinfo& dev)
return;
case PA_CHANNEL_POSITION_FRONT_LEFT:
dev.chanMask = (Volume::ChannelMask)( dev.chanMask | Volume::MLEFT);
dev.chanMask |= Volume::MLEFT;
dev.chanIDs[i] = Volume::LEFT;
break;
case PA_CHANNEL_POSITION_FRONT_RIGHT:
dev.chanMask = (Volume::ChannelMask)( dev.chanMask | Volume::MRIGHT);
dev.chanMask |= Volume::MRIGHT;
dev.chanIDs[i] = Volume::RIGHT;
break;
case PA_CHANNEL_POSITION_FRONT_CENTER:
dev.chanMask = (Volume::ChannelMask)( dev.chanMask | Volume::MCENTER);
dev.chanMask |= Volume::MCENTER;
dev.chanIDs[i] = Volume::CENTER;
break;
case PA_CHANNEL_POSITION_REAR_CENTER:
dev.chanMask = (Volume::ChannelMask)( dev.chanMask | Volume::MREARCENTER);
dev.chanMask |= Volume::MREARCENTER;
dev.chanIDs[i] = Volume::REARCENTER;
break;
case PA_CHANNEL_POSITION_REAR_LEFT:
dev.chanMask = (Volume::ChannelMask)( dev.chanMask | Volume::MSURROUNDLEFT);
dev.chanMask |= Volume::MSURROUNDLEFT;
dev.chanIDs[i] = Volume::SURROUNDLEFT;
break;
case PA_CHANNEL_POSITION_REAR_RIGHT:
dev.chanMask = (Volume::ChannelMask)( dev.chanMask | Volume::MSURROUNDRIGHT);
dev.chanMask |= Volume::MSURROUNDRIGHT;
dev.chanIDs[i] = Volume::SURROUNDRIGHT;
break;
case PA_CHANNEL_POSITION_LFE:
dev.chanMask = (Volume::ChannelMask)( dev.chanMask | Volume::MWOOFER);
dev.chanMask |= Volume::MWOOFER;
dev.chanIDs[i] = Volume::WOOFER;
break;
case PA_CHANNEL_POSITION_SIDE_LEFT:
dev.chanMask = (Volume::ChannelMask)( dev.chanMask | Volume::MREARSIDELEFT);
dev.chanMask |= Volume::MREARSIDELEFT;
dev.chanIDs[i] = Volume::REARSIDELEFT;
break;
case PA_CHANNEL_POSITION_SIDE_RIGHT:
dev.chanMask = (Volume::ChannelMask)( dev.chanMask | Volume::MREARSIDERIGHT);
dev.chanMask |= Volume::MREARSIDERIGHT;
dev.chanIDs[i] = Volume::REARSIDERIGHT;
break;
default:
......@@ -646,8 +646,8 @@ static void context_state_callback(pa_context *c, void *)
if (s_context == c) {
pa_context_set_subscribe_callback(c, subscribe_cb, NULL);
op = pa_context_subscribe(c, (pa_subscription_mask_t)
(PA_SUBSCRIPTION_MASK_SINK|
op = pa_context_subscribe(c, static_cast<pa_subscription_mask_t>(
PA_SUBSCRIPTION_MASK_SINK|
PA_SUBSCRIPTION_MASK_SOURCE|
PA_SUBSCRIPTION_MASK_CLIENT|
PA_SUBSCRIPTION_MASK_SINK_INPUT|
......@@ -715,7 +715,7 @@ static void setVolumeFromPulse(Volume& volume, const devinfo& dev)
for (iter = dev.chanIDs.begin(); iter != dev.chanIDs.end(); ++iter)
{
//qCDebug(KMIX_LOG) << "Setting volume for channel " << iter.value() << " to " << (long)dev.volume.values[iter.key()] << " (" << ((100*(long)dev.volume.values[iter.key()]) / PA_VOLUME_NORM) << "%)";
volume.setVolume(iter.value(), (long)dev.volume.values[iter.key()]);
volume.setVolume(iter.value(), static_cast<long>(dev.volume.values[iter.key()]));
}
}
......@@ -726,7 +726,7 @@ static pa_cvolume genVolumeForPulse(const devinfo& dev, Volume& volume)
chanIDMap::const_iterator iter;
for (iter = dev.chanIDs.begin(); iter != dev.chanIDs.end(); ++iter)
{
cvol.values[iter.key()] = (uint32_t)volume.getVolume(iter.value());
cvol.values[iter.key()] = static_cast<uint32_t>(volume.getVolume(iter.value()));
//qCDebug(KMIX_LOG) << "Setting volume for channel " << iter.value() << " to " << cvol.values[iter.key()] << " (" << ((100*cvol.values[iter.key()]) / PA_VOLUME_NORM) << "%)";
}
return cvol;
......@@ -753,9 +753,8 @@ static devmap* get_widget_map(int type, QString id = QString())
static devmap* get_widget_map(int type, int index)
{
if (PA_INVALID_INDEX == (uint32_t)index)
return get_widget_map(type, "restore:");
return get_widget_map(type);
if (static_cast<uint32_t>(index)==PA_INVALID_INDEX) return (get_widget_map(type, "restore:"));
return (get_widget_map(type));
}
void Mixer_PULSE::emitControlsReconfigured()
......@@ -1204,9 +1203,8 @@ case KMIXPA_PLAYBACK:
if (playing==0)
{
char devnum[64];
snprintf(devnum, sizeof(devnum), "%lu", (unsigned long) dev.index);
ca_context_change_device(s_ccontext, devnum);
const QByteArray devnum = QByteArray::number(dev.index);
ca_context_change_device(s_ccontext, devnum.constData());
// Ideally we'd use something like ca_gtk_play_for_widget()...
ca_context_play(
......
......@@ -40,7 +40,7 @@ static Volume::ChannelMask channelMask[] =
Volume::MREARCENTER
};
QString Volume::channelNameReadable(ChannelID id)
QString Volume::channelNameReadable(Volume::ChannelID id)
{
switch (id)
{
......@@ -59,7 +59,7 @@ default: qCWarning(KMIX_LOG) << "called for unknown ID" << id;
}
QString Volume::channelNameForPersistence(ChannelID id)
QString Volume::channelNameForPersistence(Volume::ChannelID id)
{
switch (id)
{
......@@ -110,13 +110,13 @@ VolumeChannel::VolumeChannel(Volume::ChannelID c)
Volume::Volume(long maxVolume, long minVolume, bool hasSwitch, bool isCapture )
{
init(static_cast<ChannelMask>(0), maxVolume, minVolume, hasSwitch, isCapture );
init(Volume::MNONE, maxVolume, minVolume, hasSwitch, isCapture );
}
/**
* @deprecated
*/
void Volume::addVolumeChannels(ChannelMask chmask)
void Volume::addVolumeChannels(Volume::ChannelMask chmask)
{
for ( Volume::ChannelID chid=Volume::CHIDMIN; chid<= Volume::CHIDMAX; )
{
......@@ -139,7 +139,7 @@ void Volume::addVolumeChannel(VolumeChannel vc)
void Volume::init( ChannelMask chmask, long maxVolume, long minVolume, bool hasSwitch, bool isCapture)
void Volume::init( Volume::ChannelMask chmask, long maxVolume, long minVolume, bool hasSwitch, bool isCapture)
{
_chmask = chmask;
_maxVolume = maxVolume;
......@@ -218,7 +218,7 @@ void Volume::changeAllVolumes( long step )
* Sets the volume for the given Channel
* @ compatibility
*/
void Volume::setVolume( ChannelID chid, long vol)
void Volume::setVolume( Volume::ChannelID chid, long vol)
{
QMap<Volume::ChannelID, VolumeChannel>::iterator it = _volumesL.find(chid);
if ( it != _volumesL.end())
......@@ -235,7 +235,7 @@ void Volume::setVolume( ChannelID chid, long vol)
// {
// foreach (VolumeChannel vc, _volumesL )
// {
// ChannelID chid = vc.chid;
// Volume::ChannelID chid = vc.chid;
// v.getVolumes()[chid].volume = vc.volume;
// //v.getVolumes()[chid].unmutedVolume = vc.volume;
// }
......@@ -275,7 +275,7 @@ void Volume::setVolume( ChannelID chid, long vol)
/**
* Returns the volume of the given channel.
*/
long Volume::getVolume(ChannelID chid) const
long Volume::getVolume(Volume::ChannelID chid) const
{
return _volumesL.value(chid).volume;
}
......@@ -283,7 +283,7 @@ long Volume::getVolume(ChannelID chid) const
/**
* Returns the volume of the given channel. If this Volume is inactive (switched off), 0 is returned.
*/
long Volume::getVolumeForGUI(ChannelID chid) const
long Volume::getVolumeForGUI(Volume::ChannelID chid) const
{
if (! isSwitchActivated() )
return 0;
......@@ -291,7 +291,7 @@ long Volume::getVolumeForGUI(ChannelID chid) const
return _volumesL.value(chid).volume;
}
qreal Volume::getAvgVolume(ChannelMask chmask) const
qreal Volume::getAvgVolume(Volume::ChannelMask chmask) const
{
int avgVolumeCounter = 0;
long long sumOfActiveVolumes = 0;
......@@ -313,7 +313,7 @@ qreal Volume::getAvgVolume(ChannelMask chmask) const
}
int Volume::getAvgVolumePercent(ChannelMask chmask) const
int Volume::getAvgVolumePercent(Volume::ChannelMask chmask) const
{
qreal volume = getAvgVolume(chmask);
// min=-100, max=200 => volSpan = 301
......
......@@ -41,43 +41,60 @@ public:
// For example a 2.0 system just has MLEFT and MRIGHT.
// A 5.1 system adds MCENTER, MWOOFER, MSURROUNDLEFT and MSURROUNDRIGHT.
// A 7.1 system furthermore adds MREARLEFT and MREARRIGHT.
enum ChannelMask { MNONE = 0,
enum ChannelMaskBits
{
MNONE = 0x000,
MLEFT = 1, MRIGHT = 2, MCENTER = 4,
MMAIN = 3, MFRONT = 7,
MLEFT = 0x001,
MRIGHT = 0x002,
MCENTER = 0x004,
MMAIN = 0x003,
MFRONT = 0x007,
MWOOFER = 8,
MWOOFER = 0x008,
// SURROUND (4.0 or 4.1 or in higher - like 5.1)
MSURROUNDLEFT = 0x10, MSURROUNDRIGHT = 0x20,
// MSURROUND
MSURROUND = 0x30,
// SURROUND (4.0 or 4.1 or in higher - like 5.1)
MSURROUNDLEFT = 0x010,
MSURROUNDRIGHT = 0x020,
// all SURROUND
MSURROUND = 0x030,
// REARSIDE (Usually only in 7.1)
MREARSIDELEFT = 0x40, MREARSIDERIGHT = 0x80,
// REARCENTER (Usually only in 6.1)
MREARCENTER = 0x100,
// MREAR
MREAR = 0x1C0,
// REARSIDE (Usually only in 7.1)
MREARSIDELEFT = 0x040,
MREARSIDERIGHT = 0x080,
// REARCENTER (Usually only in 6.1)
MREARCENTER = 0x100,
// all REAR
MREAR = 0x1C0,
MALL=0xFFFF };
MALL = 0xFFF
};
Q_DECLARE_FLAGS(ChannelMask, ChannelMaskBits)
enum ChannelID
{
NOCHANNEL = -1,
CHIDMIN = 0,
enum ChannelID { NOCHANNEL =-1, CHIDMIN = 0,
LEFT = 0, RIGHT = 1, CENTER = 2,
LEFT = 0,
RIGHT = 1,
CENTER = 2,
WOOFER = 3,
WOOFER = 3,
SURROUNDLEFT = 4, SURROUNDRIGHT = 5,
SURROUNDLEFT = 4,
SURROUNDRIGHT = 5,
REARSIDELEFT = 6, REARSIDERIGHT = 7,
REARSIDELEFT = 6,
REARSIDERIGHT = 7,
REARCENTER = 8,
REARCENTER = 8,
CHIDMAX = 8 };
CHIDMAX = 8
};
static QString channelNameForPersistence(ChannelID id);
static QString channelNameReadable(ChannelID id);
static QString channelNameForPersistence(Volume::ChannelID id);
static QString channelNameReadable(Volume::ChannelID id);
enum VolumeType { PlaybackVT = 0 , CaptureVT = 1 };
......@@ -89,23 +106,23 @@ public:
Volume(long maxVolume, long minVolume, bool hasSwitch, bool isCapture );
void addVolumeChannel(VolumeChannel ch);
/// @Deprecated
void addVolumeChannels(ChannelMask chmask);
void addVolumeChannels(Volume::ChannelMask chmask);
// Set all volumes as given by vol
void setAllVolumes(long vol);
// Set all volumes to the ones given in vol
//void setVolume(const Volume &vol );
// Set volumes as specified by the channel mask
//void setVolume( const Volume &vol, ChannelMask chmask);
void setVolume( ChannelID chid, long volume);
//void setVolume( const Volume &vol, Volume::ChannelMask chmask);
void setVolume( Volume::ChannelID chid, long volume);
// Increase or decrease all volumes by step
void changeAllVolumes( long step );
long getVolume(ChannelID chid) const;
long getVolumeForGUI(ChannelID chid) const;
qreal getAvgVolume(ChannelMask chmask) const;
int getAvgVolumePercent(ChannelMask chmask) const;
long getVolume(Volume::ChannelID chid) const;
long getVolumeForGUI(Volume::ChannelID chid) const;
qreal getAvgVolume(Volume::ChannelMask chmask) const;
int getAvgVolumePercent(Volume::ChannelMask chmask) const;
//long operator[](int);
long maxVolume() const { return (_maxVolume); }
......@@ -167,7 +184,7 @@ private:
// constructor for dummy volumes
Volume();
void init( ChannelMask chmask, long maxVolume, long minVolume, bool hasSwitch, bool isCapture);
void init( Volume::ChannelMask chmask, long maxVolume, long minVolume, bool hasSwitch, bool isCapture);
long volrange( long vol );
......@@ -177,6 +194,8 @@ private:
bool _isCapture;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Volume::ChannelMask)
class KMIXCORE_EXPORT VolumeChannel
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment