2009-03-15 12:54:56 +00:00
|
|
|
/***
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
2009-03-18 20:58:17 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2009-03-15 12:54:56 +00:00
|
|
|
#include "channelwidget.h"
|
2009-03-16 19:57:31 +00:00
|
|
|
#include "minimalstreamwidget.h"
|
2009-03-15 12:54:56 +00:00
|
|
|
|
2009-03-15 13:08:22 +00:00
|
|
|
#include "i18n.h"
|
|
|
|
|
2009-03-15 12:54:56 +00:00
|
|
|
/*** ChannelWidget ***/
|
|
|
|
|
2011-03-03 14:31:14 +00:00
|
|
|
ChannelWidget::ChannelWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& x) :
|
2009-03-15 12:54:56 +00:00
|
|
|
Gtk::EventBox(cobject),
|
2011-03-09 21:50:29 +00:00
|
|
|
can_decibel(false),
|
|
|
|
volumeScaleEnabled(true),
|
|
|
|
last(false) {
|
2009-03-15 12:54:56 +00:00
|
|
|
|
|
|
|
x->get_widget("channelLabel", channelLabel);
|
|
|
|
x->get_widget("volumeLabel", volumeLabel);
|
|
|
|
x->get_widget("volumeScale", volumeScale);
|
|
|
|
|
2011-03-09 21:50:29 +00:00
|
|
|
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);
|
2009-03-15 12:54:56 +00:00
|
|
|
|
|
|
|
volumeScale->signal_value_changed().connect(sigc::mem_fun(*this, &ChannelWidget::onVolumeScaleValueChanged));
|
|
|
|
}
|
|
|
|
|
2018-12-12 09:26:09 +00:00
|
|
|
ChannelWidget* ChannelWidget::createOne(MinimalStreamWidget *owner, int channelIndex, pa_channel_position channelPosition, bool can_decibel) {
|
2009-03-15 12:54:56 +00:00
|
|
|
ChannelWidget* w;
|
2011-03-03 14:31:14 +00:00
|
|
|
Glib::RefPtr<Gtk::Builder> x = Gtk::Builder::create();
|
|
|
|
x->add_from_file(GLADE_FILE, "adjustment1");
|
|
|
|
x->add_from_file(GLADE_FILE, "channelWidget");
|
2009-03-15 12:54:56 +00:00
|
|
|
x->get_widget_derived("channelWidget", w);
|
2014-08-28 10:58:05 +00:00
|
|
|
w->reference();
|
2018-12-12 09:26:09 +00:00
|
|
|
|
|
|
|
w->channel = channelIndex;
|
|
|
|
w->can_decibel = can_decibel;
|
|
|
|
w->minimalStreamWidget = owner;
|
|
|
|
|
|
|
|
char text[64];
|
|
|
|
snprintf(text, sizeof(text), "<b>%s</b>", pa_channel_position_to_pretty_string(channelPosition));
|
|
|
|
w->channelLabel->set_markup(text);
|
|
|
|
|
2009-03-15 12:54:56 +00:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2018-12-12 09:26:09 +00:00
|
|
|
void ChannelWidget::create(MinimalStreamWidget *owner, const pa_channel_map &m, bool can_decibel, ChannelWidget *widgets[PA_CHANNELS_MAX]) {
|
|
|
|
for (int i = 0; i < m.channels; i++)
|
|
|
|
widgets[i] = ChannelWidget::createOne(owner, i, m.map[i], can_decibel);
|
|
|
|
|
|
|
|
widgets[m.channels - 1]->last = true;
|
|
|
|
}
|
|
|
|
|
2009-03-15 12:54:56 +00:00
|
|
|
void ChannelWidget::setVolume(pa_volume_t volume) {
|
|
|
|
double v;
|
|
|
|
char txt[64];
|
|
|
|
|
|
|
|
v = ((gdouble) volume * 100) / PA_VOLUME_NORM;
|
2011-03-09 21:50:29 +00:00
|
|
|
if (can_decibel) {
|
2009-03-15 12:54:56 +00:00
|
|
|
double dB = pa_sw_volume_to_dB(volume);
|
2011-03-09 21:50:29 +00:00
|
|
|
if (dB > PA_DECIBEL_MININFTY)
|
2019-01-12 13:05:33 +00:00
|
|
|
snprintf(txt, sizeof(txt), _("<small>%0.0f%% (%0.2f dB)</small>"), v, dB);
|
2011-03-09 21:50:29 +00:00
|
|
|
else
|
2019-01-12 13:05:33 +00:00
|
|
|
snprintf(txt, sizeof(txt), _("<small>%0.0f%% (-∞ dB)</small>"), v);
|
2011-03-09 21:50:29 +00:00
|
|
|
}
|
|
|
|
else
|
2019-01-12 13:05:33 +00:00
|
|
|
snprintf(txt, sizeof(txt), _("%0.0f%%"), v);
|
2011-03-09 21:50:29 +00:00
|
|
|
volumeLabel->set_markup(txt);
|
2009-03-15 12:54:56 +00:00
|
|
|
|
|
|
|
volumeScaleEnabled = false;
|
2011-03-09 21:50:29 +00:00
|
|
|
volumeScale->set_value(volume > PA_VOLUME_UI_MAX ? PA_VOLUME_UI_MAX : volume);
|
2009-03-15 12:54:56 +00:00
|
|
|
volumeScaleEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelWidget::onVolumeScaleValueChanged() {
|
|
|
|
|
|
|
|
if (!volumeScaleEnabled)
|
|
|
|
return;
|
|
|
|
|
2009-03-16 19:57:31 +00:00
|
|
|
if (minimalStreamWidget->updating)
|
2009-03-15 12:54:56 +00:00
|
|
|
return;
|
|
|
|
|
2011-03-09 21:50:29 +00:00
|
|
|
pa_volume_t volume = (pa_volume_t) volumeScale->get_value();
|
2009-03-16 19:57:31 +00:00
|
|
|
minimalStreamWidget->updateChannelVolume(channel, volume);
|
2009-03-15 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelWidget::set_sensitive(bool enabled) {
|
|
|
|
Gtk::EventBox::set_sensitive(enabled);
|
|
|
|
|
|
|
|
channelLabel->set_sensitive(enabled);
|
|
|
|
volumeLabel->set_sensitive(enabled);
|
|
|
|
volumeScale->set_sensitive(enabled);
|
|
|
|
}
|
2009-03-21 02:27:25 +00:00
|
|
|
|
|
|
|
void ChannelWidget::setBaseVolume(pa_volume_t v) {
|
|
|
|
|
2011-03-09 21:50:29 +00:00
|
|
|
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,
|
2019-01-12 13:05:33 +00:00
|
|
|
last ? _("<small>100% (0 dB)</small>") : NULL);
|
2009-03-21 02:27:25 +00:00
|
|
|
|
|
|
|
if (v > PA_VOLUME_MUTED && v < PA_VOLUME_NORM) {
|
2011-03-09 21:50:29 +00:00
|
|
|
gtk_scale_add_mark(GTK_SCALE(volumeScale->gobj()), (double)v, (GtkPositionType) GTK_POS_BOTTOM,
|
|
|
|
last ? _("<small><i>Base</i></small>") : NULL);
|
2009-03-21 02:27:25 +00:00
|
|
|
}
|
|
|
|
|
2009-03-21 02:49:19 +00:00
|
|
|
}
|