2009-03-16 16:59:15 +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 21:07:49 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2009-06-28 14:57:59 +00:00
|
|
|
#include <pulse/ext-device-manager.h>
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
2009-03-16 16:59:15 +00:00
|
|
|
#include "devicewidget.h"
|
2009-03-16 19:57:31 +00:00
|
|
|
#include "channelwidget.h"
|
2009-03-16 16:59:15 +00:00
|
|
|
|
2009-06-28 14:57:59 +00:00
|
|
|
#include "i18n.h"
|
|
|
|
|
2009-03-16 16:59:15 +00:00
|
|
|
/*** DeviceWidget ***/
|
2011-03-03 14:31:14 +00:00
|
|
|
DeviceWidget::DeviceWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& x) :
|
2012-07-26 13:42:11 +00:00
|
|
|
MinimalStreamWidget(cobject, x),
|
|
|
|
offsetButtonEnabled(false) {
|
2009-03-16 16:59:15 +00:00
|
|
|
|
|
|
|
x->get_widget("lockToggleButton", lockToggleButton);
|
|
|
|
x->get_widget("muteToggleButton", muteToggleButton);
|
2009-03-16 23:18:40 +00:00
|
|
|
x->get_widget("defaultToggleButton", defaultToggleButton);
|
2009-06-27 17:14:05 +00:00
|
|
|
x->get_widget("portSelect", portSelect);
|
|
|
|
x->get_widget("portList", portList);
|
2012-11-20 10:51:53 +00:00
|
|
|
x->get_widget("advancedOptions", advancedOptions);
|
2012-07-26 13:42:11 +00:00
|
|
|
x->get_widget("offsetSelect", offsetSelect);
|
|
|
|
x->get_widget("offsetButton", offsetButton);
|
2009-03-16 16:59:15 +00:00
|
|
|
|
2009-06-28 14:57:59 +00:00
|
|
|
this->signal_button_press_event().connect(sigc::mem_fun(*this, &DeviceWidget::onContextTriggerEvent));
|
2009-03-16 16:59:15 +00:00
|
|
|
muteToggleButton->signal_clicked().connect(sigc::mem_fun(*this, &DeviceWidget::onMuteToggleButton));
|
2009-03-16 23:18:40 +00:00
|
|
|
defaultToggleButton->signal_clicked().connect(sigc::mem_fun(*this, &DeviceWidget::onDefaultToggleButton));
|
2009-03-16 16:59:15 +00:00
|
|
|
|
2009-06-28 14:57:59 +00:00
|
|
|
rename.set_label(_("Rename Device..."));
|
|
|
|
rename.signal_activate().connect(sigc::mem_fun(*this, &DeviceWidget::renamePopup));
|
|
|
|
contextMenu.append(rename);
|
|
|
|
contextMenu.show_all();
|
|
|
|
|
2009-06-27 17:14:05 +00:00
|
|
|
treeModel = Gtk::ListStore::create(portModel);
|
|
|
|
portList->set_model(treeModel);
|
|
|
|
portList->pack_start(portModel.desc);
|
|
|
|
|
2009-08-27 03:41:11 +00:00
|
|
|
portList->signal_changed().connect(sigc::mem_fun(*this, &DeviceWidget::onPortChange));
|
2012-07-26 13:42:11 +00:00
|
|
|
offsetButton->signal_value_changed().connect(sigc::mem_fun(*this, &DeviceWidget::onOffsetChange));
|
2009-06-27 17:14:05 +00:00
|
|
|
|
2009-03-16 16:59:15 +00:00
|
|
|
for (unsigned i = 0; i < PA_CHANNELS_MAX; i++)
|
|
|
|
channelWidgets[i] = NULL;
|
2012-07-26 13:42:11 +00:00
|
|
|
|
2013-03-08 19:27:02 +00:00
|
|
|
#ifdef HAVE_GTK3
|
2012-07-26 13:42:11 +00:00
|
|
|
offsetAdjustment = Gtk::Adjustment::create(0.0, -2000.0, 2000.0, 10.0, 50.0, 0.0);
|
|
|
|
offsetButton->configure(offsetAdjustment, 0, 2);
|
2013-03-08 19:27:02 +00:00
|
|
|
#else
|
|
|
|
offsetAdjustment = new Gtk::Adjustment(0.0, -2000.0, 2000.0, 10.0, 50.0, 0.0);
|
|
|
|
offsetButton->configure(*offsetAdjustment, 0.0, 2);
|
|
|
|
#endif /* HAVE_GTK3 */
|
2009-03-16 16:59:15 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 14:57:59 +00:00
|
|
|
void DeviceWidget::init(MainWindow* mainWindow, Glib::ustring deviceType) {
|
|
|
|
mpMainWindow = mainWindow;
|
|
|
|
mDeviceType = deviceType;
|
|
|
|
}
|
|
|
|
|
2009-03-16 16:59:15 +00:00
|
|
|
void DeviceWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
|
|
|
|
channelMap = m;
|
|
|
|
|
|
|
|
for (int i = 0; i < m.channels; i++) {
|
|
|
|
ChannelWidget *cw = channelWidgets[i] = ChannelWidget::create();
|
|
|
|
cw->channel = i;
|
|
|
|
cw->can_decibel = can_decibel;
|
2009-03-16 19:57:31 +00:00
|
|
|
cw->minimalStreamWidget = this;
|
2009-03-16 16:59:15 +00:00
|
|
|
char text[64];
|
|
|
|
snprintf(text, sizeof(text), "<b>%s</b>", pa_channel_position_to_pretty_string(m.map[i]));
|
|
|
|
cw->channelLabel->set_markup(text);
|
|
|
|
channelsVBox->pack_start(*cw, false, false, 0);
|
2014-08-28 10:58:05 +00:00
|
|
|
cw->unreference();
|
2009-03-16 16:59:15 +00:00
|
|
|
}
|
2011-03-09 21:50:29 +00:00
|
|
|
channelWidgets[m.channels-1]->last = true;
|
2009-03-16 16:59:15 +00:00
|
|
|
|
|
|
|
lockToggleButton->set_sensitive(m.channels > 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceWidget::setVolume(const pa_cvolume &v, bool force) {
|
|
|
|
g_assert(v.channels == channelMap.channels);
|
|
|
|
|
|
|
|
volume = v;
|
|
|
|
|
|
|
|
if (timeoutConnection.empty() || force) { /* do not update the volume when a volume change is still in flux */
|
|
|
|
for (int i = 0; i < volume.channels; i++)
|
|
|
|
channelWidgets[i]->setVolume(volume.values[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceWidget::updateChannelVolume(int channel, pa_volume_t v) {
|
|
|
|
pa_cvolume n;
|
|
|
|
g_assert(channel < volume.channels);
|
|
|
|
|
|
|
|
n = volume;
|
2009-08-27 03:41:11 +00:00
|
|
|
if (lockToggleButton->get_active())
|
|
|
|
pa_cvolume_set(&n, n.channels, v);
|
|
|
|
else
|
2009-03-16 16:59:15 +00:00
|
|
|
n.values[channel] = v;
|
|
|
|
|
|
|
|
setVolume(n, true);
|
|
|
|
|
|
|
|
if (timeoutConnection.empty())
|
|
|
|
timeoutConnection = Glib::signal_timeout().connect(sigc::mem_fun(*this, &DeviceWidget::timeoutEvent), 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceWidget::onMuteToggleButton() {
|
|
|
|
|
|
|
|
lockToggleButton->set_sensitive(!muteToggleButton->get_active());
|
|
|
|
|
|
|
|
for (int i = 0; i < channelMap.channels; i++)
|
|
|
|
channelWidgets[i]->set_sensitive(!muteToggleButton->get_active());
|
|
|
|
}
|
|
|
|
|
2009-03-16 23:18:40 +00:00
|
|
|
void DeviceWidget::onDefaultToggleButton() {
|
2009-06-17 21:44:02 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 13:42:11 +00:00
|
|
|
void DeviceWidget::onOffsetChange() {
|
|
|
|
pa_operation *o;
|
|
|
|
int64_t offset;
|
|
|
|
std::ostringstream card_stream;
|
|
|
|
Glib::ustring card_name;
|
|
|
|
|
|
|
|
if (!offsetButtonEnabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
offset = offsetButton->get_value() * 1000.0;
|
|
|
|
card_stream << card_index;
|
|
|
|
card_name = card_stream.str();
|
|
|
|
|
|
|
|
if (!(o = pa_context_set_port_latency_offset(get_context(),
|
|
|
|
card_name.c_str(), activePort.c_str(), offset, NULL, NULL))) {
|
|
|
|
show_error(_("pa_context_set_port_latency_offset() failed"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pa_operation_unref(o);
|
|
|
|
}
|
|
|
|
|
2009-06-17 21:44:02 +00:00
|
|
|
void DeviceWidget::setDefault(bool isDefault) {
|
|
|
|
defaultToggleButton->set_active(isDefault);
|
|
|
|
/*defaultToggleButton->set_sensitive(!isDefault);*/
|
2009-03-16 23:18:40 +00:00
|
|
|
}
|
|
|
|
|
2009-03-16 16:59:15 +00:00
|
|
|
bool DeviceWidget::timeoutEvent() {
|
|
|
|
executeVolumeUpdate();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceWidget::executeVolumeUpdate() {
|
|
|
|
}
|
2009-03-22 16:38:57 +00:00
|
|
|
|
2012-07-26 13:42:11 +00:00
|
|
|
void DeviceWidget::setLatencyOffset(int64_t offset) {
|
|
|
|
offsetButtonEnabled = false;
|
|
|
|
offsetButton->set_value(offset / 1000.0);
|
|
|
|
offsetButtonEnabled = true;
|
|
|
|
}
|
|
|
|
|
2009-03-22 16:38:57 +00:00
|
|
|
void DeviceWidget::setBaseVolume(pa_volume_t v) {
|
|
|
|
|
2011-03-28 17:52:27 +00:00
|
|
|
for (int i = 0; i < channelMap.channels; i++)
|
|
|
|
channelWidgets[i]->setBaseVolume(v);
|
2009-03-22 16:38:57 +00:00
|
|
|
}
|
|
|
|
|
2009-06-27 17:14:05 +00:00
|
|
|
void DeviceWidget::prepareMenu() {
|
2009-08-27 03:41:11 +00:00
|
|
|
int idx = 0;
|
|
|
|
int active_idx = -1;
|
|
|
|
|
|
|
|
treeModel->clear();
|
|
|
|
/* Fill the ComboBox's Tree Model */
|
|
|
|
for (uint32_t i = 0; i < ports.size(); ++i) {
|
|
|
|
Gtk::TreeModel::Row row = *(treeModel->append());
|
|
|
|
row[portModel.name] = ports[i].first;
|
|
|
|
row[portModel.desc] = ports[i].second;
|
|
|
|
if (ports[i].first == activePort)
|
|
|
|
active_idx = idx;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (active_idx >= 0)
|
|
|
|
portList->set_active(active_idx);
|
|
|
|
|
2012-07-26 13:42:11 +00:00
|
|
|
if (ports.size() > 0) {
|
2009-08-27 03:41:11 +00:00
|
|
|
portSelect->show();
|
2012-07-26 13:42:11 +00:00
|
|
|
|
2012-11-20 10:51:53 +00:00
|
|
|
if (pa_context_get_server_protocol_version(get_context()) >= 27) {
|
2012-07-26 13:42:11 +00:00
|
|
|
offsetSelect->show();
|
2012-11-20 10:51:53 +00:00
|
|
|
advancedOptions->set_sensitive(true);
|
|
|
|
} else {
|
|
|
|
/* advancedOptions has sensitive=false by default */
|
2012-07-26 13:42:11 +00:00
|
|
|
offsetSelect->hide();
|
2012-11-20 10:51:53 +00:00
|
|
|
}
|
2012-07-26 13:42:11 +00:00
|
|
|
|
|
|
|
} else {
|
2009-08-27 03:41:11 +00:00
|
|
|
portSelect->hide();
|
2012-11-20 10:51:53 +00:00
|
|
|
advancedOptions->set_sensitive(false);
|
2012-07-26 13:42:11 +00:00
|
|
|
offsetSelect->hide();
|
|
|
|
}
|
2009-06-27 17:14:05 +00:00
|
|
|
}
|
2009-06-28 14:57:59 +00:00
|
|
|
|
|
|
|
bool DeviceWidget::onContextTriggerEvent(GdkEventButton* event) {
|
|
|
|
if (GDK_BUTTON_PRESS == event->type && 3 == event->button) {
|
|
|
|
contextMenu.popup(event->button, event->time);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceWidget::renamePopup() {
|
|
|
|
if (updating)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!mpMainWindow->canRenameDevices) {
|
|
|
|
Gtk::MessageDialog dialog(
|
|
|
|
*mpMainWindow,
|
|
|
|
_("Sorry, but device renaming is not supported."),
|
|
|
|
false,
|
|
|
|
Gtk::MESSAGE_WARNING,
|
|
|
|
Gtk::BUTTONS_OK,
|
|
|
|
true);
|
|
|
|
dialog.set_secondary_text(_("You need to load module-device-manager in the PulseAudio server in order to rename devices"));
|
|
|
|
dialog.run();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Gtk::Dialog* dialog;
|
|
|
|
Gtk::Entry* renameText;
|
|
|
|
|
2011-03-03 14:31:14 +00:00
|
|
|
Glib::RefPtr<Gtk::Builder> x = Gtk::Builder::create_from_file(GLADE_FILE, "renameDialog");
|
2009-06-28 14:57:59 +00:00
|
|
|
x->get_widget("renameDialog", dialog);
|
|
|
|
x->get_widget("renameText", renameText);
|
|
|
|
|
|
|
|
renameText->set_text(description);
|
|
|
|
dialog->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
|
|
|
dialog->add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
|
|
|
|
dialog->set_default_response(Gtk::RESPONSE_OK);
|
|
|
|
if (Gtk::RESPONSE_OK == dialog->run()) {
|
|
|
|
pa_operation* o;
|
|
|
|
gchar *key = g_markup_printf_escaped("%s:%s", mDeviceType.c_str(), name.c_str());
|
|
|
|
|
2009-09-20 20:53:31 +00:00
|
|
|
if (!(o = pa_ext_device_manager_set_device_description(get_context(), key, renameText->get_text().c_str(), NULL, NULL))) {
|
2009-06-28 14:57:59 +00:00
|
|
|
show_error(_("pa_ext_device_manager_write() failed"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pa_operation_unref(o);
|
|
|
|
g_free(key);
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|