diff options
author | Colin Guthrie <cguthrie@mandriva.org> | 2011-03-09 21:50:29 +0000 |
---|---|---|
committer | Colin Guthrie <cguthrie@mandriva.org> | 2011-03-09 21:50:29 +0000 |
commit | 297af52ae5581f5373bb008f60c7aac858bb365a (patch) | |
tree | 82490cb8ac5653690163bc9342622d79c35ec81e | |
parent | 9516b6f1dc3e97587221c46086b1b57c3af67ea3 (diff) |
volume: Support volumes up to 11.
This allows us to set volumes up to ~153% aka +11dB.
Also show the current dB value in the UI - as pavucontrol is a bit more
developer-friendly than other volume UIs displaying this by default makes
sense.
-rw-r--r-- | src/channelwidget.cc | 54 | ||||
-rw-r--r-- | src/channelwidget.h | 1 | ||||
-rw-r--r-- | src/devicewidget.cc | 1 | ||||
-rw-r--r-- | src/pavucontrol.glade | 7 | ||||
-rw-r--r-- | src/pavucontrol.h | 5 | ||||
-rw-r--r-- | src/streamwidget.cc | 2 |
6 files changed, 42 insertions, 28 deletions
diff --git a/src/channelwidget.cc b/src/channelwidget.cc index 21f3afa..2fb06a4 100644 --- a/src/channelwidget.cc +++ b/src/channelwidget.cc @@ -27,20 +27,22 @@ #include "i18n.h" -static bool show_decibel = true; - /*** ChannelWidget ***/ ChannelWidget::ChannelWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& x) : Gtk::EventBox(cobject), - volumeScaleEnabled(true) { + can_decibel(false), + volumeScaleEnabled(true), + last(false) { x->get_widget("channelLabel", channelLabel); x->get_widget("volumeLabel", volumeLabel); x->get_widget("volumeScale", volumeScale); - volumeScale->set_value(100.0); - volumeScale->set_increments(1.0, 5.0); + volumeScale->set_range((double)PA_VOLUME_MUTED, (double)PA_VOLUME_UI_MAX); + volumeScale->set_value((double)PA_VOLUME_NORM); + volumeScale->set_increments(((double)PA_VOLUME_NORM)/100.0, ((double)PA_VOLUME_NORM)/20.0); + setBaseVolume(PA_VOLUME_NORM); volumeScale->signal_value_changed().connect(sigc::mem_fun(*this, &ChannelWidget::onVolumeScaleValueChanged)); } @@ -59,24 +61,19 @@ void ChannelWidget::setVolume(pa_volume_t volume) { char txt[64]; v = ((gdouble) volume * 100) / PA_VOLUME_NORM; - - if (can_decibel && show_decibel) { + if (can_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); + if (dB > PA_DECIBEL_MININFTY) + snprintf(txt, sizeof(txt), "<small>%0.0f%% (%0.2fdB)</small>", v, dB); + else + snprintf(txt, sizeof(txt), "<small>%0.0f%% (-∞dB)</small>", v); + } + else + snprintf(txt, sizeof(txt), "%0.0f%%", v); + volumeLabel->set_markup(txt); volumeScaleEnabled = false; - volumeScale->set_value(v > 100 ? 100 : v); + volumeScale->set_value(volume > PA_VOLUME_UI_MAX ? PA_VOLUME_UI_MAX : volume); volumeScaleEnabled = true; } @@ -88,7 +85,7 @@ void ChannelWidget::onVolumeScaleValueChanged() { if (minimalStreamWidget->updating) return; - pa_volume_t volume = (pa_volume_t) ((volumeScale->get_value() * PA_VOLUME_NORM) / 100); + pa_volume_t volume = (pa_volume_t) volumeScale->get_value(); minimalStreamWidget->updateChannelVolume(channel, volume); } @@ -102,17 +99,20 @@ void ChannelWidget::set_sensitive(bool enabled) { void ChannelWidget::setBaseVolume(pa_volume_t v) { - gtk_scale_add_mark(GTK_SCALE(volumeScale->gobj()), 0.0, (GtkPositionType) GTK_POS_BOTTOM, - can_decibel ? _("<small>Silence</small>") : _("<small>Min</small>")); - gtk_scale_add_mark(GTK_SCALE(volumeScale->gobj()), 100.0, (GtkPositionType) GTK_POS_BOTTOM, _("<small>Max</small>")); + gtk_scale_clear_marks(GTK_SCALE(volumeScale->gobj())); + + gtk_scale_add_mark(GTK_SCALE(volumeScale->gobj()), (double)PA_VOLUME_MUTED, (GtkPositionType) GTK_POS_BOTTOM, + last ? (can_decibel ? _("<small>Silence</small>") : _("<small>Min</small>")) : NULL); + gtk_scale_add_mark(GTK_SCALE(volumeScale->gobj()), (double)PA_VOLUME_NORM, (GtkPositionType) GTK_POS_BOTTOM, + last ? _("<small>100% (0dB)</small>") : NULL); if (v > PA_VOLUME_MUTED && v < PA_VOLUME_NORM) { - double p = ((double) v * 100) / PA_VOLUME_NORM; - gtk_scale_add_mark(GTK_SCALE(volumeScale->gobj()), p, (GtkPositionType) GTK_POS_BOTTOM, _("<small><i>Base</i></small>")); + gtk_scale_add_mark(GTK_SCALE(volumeScale->gobj()), (double)v, (GtkPositionType) GTK_POS_BOTTOM, + last ? _("<small><i>Base</i></small>") : NULL); } } void ChannelWidget::setSteps(unsigned n) { - volumeScale->set_increments(100.0/(n-1), 100.0/(n-1)); + /*volumeScale->set_increments(100.0/(n-1), 100.0/(n-1));*/ } diff --git a/src/channelwidget.h b/src/channelwidget.h index 26a880c..a1debda 100644 --- a/src/channelwidget.h +++ b/src/channelwidget.h @@ -43,6 +43,7 @@ public: bool can_decibel; bool volumeScaleEnabled; + bool last; virtual void set_sensitive(bool enabled); virtual void setBaseVolume(pa_volume_t); diff --git a/src/devicewidget.cc b/src/devicewidget.cc index 9a75970..b513ee8 100644 --- a/src/devicewidget.cc +++ b/src/devicewidget.cc @@ -77,6 +77,7 @@ void DeviceWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) { cw->channelLabel->set_markup(text); channelsVBox->pack_start(*cw, false, false, 0); } + channelWidgets[m.channels-1]->last = true; lockToggleButton->set_sensitive(m.channels > 1); } diff --git a/src/pavucontrol.glade b/src/pavucontrol.glade index db21b8a..3077a88 100644 --- a/src/pavucontrol.glade +++ b/src/pavucontrol.glade @@ -150,6 +150,7 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="xalign">0</property> + <property name="yalign">0</property> <property name="label" translatable="yes"><b>left-front</b></property> <property name="use_markup">True</property> <property name="width_chars">15</property> @@ -179,7 +180,11 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="xalign">1</property> - <property name="label" translatable="yes">50%</property> + <property name="yalign">0</property> + <property name="xpad">8</property> + <property name="label" translatable="yes"><small>50%</small></property> + <property name="use_markup">True</property> + <property name="justify">right</property> <property name="width_chars">9</property> </object> <packing> diff --git a/src/pavucontrol.h b/src/pavucontrol.h index 4e3d32e..1ef2519 100644 --- a/src/pavucontrol.h +++ b/src/pavucontrol.h @@ -34,6 +34,11 @@ #define GLADE_FILE "pavucontrol.glade" #endif +/* Can be removed when PulseAudio 0.9.23 or newer is required */ +#ifndef PA_VOLUME_UI_MAX +# define PA_VOLUME_UI_MAX (pa_sw_volume_from_dB(+11.0)) +#endif + enum SinkInputType { SINK_INPUT_ALL, SINK_INPUT_CLIENT, diff --git a/src/streamwidget.cc b/src/streamwidget.cc index 431e460..94363ec 100644 --- a/src/streamwidget.cc +++ b/src/streamwidget.cc @@ -78,6 +78,8 @@ void StreamWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) { cw->channelLabel->set_markup(text); channelsVBox->pack_start(*cw, false, false, 0); } + channelWidgets[m.channels-1]->last = true; + channelWidgets[m.channels-1]->setBaseVolume(PA_VOLUME_NORM); lockToggleButton->set_sensitive(m.channels > 1); } |