Skip to content
This repository has been archived by the owner on Dec 17, 2017. It is now read-only.

Commit

Permalink
Merge pull request #418 from nebulon1234/master
Browse files Browse the repository at this point in the history
Use Alsa and PulseAudio when available
  • Loading branch information
pvanek committed Sep 9, 2012
2 parents e4b699b + 218f2ea commit e7960d5
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 49 deletions.
2 changes: 2 additions & 0 deletions razorqt-panel/plugin-volume/alsaengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class AlsaEngine : public AudioEngine
AlsaEngine(QObject *parent = 0);
static AlsaEngine *instance();

virtual const QString backendName() const { return QLatin1String("Alsa"); }

int volumeMax(AudioDevice *device) const;
AlsaDevice *getDeviceByAlsaElem(snd_mixer_elem_t *elem) const;

Expand Down
1 change: 1 addition & 0 deletions razorqt-panel/plugin-volume/audioengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class AudioEngine : public QObject

const QList<AudioDevice *> &sinks() const { return m_sinks; }
virtual int volumeMax(AudioDevice *device) const = 0;
virtual const QString backendName() const = 0;

public slots:
virtual void commitDeviceVolume(AudioDevice *device) = 0;
Expand Down
2 changes: 2 additions & 0 deletions razorqt-panel/plugin-volume/pulseaudioengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class PulseAudioEngine : public AudioEngine
PulseAudioEngine(QObject *parent = 0);
~PulseAudioEngine();

virtual const QString backendName() const { return QLatin1String("PulseAudio"); }

int volumeMax(AudioDevice */*device*/) const { return m_maximumVolume; }

void requestSinkInfoUpdate(AudioDevice *device);
Expand Down
19 changes: 0 additions & 19 deletions razorqt-panel/plugin-volume/razortranslate.h

This file was deleted.

58 changes: 43 additions & 15 deletions razorqt-panel/plugin-volume/razorvolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ EXPORT_RAZOR_PANEL_PLUGIN_CPP(RazorVolume)

