summaryrefslogtreecommitdiffstats
path: root/src/SinkWindow.cc
blob: 6acede77b9652ed362b8ff4616533c5633929edc (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* $Id$ */

/***
  This file is part of paman.
 
  paman 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.
 
  paman 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 paman; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA.
***/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream>

#include "paman.hh"
#include "SinkWindow.hh"

#define GLADE_NAME "sinkWindow"

SinkWindow::SinkWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade) :
    Gtk::Window(cobject),
    nameLabel(NULL),
    descriptionLabel(NULL),
    indexLabel(NULL),
    sampleTypeLabel(NULL),
    channelMapLabel(NULL),
    latencyLabel(NULL),
    ownerModuleLabel(NULL),
    monitorSourceLabel(NULL),
    volumeLabel(NULL),
    closeButton(NULL),
    toMonitorSourceButton(NULL),
    toOwnerModuleButton(NULL),
    volumeResetButton(NULL),
    volumeMuteButton(NULL),
    volumeMeterButton(NULL),
    volumeScale(NULL),
    scaleEnabled(true) {

    refGlade->get_widget("nameLabel", nameLabel);
    refGlade->get_widget("descriptionLabel", descriptionLabel);
    refGlade->get_widget("indexLabel", indexLabel);
    refGlade->get_widget("sampleTypeLabel", sampleTypeLabel);
    refGlade->get_widget("channelMapLabel", channelMapLabel);
    refGlade->get_widget("latencyLabel", latencyLabel);
    refGlade->get_widget("ownerModuleLabel", ownerModuleLabel);
    refGlade->get_widget("monitorSourceLabel", monitorSourceLabel);
    refGlade->get_widget("closeButton", closeButton);
    refGlade->get_widget("toMonitorSourceButton", toMonitorSourceButton);
    refGlade->get_widget("toOwnerModuleButton", toOwnerModuleButton);
    refGlade->get_widget("volumeLabel", volumeLabel);
    refGlade->get_widget("volumeScale", volumeScale);
    refGlade->get_widget("volumeResetButton", volumeResetButton);
    refGlade->get_widget("volumeMuteButton", volumeMuteButton);
    refGlade->get_widget("volumeMeterButton", volumeMeterButton);

    closeButton->signal_clicked().connect(sigc::mem_fun(*this, &SinkWindow::onCloseButton));
    toMonitorSourceButton->signal_clicked().connect(sigc::mem_fun(*this, &SinkWindow::onToMonitorSourceButton));
    toOwnerModuleButton->signal_clicked().connect(sigc::mem_fun(*this, &SinkWindow::onToOwnerModuleButton));
    volumeScale->signal_value_changed().connect(sigc::mem_fun(*this, &SinkWindow::onVolumeScaleValueChanged));
    volumeResetButton->signal_clicked().connect(sigc::mem_fun(*this, &SinkWindow::onVolumeResetButton));
    volumeMuteButton->signal_clicked().connect(sigc::mem_fun(*this, &SinkWindow::onVolumeMuteButton));
    volumeMeterButton->signal_clicked().connect(sigc::mem_fun(*this, &SinkWindow::onVolumeMeterButton));

    volumeMeterButton->set_sensitive(serverInfoManager->volumeMeterSupported());
}

SinkWindow* SinkWindow::create() {
    SinkWindow *w = NULL;
    Glib::RefPtr<Gnome::Glade::Xml> refXml = Gnome::Glade::Xml::create(GLADE_FILE, GLADE_NAME);
    refXml->get_widget_derived(GLADE_NAME, w);
    return w;
}

void SinkWindow::updateInfo(const SinkInfo &i) {
    char t[64], ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
    double percent;

    nameLabel->set_text(i.name);
    descriptionLabel->set_text(i.description);
    snprintf(t, sizeof(t), "#%u", i.index);
    indexLabel->set_text(t);
    sampleTypeLabel->set_text(pa_sample_spec_snprint(ss, sizeof(ss), &i.sample_spec));
    channelMapLabel->set_text(pa_channel_map_snprint(cm, sizeof(cm), &i.channel_map));
    snprintf(t, sizeof(t), "#%u", i.owner_module);
    ownerModuleLabel->set_text(t);

    snprintf(t, sizeof(t), "%0.0f usec", (double) i.latency);
    latencyLabel->set_text(t);

    SourceInfo *source = serverInfoManager->getSourceInfo(i.monitor_source);
    monitorSourceLabel->set_text(source->name);

    percent = ((double) pa_cvolume_avg(&i.volume) * 100) / PA_VOLUME_NORM; 
    scaleEnabled = false;
    volumeScale->set_value(percent);
    scaleEnabled = true;

    if (i.hw_volume_supported)
        snprintf(t, sizeof(t), "%0.0f%%", percent);
    else {
        double db;
        
        db = pa_sw_volume_to_dB(pa_cvolume_avg(&i.volume));

        if (db != PA_DECIBEL_MININFTY)
            snprintf(t, sizeof(t), "%0.0f%% (%0.2fdB)", percent, db);
        else
            snprintf(t, sizeof(t), "%0.0f%% (-&#8734;dB)", percent);
    }
    volumeLabel->set_markup(t);
    
    set_title("Sink: "+i.name);
    
    monitor_source = i.monitor_source;
    owner_module = i.owner_module;
    index = i.index;
    monitor_source_name = i.monitor_source_name;

    toOwnerModuleButton->set_sensitive(owner_module != PA_INVALID_INDEX);
}

void SinkWindow::onCloseButton() {
    hide();
}

void SinkWindow::onToMonitorSourceButton() {
    serverInfoManager->showSourceWindow(monitor_source);
}

void SinkWindow::onToOwnerModuleButton() {
    if (owner_module != (uint32_t) -1)
        serverInfoManager->showModuleWindow(owner_module);
}

void SinkWindow::onVolumeScaleValueChanged() {
    if (scaleEnabled)
        serverInfoManager->setSinkVolume(index, (pa_volume_t) (((double) volumeScale->get_value()/100) * PA_VOLUME_NORM));
}

void SinkWindow::onVolumeResetButton() {
    serverInfoManager->setSinkVolume(index, PA_VOLUME_NORM);
}

void SinkWindow::onVolumeMuteButton() {
    serverInfoManager->setSinkVolume(index, PA_VOLUME_MUTED);
}

bool SinkWindow::on_delete_event(GdkEventAny*) {
    hide();
    return false;
}

void SinkWindow::onVolumeMeterButton() {
    serverInfoManager->runVolumeMeter(monitor_source_name);
}