1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/***
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/>.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "channelwidget.h"
#include "streamwidget.h"
#include "i18n.h"
static bool show_decibel = true;
/*** ChannelWidget ***/
ChannelWidget::ChannelWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& 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.0);
volumeScale->set_increments(100.0/PA_VOLUME_NORM, 100.0/PA_VOLUME_NORM);
volumeScale->signal_value_changed().connect(sigc::mem_fun(*this, &ChannelWidget::onVolumeScaleValueChanged));
}
ChannelWidget* ChannelWidget::create() {
ChannelWidget* w;
Glib::RefPtr<Gnome::Glade::Xml> 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);
}
void ChannelWidget::setBaseVolume(pa_volume_t v) {
gtk_scale_add_mark(GTK_SCALE(volumeScale->gobj()), 0.0, (GtkPositionType) GTK_POS_BOTTOM, _("<small>Silence</small>"));
gtk_scale_add_mark(GTK_SCALE(volumeScale->gobj()), 100.0, (GtkPositionType) GTK_POS_BOTTOM, _("<small>Max</small>"));
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>"));
}
}
void ChannelWidget::setSteps(unsigned n) {
volumeScale->set_increments(100.0/(n-1), 100.0/(n-1));
}
|