RazorVolume::RazorVolume(const RazorPanelPluginStartInfo* startInfo, QWidget* parent):
RazorPanelPlugin(startInfo, parent),
m_engine(0),
m_defaultSinkIndex(0),
m_defaultSink(0)
{
Expand Down Expand Up @@ -83,13 +84,25 @@ RazorVolume::RazorVolume(const RazorPanelPluginStartInfo* startInfo, QWidget* pa
connect(m_keyVolumeDown, SIGNAL(activated()), this, SLOT(handleShortcutVolumeDown()));
connect(m_keyMuteToggle, SIGNAL(activated()), this, SLOT(handleShortcutVolumeMute()));

#ifdef USE_PULSEAUDIO
m_engine = new PulseAudioEngine(this);
#else
m_engine = new AlsaEngine(this);
#endif
settingsChanged();
}

void RazorVolume::setAudioEngine(AudioEngine *engine)
{
if (m_engine) {
if (m_engine->backendName() == engine->backendName())
return;

m_volumeButton->volumePopup()->setDevice(0);

disconnect(m_engine, 0, 0, 0);
delete m_engine;
m_engine = 0;
}

m_engine = engine;
connect(m_engine, SIGNAL(sinkListChanged()), this, SLOT(updateConfigurationSinkList()));

updateConfigurationSinkList();
}

Expand All @@ -102,26 +115,41 @@ void RazorVolume::showConfigureDialog()

void RazorVolume::settingsChanged()
{
m_defaultSinkIndex = settings().value(SETTINGS_DEVICE, SETTINGS_DEFAULT_DEVICE).toInt();

if (m_defaultSinkIndex < m_engine->sinks().count()
&& m_engine->sinks().at(m_defaultSinkIndex))
{
m_defaultSink = m_engine->sinks().at(m_defaultSinkIndex);
m_volumeButton->volumePopup()->setDevice(m_defaultSink);
#if defined(USE_PULSEAUDIO) && defined(USE_ALSA)
if (!m_engine || m_engine->backendName() != settings().value(SETTINGS_AUDIO_ENGINE, SETTINGS_DEFAULT_AUDIO_ENGINE).toString()) {
if (settings().value(SETTINGS_AUDIO_ENGINE, SETTINGS_DEFAULT_AUDIO_ENGINE).toString() == "PulseAudio")
setAudioEngine(new PulseAudioEngine(this));
else
setAudioEngine(new AlsaEngine(this));
}
#elif defined(USE_PULSEAUDIO)
if (!m_engine)
setAudioEngine(new PulseAudioEngine(this));
#elif defined(USE_ALSA)
if (!m_engine)
setAudioEngine(new AlsaEngine(this));
#endif

m_volumeButton->setShowOnClicked(settings().value(SETTINGS_SHOW_ON_LEFTCLICK, SETTINGS_DEFAULT_SHOW_ON_LEFTCLICK).toBool());
m_volumeButton->setMuteOnMiddleClick(settings().value(SETTINGS_MUTE_ON_MIDDLECLICK, SETTINGS_DEFAULT_MUTE_ON_MIDDLECLICK).toBool());
m_volumeButton->setMixerCommand(settings().value(SETTINGS_MIXER_COMMAND, SETTINGS_DEFAULT_MIXER_COMMAND).toString());
m_volumeButton->volumePopup()->setSliderStep(settings().value(SETTINGS_STEP, SETTINGS_DEFAULT_STEP).toInt());
m_engine->setIgnoreMaxVolume(settings().value(SETTINGS_IGNORE_MAX_VOLUME, SETTINGS_DEFAULT_IGNORE_MAX_VOLUME).toBool());

m_defaultSinkIndex = settings().value(SETTINGS_DEVICE, SETTINGS_DEFAULT_DEVICE).toInt();
if (m_engine && m_engine->sinks().count() > 0) {
m_defaultSinkIndex = qBound(0, m_defaultSinkIndex, m_engine->sinks().count()-1);

m_defaultSink = m_engine->sinks().at(m_defaultSinkIndex);
m_volumeButton->volumePopup()->setDevice(m_defaultSink);

m_engine->setIgnoreMaxVolume(settings().value(SETTINGS_IGNORE_MAX_VOLUME, SETTINGS_DEFAULT_IGNORE_MAX_VOLUME).toBool());
}
}

void RazorVolume::updateConfigurationSinkList()
{
m_configWindow->setSinkList(m_engine->sinks());
settingsChanged();
if (m_engine)
m_configWindow->setSinkList(m_engine->sinks());
}

void RazorVolume::handleShortcutVolumeUp()
Expand Down
2 changes: 2 additions & 0 deletions razorqt-panel/plugin-volume/razorvolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class RazorVolume : public RazorPanelPlugin

virtual RazorPanelPlugin::Flags flags() const { return PreferRightAlignment | HaveConfigDialog ; }

void setAudioEngine(AudioEngine *engine);

protected slots:
virtual void showConfigureDialog();
virtual void settingsChanged();
Expand Down
31 changes: 29 additions & 2 deletions razorqt-panel/plugin-volume/razorvolumeconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ RazorVolumeConfiguration::RazorVolumeConfiguration(QSettings &settings, QWidget
ui->setupUi(this);

loadSettings();
connect(ui->pulseAudioRadioButton, SIGNAL(toggled(bool)), this, SLOT(audioEngineChanged(bool)));
connect(ui->alsaRadioButton, SIGNAL(toggled(bool)), this, SLOT(audioEngineChanged(bool)));
connect(ui->devAddedCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(sinkSelectionChanged(int)));
connect(ui->buttons, SIGNAL(clicked(QAbstractButton*)), this, SLOT(dialogButtonsAction(QAbstractButton*)));
connect(ui->showOnClickCheckBox, SIGNAL(toggled(bool)), this, SLOT(showOnClickedChanged(bool)));
Expand All @@ -48,8 +50,12 @@ RazorVolumeConfiguration::RazorVolumeConfiguration(QSettings &settings, QWidget
connect(ui->stepSpinBox, SIGNAL(valueChanged(int)), this, SLOT(stepSpinBoxChanged(int)));
connect(ui->ignoreMaxVolumeCheckBox, SIGNAL(toggled(bool)), this, SLOT(ignoreMaxVolumeCheckBoxChanged(bool)));

#ifndef USE_PULSEAUDIO
ui->ignoreMaxVolumeCheckBox->setVisible(false);
#if defined(USE_PULSEAUDIO) && defined(USE_ALSA)
ui->pulseAudioRadioButton->setVisible(true);
ui->alsaRadioButton->setVisible(true);
#else
ui->pulseAudioRadioButton->setVisible(false);
ui->alsaRadioButton->setVisible(false);
#endif
}

Expand All @@ -60,11 +66,27 @@ RazorVolumeConfiguration::~RazorVolumeConfiguration()

void RazorVolumeConfiguration::setSinkList(const QList<AudioDevice *> sinks)
{
// preserve the current index, as we change the list
int tmp_index = settings().value(SETTINGS_DEVICE, SETTINGS_DEFAULT_DEVICE).toInt();

ui->devAddedCombo->clear();

foreach (const AudioDevice *dev, sinks) {
ui->devAddedCombo->addItem(dev->description(), dev->index());
}

ui->devAddedCombo->setCurrentIndex(tmp_index);
}

void RazorVolumeConfiguration::audioEngineChanged(bool checked)
{
if (!checked)
return;

if (ui->pulseAudioRadioButton->isChecked())
settings().setValue(SETTINGS_AUDIO_ENGINE, "PulseAudio");
else
settings().setValue(SETTINGS_AUDIO_ENGINE, "Alsa");
}

void RazorVolumeConfiguration::sinkSelectionChanged(int index)
Expand Down Expand Up @@ -99,6 +121,11 @@ void RazorVolumeConfiguration::ignoreMaxVolumeCheckBoxChanged(bool state)

void RazorVolumeConfiguration::loadSettings()
{
if (settings().value(SETTINGS_AUDIO_ENGINE, SETTINGS_DEFAULT_AUDIO_ENGINE).toString() == "PulseAudio")
ui->pulseAudioRadioButton->setChecked(true);
else
ui->alsaRadioButton->setChecked(true);

setComboboxIndexByData(ui->devAddedCombo, settings().value(SETTINGS_DEVICE, SETTINGS_DEFAULT_DEVICE), 1);
ui->showOnClickCheckBox->setChecked(settings().value(SETTINGS_SHOW_ON_LEFTCLICK, SETTINGS_DEFAULT_SHOW_ON_LEFTCLICK).toBool());
ui->muteOnMiddleClickCheckBox->setChecked(settings().value(SETTINGS_MUTE_ON_MIDDLECLICK, SETTINGS_DEFAULT_MUTE_ON_MIDDLECLICK).toBool());
Expand Down
4 changes: 4 additions & 0 deletions razorqt-panel/plugin-volume/razorvolumeconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@
#define SETTINGS_DEVICE "device"
#define SETTINGS_STEP "volumeAdjustStep"
#define SETTINGS_IGNORE_MAX_VOLUME "ignoreMaxVolume"
#define SETTINGS_AUDIO_ENGINE "audioEngine"

#define SETTINGS_DEFAULT_SHOW_ON_LEFTCLICK true
#define SETTINGS_DEFAULT_MUTE_ON_MIDDLECLICK true
#define SETTINGS_DEFAULT_DEVICE 0
#define SETTINGS_DEFAULT_STEP 3
#ifdef USE_PULSEAUDIO
#define SETTINGS_DEFAULT_MIXER_COMMAND "pavucontrol"
#define SETTINGS_DEFAULT_AUDIO_ENGINE "pulseaudio"
#else
#define SETTINGS_DEFAULT_MIXER_COMMAND "qasmixer"
#define SETTINGS_DEFAULT_AUDIO_ENGINE "alsa"
#endif
#define SETTINGS_DEFAULT_IGNORE_MAX_VOLUME false

Expand All @@ -66,6 +69,7 @@ class RazorVolumeConfiguration : public RazorPanelPluginConfigDialog

public slots:
void setSinkList(const QList<AudioDevice*> sinks);
void audioEngineChanged(bool checked);
void sinkSelectionChanged(int index);
void showOnClickedChanged(bool state);
void muteOnMiddleClickChanged(bool state);
Expand Down
20 changes: 19 additions & 1 deletion razorqt-panel/plugin-volume/razorvolumeconfiguration.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>363</width>
<height>297</height>
<height>355</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -20,6 +20,24 @@
<string>Device to control</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="alsaRadioButton">
<property name="text">
<string>Alsa</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="pulseAudioRadioButton">
<property name="text">
<string>PulseAudio</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QComboBox" name="devAddedCombo"/>
</item>
Expand Down
1 change: 0 additions & 1 deletion razorqt-panel/plugin-volume/volumebutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ VolumeButton::VolumeButton(RazorPanel *panel, QWidget* parent):
connect(m_volumePopup, SIGNAL(mouseEntered()), this, SLOT(popupHideTimerStop()));
connect(m_volumePopup, SIGNAL(mouseLeft()), this, SLOT(popupHideTimerStart()));

connect(m_volumePopup, SIGNAL(deviceChanged()), this, SLOT(handleDeviceChanged()));
connect(m_volumePopup, SIGNAL(launchMixer()), this, SLOT(handleMixerLaunch()));
connect(m_volumePopup, SIGNAL(stockIconChanged(QString)), this, SLOT(handleStockIconChanged(QString)));
}
Expand Down
20 changes: 9 additions & 11 deletions razorqt-panel/plugin-volume/volumepopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,20 @@ void VolumePopup::setDevice(AudioDevice *device)
return;

// disconnect old device
if (m_device) {
disconnect(m_device, SIGNAL(volumeChanged(int)), this, SLOT(handleDeviceVolumeChanged(int)));
disconnect(m_device, SIGNAL(muteChanged(bool)), this, SLOT(handleDeviceMuteChanged(bool)));
disconnect(m_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(handleSliderValueChanged(int)));
}
if (m_device)
disconnect(m_device);

m_device = device;
m_volumeSlider->setValue(m_device->volume());
m_muteToggleButton->setChecked(m_device->mute());

connect(m_device, SIGNAL(volumeChanged(int)), this, SLOT(handleDeviceVolumeChanged(int)));
connect(m_device, SIGNAL(muteChanged(bool)), this, SLOT(handleDeviceMuteChanged(bool)));
connect(m_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(handleSliderValueChanged(int)));
if (m_device) {
m_volumeSlider->setValue(m_device->volume());
m_muteToggleButton->setChecked(m_device->mute());

updateStockIcon();
connect(m_device, SIGNAL(volumeChanged(int)), this, SLOT(handleDeviceVolumeChanged(int)));
connect(m_device, SIGNAL(muteChanged(bool)), this, SLOT(handleDeviceMuteChanged(bool)));
}

updateStockIcon();
emit deviceChanged();
}

Expand Down

0 comments on commit e7960d5

Please sign in to comment.