Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 7cd16db3 authored by Nicolas Fella's avatar Nicolas Fella

Use unpretty channel name in speakertest

Summary:
The speaker test did not work when channel names were translated, e.g. "Front Left" => "Vorne Links" because the comparison failed. Using pa_channel_position_to_string instead of pa_channel_position_to_pretty_string hopefully
works better.

Reviewers: drosca, broulik

Reviewed By: broulik

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D14362
parent 88e2ffb7
......@@ -147,8 +147,8 @@ ScrollView {
Button{
text: i18n("Front Left")
anchors.centerIn: parent
visible: sinks.pulseObject ? sinks.pulseObject.channels.indexOf("Front Left") > -1 : false
onClicked: sinks.pulseObject.testChannel("Front Left")
visible: sinks.pulseObject ? sinks.pulseObject.rawChannels.indexOf("front-left") > -1 : false
onClicked: sinks.pulseObject.testChannel("front-left")
}
}
Item {
......@@ -158,8 +158,8 @@ ScrollView {
Button{
text: i18n("Front Center")
anchors.centerIn: parent
visible: sinks.pulseObject ? sinks.pulseObject.channels.indexOf("Front Center") > -1 : false
onClicked: sinks.pulseObject.testChannel("Front Center")
visible: sinks.pulseObject ? sinks.pulseObject.rawChannels.indexOf("front-center") > -1 : false
onClicked: sinks.pulseObject.testChannel("front-center")
}
}
Item {
......@@ -169,8 +169,8 @@ ScrollView {
Button{
text: i18n("Front Right")
anchors.centerIn: parent
visible: sinks.pulseObject ? sinks.pulseObject.channels.indexOf("Front Right") > -1 : false
onClicked: sinks.pulseObject.testChannel("Front Right")
visible: sinks.pulseObject ? sinks.pulseObject.rawChannels.indexOf("front-right") > -1 : false
onClicked: sinks.pulseObject.testChannel("front-right")
}
}
Item {
......@@ -180,8 +180,8 @@ ScrollView {
Button{
text: i18n("Side Left")
anchors.centerIn: parent
visible: sinks.pulseObject ? sinks.pulseObject.channels.indexOf("Side Left") > -1 : false
onClicked: sinks.pulseObject.testChannel("Side Left")
visible: sinks.pulseObject ? sinks.pulseObject.rawChannels.indexOf("side-left") > -1 : false
onClicked: sinks.pulseObject.testChannel("side-left")
}
}
......@@ -206,8 +206,8 @@ ScrollView {
Button{
text: i18n("Side Right")
anchors.centerIn: parent
visible: sinks.pulseObject ? sinks.pulseObject.channels.indexOf("Side Right") > -1 : false
onClicked: sinks.pulseObject.testChannel("Side Right")
visible: sinks.pulseObject ? sinks.pulseObject.rawChannels.indexOf("side-right") > -1 : false
onClicked: sinks.pulseObject.testChannel("side-right")
}
}
Item {
......@@ -216,8 +216,8 @@ ScrollView {
Button{
text: i18n("Rear Left")
anchors.centerIn: parent
visible: sinks.pulseObject ? sinks.pulseObject.channels.indexOf("Rear Left") > -1 : false
onClicked: sinks.pulseObject.testChannel("Rear Left")
visible: sinks.pulseObject ? sinks.pulseObject.rawChannels.indexOf("rear-left") > -1 : false
onClicked: sinks.pulseObject.testChannel("rear-left")
}
}
Item {
......@@ -226,8 +226,8 @@ ScrollView {
Button{
text: i18n("Subwoofer")
anchors.centerIn: parent
visible: sinks.pulseObject ? sinks.pulseObject.channels.indexOf("Subwoofer") > -1 : false
onClicked: sinks.pulseObject.testChannel("Subwoofer")
visible: sinks.pulseObject ? sinks.pulseObject.rawChannels.indexOf("lfe") > -1 : false
onClicked: sinks.pulseObject.testChannel("subwoofer")
}
}
Item {
......@@ -236,8 +236,8 @@ ScrollView {
Button{
text: i18n("Rear Right")
anchors.centerIn: parent
visible: sinks.pulseObject ? sinks.pulseObject.channels.indexOf("Rear Right") > -1 : false
onClicked: sinks.pulseObject.testChannel("Rear Right")
visible: sinks.pulseObject ? sinks.pulseObject.rawChannels.indexOf("rear-right") > -1 : false
onClicked: sinks.pulseObject.testChannel("rear-right")
}
}
}
......
......@@ -82,53 +82,6 @@ void Sink::setDefault(bool enable)
}
}
pa_channel_position_t Sink::channelNameToPosition(const QString &name)
{
if (name == QLatin1String("Front Left")) {
return PA_CHANNEL_POSITION_FRONT_LEFT;
} else if (name == QLatin1String("Front Center")) {
return PA_CHANNEL_POSITION_FRONT_CENTER;
} else if (name == QLatin1String("Front Right")) {
return PA_CHANNEL_POSITION_FRONT_RIGHT;
} else if (name == QLatin1String("Side Left")) {
return PA_CHANNEL_POSITION_SIDE_LEFT;
} else if (name == QLatin1String("Side Right")) {
return PA_CHANNEL_POSITION_SIDE_RIGHT;
} else if (name == QLatin1String("Rear Left")) {
return PA_CHANNEL_POSITION_REAR_LEFT;
} else if (name == QLatin1String("Rear Right")) {
return PA_CHANNEL_POSITION_REAR_RIGHT;
} else if (name == QLatin1String("Subwoofer")) {
return PA_CHANNEL_POSITION_SUBWOOFER;
}
return PA_CHANNEL_POSITION_MONO;
}
QString Sink::positionToChannelName(pa_channel_position_t position)
{
switch (position) {
case PA_CHANNEL_POSITION_FRONT_LEFT:
return QStringLiteral("Front Left");
case PA_CHANNEL_POSITION_FRONT_RIGHT:
return QStringLiteral("Front Right");
case PA_CHANNEL_POSITION_FRONT_CENTER:
return QStringLiteral("Front Center");
case PA_CHANNEL_POSITION_SIDE_LEFT:
return QStringLiteral("Side Left");
case PA_CHANNEL_POSITION_SIDE_RIGHT:
return QStringLiteral("Side Right");
case PA_CHANNEL_POSITION_REAR_LEFT:
return QStringLiteral("Rear Left");
case PA_CHANNEL_POSITION_REAR_RIGHT:
return QStringLiteral("Rear Right");
case PA_CHANNEL_POSITION_SUBWOOFER:
return QStringLiteral("Subwoofer");
default:
return QStringLiteral("Mono");
}
}
void Sink::testChannel(const QString &name)
{
auto context = CanberraContext::instance()->canberra();
......@@ -139,13 +92,13 @@ void Sink::testChannel(const QString &name)
snprintf(dev, sizeof(dev), "%lu", (unsigned long) m_index);
ca_context_change_device(context, dev);
QString sound_name = QStringLiteral("audio-channel-") + positionAsString(channelNameToPosition(name));
QString sound_name = QStringLiteral("audio-channel-") + name;
ca_proplist *proplist;
ca_proplist_create(&proplist);
ca_proplist_sets(proplist, CA_PROP_MEDIA_ROLE, "test");
ca_proplist_sets(proplist, CA_PROP_MEDIA_NAME, name.toLatin1().constData());
ca_proplist_sets(proplist, CA_PROP_CANBERRA_FORCE_CHANNEL, positionAsString(channelNameToPosition(name)).toLatin1().data());
ca_proplist_sets(proplist, CA_PROP_CANBERRA_FORCE_CHANNEL, name.toLatin1().data());
ca_proplist_sets(proplist, CA_PROP_CANBERRA_ENABLE, "1");
ca_proplist_sets(proplist, CA_PROP_EVENT_ID, sound_name.toLatin1().data());
......@@ -163,36 +116,4 @@ void Sink::testChannel(const QString &name)
ca_proplist_destroy(proplist);
}
QString Sink::positionAsString(pa_channel_position_t pos)
{
switch (pos) {
case PA_CHANNEL_POSITION_FRONT_LEFT:
return QStringLiteral("front-left");
case PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER:
return QStringLiteral("front-left-of-center");
case PA_CHANNEL_POSITION_FRONT_CENTER:
return QStringLiteral("front-center");
case PA_CHANNEL_POSITION_MONO:
return QStringLiteral("mono");
case PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER:
return QStringLiteral("front-right-of-center");
case PA_CHANNEL_POSITION_FRONT_RIGHT:
return QStringLiteral("front-right");
case PA_CHANNEL_POSITION_SIDE_LEFT:
return QStringLiteral("side-left");
case PA_CHANNEL_POSITION_SIDE_RIGHT:
return QStringLiteral("side-right");
case PA_CHANNEL_POSITION_REAR_LEFT:
return QStringLiteral("rear-left");
case PA_CHANNEL_POSITION_REAR_CENTER:
return QStringLiteral("rear-center");
case PA_CHANNEL_POSITION_REAR_RIGHT:
return QStringLiteral("rear-right");
case PA_CHANNEL_POSITION_SUBWOOFER:
return QStringLiteral("subwoofer");
default:
break;
}
return QStringLiteral("invalid");
}
} // QPulseAudio
......@@ -46,12 +46,6 @@ public:
public Q_SLOTS:
void testChannel(const QString &name);
private:
pa_channel_position_t channelNameToPosition(const QString &name);
QString positionToChannelName(pa_channel_position_t position);
QString positionAsString(pa_channel_position_t pos);
};
} // QPulseAudio
......
......@@ -66,6 +66,11 @@ QStringList VolumeObject::channels() const
return m_channels;
}
QStringList VolumeObject::rawChannels() const
{
return m_rawChannels;
}
QList<qreal> VolumeObject::channelVolumes() const
{
QList<qreal> ret;
......
......@@ -36,6 +36,7 @@ class VolumeObject : public PulseObject
Q_PROPERTY(bool hasVolume READ hasVolume NOTIFY hasVolumeChanged)
Q_PROPERTY(bool volumeWritable READ isVolumeWritable NOTIFY isVolumeWritableChanged)
Q_PROPERTY(QStringList channels READ channels NOTIFY channelsChanged)
Q_PROPERTY(QStringList rawChannels READ rawChannels NOTIFY rawChannelsChanged)
Q_PROPERTY(QList<qreal> channelVolumes READ channelVolumes NOTIFY channelVolumesChanged)
public:
explicit VolumeObject(QObject *parent);
......@@ -63,6 +64,16 @@ public:
m_channels = infoChannels;
Q_EMIT channelsChanged();
}
QStringList infoRawChannels;
infoRawChannels.reserve(info->channel_map.channels);
for (int i = 0; i < info->channel_map.channels; ++i) {
infoRawChannels << QString::fromUtf8(pa_channel_position_to_string(info->channel_map.map[i]));
}
if (m_rawChannels != infoRawChannels) {
m_rawChannels = infoRawChannels;
Q_EMIT rawChannelsChanged();
}
}
qint64 volume() const;
......@@ -75,6 +86,7 @@ public:
bool isVolumeWritable() const;
QStringList channels() const;
QStringList rawChannels() const;
QList<qreal> channelVolumes() const;
Q_INVOKABLE virtual void setChannelVolume(int channel, qint64 volume) = 0;
......@@ -84,6 +96,7 @@ Q_SIGNALS:
void hasVolumeChanged();
void isVolumeWritableChanged();
void channelsChanged();
void rawChannelsChanged();
void channelVolumesChanged();
protected:
......@@ -94,6 +107,7 @@ protected:
bool m_hasVolume;
bool m_volumeWritable;
QStringList m_channels;
QStringList m_rawChannels;
};
} // QPulseAudio
......
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