From ecc9ad9b06184dc2a4d2bc8da581d8bca0ae67aa Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 19 Aug 2008 17:36:18 +0200 Subject: [PATCH] beep when changing volume --- configure.ac | 2 +- src/pavucontrol.cc | 59 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index e4663e7..65c685a 100644 --- a/configure.ac +++ b/configure.ac @@ -38,7 +38,7 @@ AC_PROG_LN_S AC_TYPE_SIGNAL 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_LIBS) diff --git a/src/pavucontrol.cc b/src/pavucontrol.cc index 8b67e58..fd63209 100644 --- a/src/pavucontrol.cc +++ b/src/pavucontrol.cc @@ -29,6 +29,8 @@ #include #include +#include + #include #include #include @@ -91,6 +93,8 @@ public: bool can_decibel; bool volumeScaleEnabled; + Glib::ustring beepDevice; + virtual void set_sensitive(bool enabled); }; @@ -118,6 +122,8 @@ public: void enableVolumeMeter(); void updatePeak(double v); + Glib::ustring beepDevice; + protected: virtual bool on_button_press_event(GdkEventButton* event); }; @@ -376,13 +382,15 @@ void ChannelWidget::setVolume(pa_volume_t volume) { if (dB > PA_DECIBEL_MININFTY) { snprintf(txt, sizeof(txt), "%0.2f dB", dB); - volumeLabel->set_text(txt); + volumeLabel->set_tooltip_text(txt); } else - volumeLabel->set_markup("-∞dB"); - } else { - snprintf(txt, sizeof(txt), "%0.0f%%", v); - volumeLabel->set_text(txt); - } + volumeLabel->set_tooltip_markup("-∞dB"); + volumeLabel->set_has_tooltip(TRUE); + } else + volumeLabel->set_has_tooltip(FALSE); + + snprintf(txt, sizeof(txt), "%0.0f%%", v); + volumeLabel->set_text(txt); volumeScaleEnabled = false; 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); 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) { @@ -524,6 +552,7 @@ 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->streamWidget = this; @@ -988,6 +1017,7 @@ void MainWindow::updateSink(const pa_sink_info &info) { w = sinkWidgets[info.index]; else { sinkWidgets[info.index] = w = SinkWidget::create(); + w->beepDevice = info.name; w->setChannelMap(info.channel_map, !!(info.flags & PA_SINK_DECIBEL_VOLUME)); sinksVBox->pack_start(*w, false, false, 0); 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(userdata); if (eol < 0) { + if (pa_context_errno(context) == PA_ERR_NOENTITY) + return; + show_error(_("Sink callback failure")); return; } @@ -1647,6 +1680,9 @@ void source_cb(pa_context *, const pa_source_info *i, int eol, void *userdata) { MainWindow *w = static_cast(userdata); if (eol < 0) { + if (pa_context_errno(context) == PA_ERR_NOENTITY) + return; + show_error(_("Source callback failure")); 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(userdata); if (eol < 0) { + if (pa_context_errno(context) == PA_ERR_NOENTITY) + return; + show_error(_("Sink input callback failure")); return; } @@ -1679,6 +1718,9 @@ void source_output_cb(pa_context *, const pa_source_output_info *i, int eol, voi MainWindow *w = static_cast(userdata); if (eol < 0) { + if (pa_context_errno(context) == PA_ERR_NOENTITY) + return; + show_error(_("Source output callback failure")); return; } @@ -1710,6 +1752,9 @@ void client_cb(pa_context *, const pa_client_info *i, int eol, void *userdata) { MainWindow *w = static_cast(userdata); if (eol < 0) { + if (pa_context_errno(context) == PA_ERR_NOENTITY) + return; + show_error(_("Client callback failure")); return; } @@ -1955,6 +2000,8 @@ int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); + ca_context_set_driver(ca_gtk_context_get(), "pulse"); + Gtk::Window* mainWindow = MainWindow::create(); pa_glib_mainloop *m = pa_glib_mainloop_new(g_main_context_default());