beep when changing volume

This commit is contained in:
Lennart Poettering 2008-08-19 17:36:18 +02:00
parent 34e69af0a4
commit ecc9ad9b06
2 changed files with 54 additions and 7 deletions

View File

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

View File

@ -29,6 +29,8 @@
#include <libglademm.h> #include <libglademm.h>
#include <libintl.h> #include <libintl.h>
#include <canberra-gtk.h>
#include <pulse/pulseaudio.h> #include <pulse/pulseaudio.h>
#include <pulse/glib-mainloop.h> #include <pulse/glib-mainloop.h>
#include <pulse/ext-stream-restore.h> #include <pulse/ext-stream-restore.h>
@ -91,6 +93,8 @@ public:
bool can_decibel; bool can_decibel;
bool volumeScaleEnabled; bool volumeScaleEnabled;
Glib::ustring beepDevice;
virtual void set_sensitive(bool enabled); virtual void set_sensitive(bool enabled);
}; };
@ -118,6 +122,8 @@ public:
void enableVolumeMeter(); void enableVolumeMeter();
void updatePeak(double v); void updatePeak(double v);
Glib::ustring beepDevice;
protected: protected:
virtual bool on_button_press_event(GdkEventButton* event); virtual bool on_button_press_event(GdkEventButton* event);
}; };
@ -376,13 +382,15 @@ void ChannelWidget::setVolume(pa_volume_t volume) {
if (dB > PA_DECIBEL_MININFTY) { if (dB > PA_DECIBEL_MININFTY) {
snprintf(txt, sizeof(txt), "%0.2f dB", dB); snprintf(txt, sizeof(txt), "%0.2f dB", dB);
volumeLabel->set_text(txt); volumeLabel->set_tooltip_text(txt);
} else } else
volumeLabel->set_markup("-&#8734;dB"); volumeLabel->set_tooltip_markup("-&#8734;dB");
} else { volumeLabel->set_has_tooltip(TRUE);
} else
volumeLabel->set_has_tooltip(FALSE);
snprintf(txt, sizeof(txt), "%0.0f%%", v); snprintf(txt, sizeof(txt), "%0.0f%%", v);
volumeLabel->set_text(txt); volumeLabel->set_text(txt);
}
volumeScaleEnabled = false; volumeScaleEnabled = false;
volumeScale->set_value(v > 100 ? 100 : v); volumeScale->set_value(v > 100 ? 100 : v);
@ -399,6 +407,26 @@ void ChannelWidget::onVolumeScaleValueChanged() {
pa_volume_t volume = (pa_volume_t) ((volumeScale->get_value() * PA_VOLUME_NORM) / 100); pa_volume_t volume = (pa_volume_t) ((volumeScale->get_value() * PA_VOLUME_NORM) / 100);
streamWidget->updateChannelVolume(channel, volume); streamWidget->updateChannelVolume(channel, volume);
if (beepDevice != "") {
g_debug("blah: %s", beepDevice.c_str());
ca_context_change_device(ca_gtk_context_get(), beepDevice.c_str());
ca_context_cancel(ca_gtk_context_get(), 2);
int r = 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);
g_debug("%i = %s", r, ca_strerror(r));
ca_context_change_device(ca_gtk_context_get(), NULL);
}
} }
void ChannelWidget::set_sensitive(bool enabled) { void ChannelWidget::set_sensitive(bool enabled) {
@ -524,6 +552,7 @@ void StreamWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
for (int i = 0; i < m.channels; i++) { for (int i = 0; i < m.channels; i++) {
ChannelWidget *cw = channelWidgets[i] = ChannelWidget::create(); ChannelWidget *cw = channelWidgets[i] = ChannelWidget::create();
cw->beepDevice = beepDevice;
cw->channel = i; cw->channel = i;
cw->can_decibel = can_decibel; cw->can_decibel = can_decibel;
cw->streamWidget = this; cw->streamWidget = this;
@ -988,6 +1017,7 @@ void MainWindow::updateSink(const pa_sink_info &info) {
w = sinkWidgets[info.index]; w = sinkWidgets[info.index];
else { else {
sinkWidgets[info.index] = w = SinkWidget::create(); sinkWidgets[info.index] = w = SinkWidget::create();
w->beepDevice = info.name;
w->setChannelMap(info.channel_map, !!(info.flags & PA_SINK_DECIBEL_VOLUME)); w->setChannelMap(info.channel_map, !!(info.flags & PA_SINK_DECIBEL_VOLUME));
sinksVBox->pack_start(*w, false, false, 0); sinksVBox->pack_start(*w, false, false, 0);
w->index = info.index; w->index = info.index;
@ -1631,6 +1661,9 @@ void sink_cb(pa_context *, const pa_sink_info *i, int eol, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata); MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) { if (eol < 0) {
if (pa_context_errno(context) == PA_ERR_NOENTITY)
return;
show_error(_("Sink callback failure")); show_error(_("Sink callback failure"));
return; return;
} }
@ -1647,6 +1680,9 @@ void source_cb(pa_context *, const pa_source_info *i, int eol, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata); MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) { if (eol < 0) {
if (pa_context_errno(context) == PA_ERR_NOENTITY)
return;
show_error(_("Source callback failure")); show_error(_("Source callback failure"));
return; return;
} }
@ -1663,6 +1699,9 @@ void sink_input_cb(pa_context *, const pa_sink_input_info *i, int eol, void *use
MainWindow *w = static_cast<MainWindow*>(userdata); MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) { if (eol < 0) {
if (pa_context_errno(context) == PA_ERR_NOENTITY)
return;
show_error(_("Sink input callback failure")); show_error(_("Sink input callback failure"));
return; return;
} }
@ -1679,6 +1718,9 @@ void source_output_cb(pa_context *, const pa_source_output_info *i, int eol, voi
MainWindow *w = static_cast<MainWindow*>(userdata); MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) { if (eol < 0) {
if (pa_context_errno(context) == PA_ERR_NOENTITY)
return;
show_error(_("Source output callback failure")); show_error(_("Source output callback failure"));
return; return;
} }
@ -1710,6 +1752,9 @@ void client_cb(pa_context *, const pa_client_info *i, int eol, void *userdata) {
MainWindow *w = static_cast<MainWindow*>(userdata); MainWindow *w = static_cast<MainWindow*>(userdata);
if (eol < 0) { if (eol < 0) {
if (pa_context_errno(context) == PA_ERR_NOENTITY)
return;
show_error(_("Client callback failure")); show_error(_("Client callback failure"));
return; return;
} }
@ -1955,6 +2000,8 @@ int main(int argc, char *argv[]) {
Gtk::Main kit(argc, argv); Gtk::Main kit(argc, argv);
ca_context_set_driver(ca_gtk_context_get(), "pulse");
Gtk::Window* mainWindow = MainWindow::create(); Gtk::Window* mainWindow = MainWindow::create();
pa_glib_mainloop *m = pa_glib_mainloop_new(g_main_context_default()); pa_glib_mainloop *m = pa_glib_mainloop_new(g_main_context_default());