fix event sound generation for volume changes

This commit is contained in:
Lennart Poettering 2009-08-27 05:41:11 +02:00
parent 5143fa8dae
commit 8a11d0f781
9 changed files with 64 additions and 70 deletions

View File

@ -39,7 +39,7 @@ AC_PROG_LN_S
AC_TYPE_SIGNAL
AC_HEADER_STDC
PKG_CHECK_MODULES(GUILIBS, [ gtkmm-2.4 libglademm-2.4 sigc++-2.0 libcanberra-gtk >= 0.11 ])
PKG_CHECK_MODULES(GUILIBS, [ gtkmm-2.4 libglademm-2.4 sigc++-2.0 libcanberra-gtk >= 0.16 ])
AC_SUBST(GUILIBS_CFLAGS)
AC_SUBST(GUILIBS_LIBS)

View File

@ -88,23 +88,6 @@ void ChannelWidget::onVolumeScaleValueChanged() {
pa_volume_t volume = (pa_volume_t) ((volumeScale->get_value() * PA_VOLUME_NORM) / 100);
minimalStreamWidget->updateChannelVolume(channel, volume);
if (beepDevice != "") {
ca_context_change_device(ca_gtk_context_get(), beepDevice.c_str());
ca_context_cancel(ca_gtk_context_get(), 2);
ca_gtk_play_for_widget(GTK_WIDGET(volumeScale->gobj()),
2,
CA_PROP_EVENT_DESCRIPTION, _("Volume Control Feedback Sound"),
CA_PROP_EVENT_ID, "audio-volume-change",
CA_PROP_CANBERRA_CACHE_CONTROL, "permanent",
CA_PROP_CANBERRA_VOLUME, "0",
CA_PROP_CANBERRA_ENABLE, "1",
NULL);
ca_context_change_device(ca_gtk_context_get(), NULL);
}
}
void ChannelWidget::set_sensitive(bool enabled) {

View File

@ -23,8 +23,6 @@
#include "pavucontrol.h"
#include <canberra-gtk.h>
class MinimalStreamWidget;
class ChannelWidget : public Gtk::EventBox {
@ -46,8 +44,6 @@ public:
bool can_decibel;
bool volumeScaleEnabled;
Glib::ustring beepDevice;
virtual void set_sensitive(bool enabled);
virtual void setBaseVolume(pa_volume_t);
virtual void setSteps(unsigned n);

View File

@ -42,7 +42,7 @@ DeviceWidget::DeviceWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Gl
portList->set_model(treeModel);
portList->pack_start(portModel.desc);
portList->signal_changed().connect( sigc::mem_fun(*this, &DeviceWidget::onPortChange));
portList->signal_changed().connect(sigc::mem_fun(*this, &DeviceWidget::onPortChange));
for (unsigned i = 0; i < PA_CHANNELS_MAX; i++)
channelWidgets[i] = NULL;
@ -53,7 +53,6 @@ void DeviceWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
for (int i = 0; i < m.channels; i++) {
ChannelWidget *cw = channelWidgets[i] = ChannelWidget::create();
cw->beepDevice = beepDevice;
cw->channel = i;
cw->can_decibel = can_decibel;
cw->minimalStreamWidget = this;
@ -82,10 +81,9 @@ void DeviceWidget::updateChannelVolume(int channel, pa_volume_t v) {
g_assert(channel < volume.channels);
n = volume;
if (lockToggleButton->get_active()) {
for (int i = 0; i < n.channels; i++)
n.values[i] = v;
} else
if (lockToggleButton->get_active())
pa_cvolume_set(&n, n.channels, v);
else
n.values[channel] = v;
setVolume(n, true);
@ -131,25 +129,25 @@ void DeviceWidget::setSteps(unsigned n) {
}
void DeviceWidget::prepareMenu() {
int idx = 0;
int active_idx = -1;
int idx = 0;
int active_idx = -1;
treeModel->clear();
/* Fill the ComboBox's Tree Model */
for (uint32_t i = 0; i < ports.size(); ++i) {
Gtk::TreeModel::Row row = *(treeModel->append());
row[portModel.name] = ports[i].first;
row[portModel.desc] = ports[i].second;
if (ports[i].first == activePort)
active_idx = idx;
idx++;
}
treeModel->clear();
/* Fill the ComboBox's Tree Model */
for (uint32_t i = 0; i < ports.size(); ++i) {
Gtk::TreeModel::Row row = *(treeModel->append());
row[portModel.name] = ports[i].first;
row[portModel.desc] = ports[i].second;
if (ports[i].first == activePort)
active_idx = idx;
idx++;
}
if (active_idx >= 0)
portList->set_active(active_idx);
if (active_idx >= 0)
portList->set_active(active_idx);
if (ports.size() > 0)
portSelect->show();
else
portSelect->hide();
if (ports.size() > 0)
portSelect->show();
else
portSelect->hide();
}

View File

@ -41,8 +41,6 @@ public:
bool volumeMeterEnabled;
void enableVolumeMeter();
void updatePeak(double v);
Glib::ustring beepDevice;
};
#endif

View File

@ -22,11 +22,13 @@
#include <config.h>
#endif
#include "pavucontrol.h"
#include <pulse/pulseaudio.h>
#include <pulse/glib-mainloop.h>
#include <pulse/ext-stream-restore.h>
#include <canberra-gtk.h>
#include "pavucontrol.h"
#include "i18n.h"
#include "minimalstreamwidget.h"
#include "channelwidget.h"

View File

@ -22,6 +22,8 @@
#include <config.h>
#endif
#include <canberra-gtk.h>
#include "sinkwidget.h"
#include "i18n.h"
@ -39,6 +41,8 @@ SinkWidget* SinkWidget::create() {
void SinkWidget::executeVolumeUpdate() {
pa_operation* o;
char dev[64];
int playing = 0;
if (!(o = pa_context_set_sink_volume_by_index(get_context(), index, &volume, NULL, NULL))) {
show_error(_("pa_context_set_sink_volume_by_index() failed"));
@ -46,6 +50,23 @@ void SinkWidget::executeVolumeUpdate() {
}
pa_operation_unref(o);
ca_context_playing(ca_gtk_context_get(), 2, &playing);
if (playing)
return;
snprintf(dev, sizeof(dev), "%lu", (unsigned long) index);
ca_context_change_device(ca_gtk_context_get(), dev);
ca_gtk_play_for_widget(GTK_WIDGET(gobj()),
2,
CA_PROP_EVENT_DESCRIPTION, _("Volume Control Feedback Sound"),
CA_PROP_EVENT_ID, "audio-volume-change",
CA_PROP_CANBERRA_CACHE_CONTROL, "permanent",
CA_PROP_CANBERRA_ENABLE, "1",
NULL);
ca_context_change_device(ca_gtk_context_get(), NULL);
}
void SinkWidget::onMuteToggleButton() {
@ -77,26 +98,24 @@ void SinkWidget::onDefaultToggleButton() {
}
void SinkWidget::onPortChange() {
Gtk::TreeModel::iterator iter;
Gtk::TreeModel::iterator iter;
if (updating)
return;
iter = portList->get_active();
if (iter)
{
Gtk::TreeModel::Row row = *iter;
if (row)
{
pa_operation* o;
Glib::ustring port = row[portModel.name];
if (!(o = pa_context_set_sink_port_by_index(get_context(), index, port.c_str(), NULL, NULL))) {
show_error(_("pa_context_set_sink_port_by_index() failed"));
if (updating)
return;
}
pa_operation_unref(o);
iter = portList->get_active();
if (iter) {
Gtk::TreeModel::Row row = *iter;
if (row) {
pa_operation* o;
Glib::ustring port = row[portModel.name];
if (!(o = pa_context_set_sink_port_by_index(get_context(), index, port.c_str(), NULL, NULL))) {
show_error(_("pa_context_set_sink_port_by_index() failed"));
return;
}
pa_operation_unref(o);
}
}
}
}

View File

@ -69,7 +69,6 @@ void StreamWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
for (int i = 0; i < m.channels; i++) {
ChannelWidget *cw = channelWidgets[i] = ChannelWidget::create();
cw->beepDevice = beepDevice;
cw->channel = i;
cw->can_decibel = can_decibel;
cw->minimalStreamWidget = this;

View File

@ -62,7 +62,6 @@ protected:
Gtk::Menu contextMenu;
Gtk::MenuItem terminate;
};
#endif