From f6af4f80b8e4760bdfdc8ca66509d8667bb6f41b Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Sun, 15 Mar 2009 12:54:56 +0000 Subject: [PATCH] Split channelwidget into separate files. Also separate out the definition of streamwidget into it's own header --- src/Makefile.am | 2 + src/channelwidget.cc | 109 ++++++++++++++++++++++++++++++++++ src/channelwidget.h | 64 ++++++++++++++++++++ src/pavucontrol.cc | 138 +------------------------------------------ src/streamwidget.h | 58 ++++++++++++++++++ 5 files changed, 235 insertions(+), 136 deletions(-) create mode 100644 src/channelwidget.cc create mode 100644 src/channelwidget.h create mode 100644 src/streamwidget.h diff --git a/src/Makefile.am b/src/Makefile.am index 7a1dc0a..d0aea0f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,6 +26,8 @@ desktop_DATA=$(desktop_in_files:.desktop.in=.desktop) pavucontrol_SOURCES= \ minimalstreamwidget.h minimalstreamwidget.cc \ + channelwidget.h channelwidget.cc \ + streamwidget.h \ pavucontrol.cc i18n.h pavucontrol_LDADD=$(AM_LDADD) $(GUILIBS_LIBS) $(PULSE_LIBS) diff --git a/src/channelwidget.cc b/src/channelwidget.cc new file mode 100644 index 0000000..f30a01a --- /dev/null +++ b/src/channelwidget.cc @@ -0,0 +1,109 @@ +/*** + This file is part of pavucontrol. + + Copyright 2006-2008 Lennart Poettering + Copyright 2009 Colin Guthrie + + pavucontrol is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + pavucontrol is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with pavucontrol. If not, see . +***/ + +#include "channelwidget.h" +#include "streamwidget.h" + +static bool show_decibel = true; + +/*** ChannelWidget ***/ + +ChannelWidget::ChannelWidget(BaseObjectType* cobject, const Glib::RefPtr& x) : + Gtk::EventBox(cobject), + volumeScaleEnabled(true) { + + x->get_widget("channelLabel", channelLabel); + x->get_widget("volumeLabel", volumeLabel); + x->get_widget("volumeScale", volumeScale); + + volumeScale->set_value(100); + + volumeScale->signal_value_changed().connect(sigc::mem_fun(*this, &ChannelWidget::onVolumeScaleValueChanged)); +} + +ChannelWidget* ChannelWidget::create() { + ChannelWidget* w; + Glib::RefPtr x = Gnome::Glade::Xml::create(GLADE_FILE, "channelWidget"); + x->get_widget_derived("channelWidget", w); + return w; +} + +void ChannelWidget::setVolume(pa_volume_t volume) { + double v; + char txt[64]; + + v = ((gdouble) volume * 100) / PA_VOLUME_NORM; + + if (can_decibel && show_decibel) { + double dB = pa_sw_volume_to_dB(volume); + + if (dB > PA_DECIBEL_MININFTY) { + snprintf(txt, sizeof(txt), "%0.2f dB", dB); + volumeLabel->set_tooltip_text(txt); + } else + 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); + volumeScaleEnabled = true; +} + +void ChannelWidget::onVolumeScaleValueChanged() { + + if (!volumeScaleEnabled) + return; + + if (streamWidget->updating) + return; + + pa_volume_t volume = (pa_volume_t) ((volumeScale->get_value() * PA_VOLUME_NORM) / 100); + streamWidget->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) { + Gtk::EventBox::set_sensitive(enabled); + + channelLabel->set_sensitive(enabled); + volumeLabel->set_sensitive(enabled); + volumeScale->set_sensitive(enabled); +} diff --git a/src/channelwidget.h b/src/channelwidget.h new file mode 100644 index 0000000..a999783 --- /dev/null +++ b/src/channelwidget.h @@ -0,0 +1,64 @@ +/*** + This file is part of pavucontrol. + + Copyright 2006-2008 Lennart Poettering + Copyright 2009 Colin Guthrie + + pavucontrol is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + pavucontrol is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with pavucontrol. If not, see . +***/ + +#ifndef channelwidget_h +#define channelwidget_h + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include + +#include + +#include "i18n.h" + +class StreamWidget; + +class ChannelWidget : public Gtk::EventBox { +public: + ChannelWidget(BaseObjectType* cobject, const Glib::RefPtr& x); + static ChannelWidget* create(); + + void setVolume(pa_volume_t volume); + + Gtk::Label *channelLabel; + Gtk::Label *volumeLabel; + Gtk::HScale *volumeScale; + + int channel; + StreamWidget *streamWidget; + + void onVolumeScaleValueChanged(); + + bool can_decibel; + bool volumeScaleEnabled; + + Glib::ustring beepDevice; + + virtual void set_sensitive(bool enabled); +}; + + +#endif diff --git a/src/pavucontrol.cc b/src/pavucontrol.cc index a4c0f31..a88f5d5 100644 --- a/src/pavucontrol.cc +++ b/src/pavucontrol.cc @@ -37,6 +37,8 @@ #include "i18n.h" #include "minimalstreamwidget.h" +#include "channelwidget.h" +#include "streamwidget.h" #ifndef GLADE_FILE #define GLADE_FILE "pavucontrol.glade" @@ -44,7 +46,6 @@ static pa_context *context = NULL; static int n_outstanding = 0; -static bool show_decibel = true; enum SinkInputType { SINK_INPUT_ALL, @@ -75,54 +76,6 @@ enum SourceType{ class StreamWidget; class MainWindow; -class ChannelWidget : public Gtk::EventBox { -public: - ChannelWidget(BaseObjectType* cobject, const Glib::RefPtr& x); - static ChannelWidget* create(); - - void setVolume(pa_volume_t volume); - - Gtk::Label *channelLabel; - Gtk::Label *volumeLabel; - Gtk::HScale *volumeScale; - - int channel; - StreamWidget *streamWidget; - - void onVolumeScaleValueChanged(); - - bool can_decibel; - bool volumeScaleEnabled; - - Glib::ustring beepDevice; - - virtual void set_sensitive(bool enabled); -}; - -class StreamWidget : public MinimalStreamWidget { -public: - StreamWidget(BaseObjectType* cobject, const Glib::RefPtr& x); - - void setChannelMap(const pa_channel_map &m, bool can_decibel); - void setVolume(const pa_cvolume &volume, bool force); - virtual void updateChannelVolume(int channel, pa_volume_t v); - - Gtk::ToggleButton *lockToggleButton, *muteToggleButton; - - pa_channel_map channelMap; - pa_cvolume volume; - - ChannelWidget *channelWidgets[PA_CHANNELS_MAX]; - - virtual void onMuteToggleButton(); - - sigc::connection timeoutConnection; - - bool timeoutEvent(); - - virtual void executeVolumeUpdate(); -}; - class CardWidget : public Gtk::VBox { public: CardWidget(BaseObjectType* cobject, const Glib::RefPtr& x); @@ -365,93 +318,6 @@ void show_error(const char *txt) { Gtk::Main::quit(); } -/*** ChannelWidget ***/ - -ChannelWidget::ChannelWidget(BaseObjectType* cobject, const Glib::RefPtr& x) : - Gtk::EventBox(cobject), - volumeScaleEnabled(true) { - - x->get_widget("channelLabel", channelLabel); - x->get_widget("volumeLabel", volumeLabel); - x->get_widget("volumeScale", volumeScale); - - volumeScale->set_value(100); - - volumeScale->signal_value_changed().connect(sigc::mem_fun(*this, &ChannelWidget::onVolumeScaleValueChanged)); -} - -ChannelWidget* ChannelWidget::create() { - ChannelWidget* w; - Glib::RefPtr x = Gnome::Glade::Xml::create(GLADE_FILE, "channelWidget"); - x->get_widget_derived("channelWidget", w); - return w; -} - -void ChannelWidget::setVolume(pa_volume_t volume) { - double v; - char txt[64]; - - v = ((gdouble) volume * 100) / PA_VOLUME_NORM; - - if (can_decibel && show_decibel) { - double dB = pa_sw_volume_to_dB(volume); - - if (dB > PA_DECIBEL_MININFTY) { - snprintf(txt, sizeof(txt), "%0.2f dB", dB); - volumeLabel->set_tooltip_text(txt); - } else - 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); - volumeScaleEnabled = true; -} - -void ChannelWidget::onVolumeScaleValueChanged() { - - if (!volumeScaleEnabled) - return; - - if (streamWidget->updating) - return; - - pa_volume_t volume = (pa_volume_t) ((volumeScale->get_value() * PA_VOLUME_NORM) / 100); - streamWidget->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) { - Gtk::EventBox::set_sensitive(enabled); - - channelLabel->set_sensitive(enabled); - volumeLabel->set_sensitive(enabled); - volumeScale->set_sensitive(enabled); -} - - - /*** CardWidget ***/ CardWidget::CardWidget(BaseObjectType* cobject, const Glib::RefPtr& x) : Gtk::VBox(cobject) { diff --git a/src/streamwidget.h b/src/streamwidget.h new file mode 100644 index 0000000..b6f49c8 --- /dev/null +++ b/src/streamwidget.h @@ -0,0 +1,58 @@ +/*** + This file is part of pavucontrol. + + Copyright 2006-2008 Lennart Poettering + Copyright 2009 Colin Guthrie + + pavucontrol is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + pavucontrol is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with pavucontrol. If not, see . +***/ + +#ifndef streamwidget_h +#define streamwidget_h + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include "minimalstreamwidget.h" + +class StreamWidget : public MinimalStreamWidget { +public: + StreamWidget(BaseObjectType* cobject, const Glib::RefPtr& x); + + void setChannelMap(const pa_channel_map &m, bool can_decibel); + void setVolume(const pa_cvolume &volume, bool force); + virtual void updateChannelVolume(int channel, pa_volume_t v); + + Gtk::ToggleButton *lockToggleButton, *muteToggleButton; + + pa_channel_map channelMap; + pa_cvolume volume; + + ChannelWidget *channelWidgets[PA_CHANNELS_MAX]; + + virtual void onMuteToggleButton(); + + sigc::connection timeoutConnection; + + bool timeoutEvent(); + + virtual void executeVolumeUpdate(); +}; + + +#endif \ No newline at end of file