Initial import

Code from gnome-control-center, build system integration from gnome-shell
This commit is contained in:
Giovanni Campagna 2012-10-19 18:55:52 +02:00
commit 9b6e6719d4
30 changed files with 10904 additions and 0 deletions

65
Makefile.am Normal file
View File

@ -0,0 +1,65 @@
noinst_LTLIBRARIES = libgvc.la
INTROSPECTION_SCANNER_ARGS = --warn-all
libgvc_la_CPPFLAGS = \
$(WARN_CFLAGS) \
$(GVC_CFLAGS) \
-I$(srcdir)/gvc/ \
-DWITH_INTROSPECTION \
-DG_LOG_DOMAIN="\"Gvc\""
libgvc_la_gir_sources = \
gvc-mixer-card.h \
gvc-mixer-card.c \
gvc-mixer-stream.h \
gvc-mixer-stream.c \
gvc-channel-map.h \
gvc-channel-map.c \
gvc-mixer-ui-device.h \
gvc-mixer-ui-device.c \
gvc-mixer-sink.h \
gvc-mixer-sink.c \
gvc-mixer-source.h \
gvc-mixer-source.c \
gvc-mixer-sink-input.h \
gvc-mixer-sink-input.c \
gvc-mixer-source-output.h \
gvc-mixer-source-output.c \
gvc-mixer-event-role.h \
gvc-mixer-event-role.c \
gvc-mixer-control.h \
gvc-mixer-control.c \
gvc-channel-bar.h \
gvc-channel-bar.c \
$(NULL)
libgvc_la_SOURCES = \
$(libgvc_la_gir_sources) \
gvc-mixer-card-private.h \
gvc-mixer-stream-private.h \
gvc-channel-map-private.h \
gvc-mixer-control-private.h \
gvc-pulseaudio-fake.h \
$(NULL)
libgvc_la_LIBADD = \
$(GVC_LIBS) \
$(NULL)
if HAVE_INTROSPECTION
include $(INTROSPECTION_MAKEFILE)
Gvc-1.0.gir: libgvc.la
Gvc_1_0_gir_INCLUDES = GObject-2.0 Gio-2.0 Gtk-3.0
Gvc_1_0_gir_CFLAGS = $(INCLUDES) -I$(srcdir)/gvc -DWITH_INTROSPECTION
Gvc_1_0_gir_LIBS = libgvc.la
Gvc_1_0_gir_FILES = $(addprefix $(srcdir)/,$(libgvc_la_gir_sources))
INTROSPECTION_GIRS = Gvc-1.0.gir
CLEANFILES = Gvc-1.0.gir
typelibdir = $(pkglibdir)
typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
endif

974
gvc-channel-bar.c Normal file
View File

@ -0,0 +1,974 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 William Jon McCann
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <pulse/pulseaudio.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <canberra-gtk.h>
#include "gvc-channel-bar.h"
#include "gvc-mixer-control.h"
#define SCALE_SIZE 128
#define ADJUSTMENT_MAX_NORMAL gvc_mixer_control_get_vol_max_norm(NULL)
#define ADJUSTMENT_MAX_AMPLIFIED gvc_mixer_control_get_vol_max_amplified(NULL)
#define ADJUSTMENT_MAX (bar->priv->is_amplified ? ADJUSTMENT_MAX_AMPLIFIED : ADJUSTMENT_MAX_NORMAL)
#define SCROLLSTEP (ADJUSTMENT_MAX / 100.0 * 5.0)
#define GVC_CHANNEL_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_CHANNEL_BAR, GvcChannelBarPrivate))
struct GvcChannelBarPrivate
{
GtkOrientation orientation;
GtkWidget *scale_box;
GtkWidget *start_box;
GtkWidget *end_box;
GtkWidget *image;
GtkWidget *label;
GtkWidget *low_image;
GtkWidget *scale;
GtkWidget *high_image;
GtkWidget *mute_box;
GtkWidget *mute_switch;
GtkAdjustment *adjustment;
GtkAdjustment *zero_adjustment;
gboolean show_mute;
gboolean is_muted;
char *name;
char *icon_name;
char *low_icon_name;
char *high_icon_name;
GtkSizeGroup *size_group;
gboolean symmetric;
gboolean click_lock;
gboolean is_amplified;
guint32 base_volume;
};
enum
{
PROP_0,
PROP_ORIENTATION,
PROP_SHOW_MUTE,
PROP_IS_MUTED,
PROP_ADJUSTMENT,
PROP_NAME,
PROP_ICON_NAME,
PROP_LOW_ICON_NAME,
PROP_HIGH_ICON_NAME,
PROP_IS_AMPLIFIED,
PROP_ELLIPSIZE
};
static void gvc_channel_bar_class_init (GvcChannelBarClass *klass);
static void gvc_channel_bar_init (GvcChannelBar *channel_bar);
static void gvc_channel_bar_finalize (GObject *object);
static gboolean on_scale_button_press_event (GtkWidget *widget,
GdkEventButton *event,
GvcChannelBar *bar);
static gboolean on_scale_button_release_event (GtkWidget *widget,
GdkEventButton *event,
GvcChannelBar *bar);
static gboolean on_scale_scroll_event (GtkWidget *widget,
GdkEventScroll *event,
GvcChannelBar *bar);
G_DEFINE_TYPE (GvcChannelBar, gvc_channel_bar, GTK_TYPE_HBOX)
static GtkWidget *
_scale_box_new (GvcChannelBar *bar)
{
GvcChannelBarPrivate *priv = bar->priv;
GtkWidget *box;
GtkWidget *sbox;
GtkWidget *ebox;
if (priv->orientation == GTK_ORIENTATION_VERTICAL) {
bar->priv->scale_box = box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
priv->scale = gtk_scale_new (GTK_ORIENTATION_VERTICAL, priv->adjustment);
gtk_widget_set_size_request (priv->scale, -1, SCALE_SIZE);
gtk_range_set_inverted (GTK_RANGE (priv->scale), TRUE);
bar->priv->start_box = sbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_box_pack_start (GTK_BOX (box), sbox, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (sbox), priv->image, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (sbox), priv->label, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (sbox), priv->high_image, FALSE, FALSE, 0);
gtk_widget_hide (priv->high_image);
gtk_box_pack_start (GTK_BOX (box), priv->scale, TRUE, TRUE, 0);
bar->priv->end_box = ebox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_box_pack_start (GTK_BOX (box), ebox, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (ebox), priv->low_image, FALSE, FALSE, 0);
gtk_widget_hide (priv->low_image);
gtk_box_pack_start (GTK_BOX (ebox), priv->mute_box, FALSE, FALSE, 0);
} else {
bar->priv->scale_box = box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (GTK_BOX (box), priv->image, FALSE, FALSE, 0);
priv->scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, priv->adjustment);
gtk_widget_set_size_request (priv->scale, SCALE_SIZE, -1);
bar->priv->start_box = sbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (GTK_BOX (box), sbox, FALSE, FALSE, 0);
gtk_box_pack_end (GTK_BOX (sbox), priv->low_image, FALSE, FALSE, 0);
gtk_widget_show (priv->low_image);
gtk_box_pack_start (GTK_BOX (sbox), priv->label, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box), priv->scale, TRUE, TRUE, 0);
bar->priv->end_box = ebox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (GTK_BOX (box), ebox, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (ebox), priv->high_image, FALSE, FALSE, 0);
gtk_widget_show (priv->high_image);
gtk_box_pack_start (GTK_BOX (ebox), priv->mute_box, FALSE, FALSE, 0);
}
ca_gtk_widget_disable_sounds (bar->priv->scale, FALSE);
gtk_widget_add_events (bar->priv->scale, GDK_SCROLL_MASK);
g_signal_connect (G_OBJECT (bar->priv->scale), "button-press-event",
G_CALLBACK (on_scale_button_press_event), bar);
g_signal_connect (G_OBJECT (bar->priv->scale), "button-release-event",
G_CALLBACK (on_scale_button_release_event), bar);
g_signal_connect (G_OBJECT (bar->priv->scale), "scroll-event",
G_CALLBACK (on_scale_scroll_event), bar);
if (bar->priv->size_group != NULL) {
gtk_size_group_add_widget (bar->priv->size_group, sbox);
if (bar->priv->symmetric) {
gtk_size_group_add_widget (bar->priv->size_group, ebox);
}
}
gtk_scale_set_draw_value (GTK_SCALE (priv->scale), FALSE);
return box;
}
static void
update_image (GvcChannelBar *bar)
{
gtk_image_set_from_icon_name (GTK_IMAGE (bar->priv->image),
bar->priv->icon_name,
GTK_ICON_SIZE_DIALOG);
if (bar->priv->icon_name != NULL) {
gtk_widget_show (bar->priv->image);
} else {
gtk_widget_hide (bar->priv->image);
}
}
static void
update_label (GvcChannelBar *bar)
{
if (bar->priv->name != NULL) {
gtk_label_set_text_with_mnemonic (GTK_LABEL (bar->priv->label),
bar->priv->name);
gtk_label_set_mnemonic_widget (GTK_LABEL (bar->priv->label),
bar->priv->scale);
gtk_widget_show (bar->priv->label);
} else {
gtk_label_set_text (GTK_LABEL (bar->priv->label), NULL);
gtk_widget_hide (bar->priv->label);
}
}
static void
update_layout (GvcChannelBar *bar)
{
GtkWidget *box;
GtkWidget *frame;
if (bar->priv->scale == NULL) {
return;
}
box = bar->priv->scale_box;
frame = gtk_widget_get_parent (box);
g_object_ref (bar->priv->image);
g_object_ref (bar->priv->label);
g_object_ref (bar->priv->mute_box);
g_object_ref (bar->priv->low_image);
g_object_ref (bar->priv->high_image);
gtk_container_remove (GTK_CONTAINER (bar->priv->start_box), bar->priv->image);
gtk_container_remove (GTK_CONTAINER (bar->priv->start_box), bar->priv->label);
gtk_container_remove (GTK_CONTAINER (bar->priv->end_box), bar->priv->mute_box);
if (bar->priv->orientation == GTK_ORIENTATION_VERTICAL) {
gtk_container_remove (GTK_CONTAINER (bar->priv->start_box), bar->priv->low_image);
gtk_container_remove (GTK_CONTAINER (bar->priv->end_box), bar->priv->high_image);
} else {
gtk_container_remove (GTK_CONTAINER (bar->priv->end_box), bar->priv->low_image);
gtk_container_remove (GTK_CONTAINER (bar->priv->start_box), bar->priv->high_image);
}
gtk_container_remove (GTK_CONTAINER (box), bar->priv->start_box);
gtk_container_remove (GTK_CONTAINER (box), bar->priv->scale);
gtk_container_remove (GTK_CONTAINER (box), bar->priv->end_box);
gtk_container_remove (GTK_CONTAINER (frame), box);
bar->priv->scale_box = _scale_box_new (bar);
gtk_container_add (GTK_CONTAINER (frame), bar->priv->scale_box);
g_object_unref (bar->priv->image);
g_object_unref (bar->priv->label);
g_object_unref (bar->priv->mute_box);
g_object_unref (bar->priv->low_image);
g_object_unref (bar->priv->high_image);
gtk_widget_show_all (frame);
}
void
gvc_channel_bar_set_size_group (GvcChannelBar *bar,
GtkSizeGroup *group,
gboolean symmetric)
{
g_return_if_fail (GVC_IS_CHANNEL_BAR (bar));
bar->priv->size_group = group;
bar->priv->symmetric = symmetric;
if (bar->priv->size_group != NULL) {
gtk_size_group_add_widget (bar->priv->size_group,
bar->priv->start_box);
if (bar->priv->symmetric) {
gtk_size_group_add_widget (bar->priv->size_group,
bar->priv->end_box);
}
}
gtk_widget_queue_draw (GTK_WIDGET (bar));
}
void
gvc_channel_bar_set_name (GvcChannelBar *bar,
const char *name)
{
g_return_if_fail (GVC_IS_CHANNEL_BAR (bar));
g_free (bar->priv->name);
bar->priv->name = g_strdup (name);
update_label (bar);
g_object_notify (G_OBJECT (bar), "name");
}
void
gvc_channel_bar_set_icon_name (GvcChannelBar *bar,
const char *name)
{
g_return_if_fail (GVC_IS_CHANNEL_BAR (bar));
g_free (bar->priv->icon_name);
bar->priv->icon_name = g_strdup (name);
update_image (bar);
g_object_notify (G_OBJECT (bar), "icon-name");
}
void
gvc_channel_bar_set_low_icon_name (GvcChannelBar *bar,
const char *name)
{
g_return_if_fail (GVC_IS_CHANNEL_BAR (bar));
if (name != NULL && strcmp (bar->priv->low_icon_name, name) != 0) {
g_free (bar->priv->low_icon_name);
bar->priv->low_icon_name = g_strdup (name);
gtk_image_set_from_icon_name (GTK_IMAGE (bar->priv->low_image),
bar->priv->low_icon_name,
GTK_ICON_SIZE_MENU);
g_object_notify (G_OBJECT (bar), "low-icon-name");
}
}
void
gvc_channel_bar_set_high_icon_name (GvcChannelBar *bar,
const char *name)
{
g_return_if_fail (GVC_IS_CHANNEL_BAR (bar));
if (name != NULL && strcmp (bar->priv->high_icon_name, name) != 0) {
g_free (bar->priv->high_icon_name);
bar->priv->high_icon_name = g_strdup (name);
gtk_image_set_from_icon_name (GTK_IMAGE (bar->priv->high_image),
bar->priv->high_icon_name,
GTK_ICON_SIZE_MENU);
g_object_notify (G_OBJECT (bar), "high-icon-name");
}
}
void
gvc_channel_bar_set_orientation (GvcChannelBar *bar,
GtkOrientation orientation)
{
g_return_if_fail (GVC_IS_CHANNEL_BAR (bar));
if (orientation != bar->priv->orientation) {
bar->priv->orientation = orientation;
update_layout (bar);
g_object_notify (G_OBJECT (bar), "orientation");
}
}
static void
gvc_channel_bar_set_adjustment (GvcChannelBar *bar,
GtkAdjustment *adjustment)
{
g_return_if_fail (GVC_CHANNEL_BAR (bar));
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
if (bar->priv->adjustment != NULL) {
g_object_unref (bar->priv->adjustment);
}
bar->priv->adjustment = g_object_ref_sink (adjustment);
if (bar->priv->scale != NULL) {
gtk_range_set_adjustment (GTK_RANGE (bar->priv->scale), adjustment);
}
g_object_notify (G_OBJECT (bar), "adjustment");
}
GtkAdjustment *
gvc_channel_bar_get_adjustment (GvcChannelBar *bar)
{
g_return_val_if_fail (GVC_IS_CHANNEL_BAR (bar), NULL);
return bar->priv->adjustment;
}
static gboolean
on_scale_button_press_event (GtkWidget *widget,
GdkEventButton *event,
GvcChannelBar *bar)
{
bar->priv->click_lock = TRUE;
return FALSE;
}
static gboolean
on_scale_button_release_event (GtkWidget *widget,
GdkEventButton *event,
GvcChannelBar *bar)
{
GtkAdjustment *adj;
gdouble value;
bar->priv->click_lock = FALSE;
adj = gtk_range_get_adjustment (GTK_RANGE (widget));
value = gtk_adjustment_get_value (adj);
/* this means the adjustment moved away from zero and
* therefore we should unmute and set the volume. */
gvc_channel_bar_set_is_muted (bar, (value == 0.0));
/* Play a sound! */
ca_gtk_play_for_widget (GTK_WIDGET (bar), 0,
CA_PROP_EVENT_ID, "audio-volume-change",
CA_PROP_EVENT_DESCRIPTION, "foobar event happened",
CA_PROP_APPLICATION_ID, "org.gnome.VolumeControl",
NULL);
return FALSE;
}
gboolean
gvc_channel_bar_scroll (GvcChannelBar *bar, GdkEventScroll *event)
{
GtkAdjustment *adj;
gdouble value;
GdkScrollDirection direction;
gdouble dx, dy;
g_return_val_if_fail (bar != NULL, FALSE);
g_return_val_if_fail (GVC_IS_CHANNEL_BAR (bar), FALSE);
direction = event->direction;
if (bar->priv->orientation == GTK_ORIENTATION_VERTICAL) {
if (direction == GDK_SCROLL_LEFT || direction == GDK_SCROLL_RIGHT)
return FALSE;
} else {
/* Switch direction for RTL */
if (gtk_widget_get_direction (GTK_WIDGET (bar)) == GTK_TEXT_DIR_RTL) {
if (direction == GDK_SCROLL_RIGHT)
direction = GDK_SCROLL_LEFT;
else if (direction == GDK_SCROLL_LEFT)
direction = GDK_SCROLL_RIGHT;
}
/* Switch side scroll to vertical */
if (direction == GDK_SCROLL_RIGHT)
direction = GDK_SCROLL_UP;
else if (direction == GDK_SCROLL_LEFT)
direction = GDK_SCROLL_DOWN;
}
if (!gdk_event_get_scroll_deltas ((GdkEvent*)event, &dx, &dy)) {
dx = 0.0;
dy = 0.0;
switch (direction) {
case GDK_SCROLL_UP:
case GDK_SCROLL_LEFT:
dy = 1.0;
break;
case GDK_SCROLL_DOWN:
case GDK_SCROLL_RIGHT:
dy = -1.0;
break;
default:
;
}
}
adj = gtk_range_get_adjustment (GTK_RANGE (bar->priv->scale));
if (adj == bar->priv->zero_adjustment) {
if (dy > 0)
gvc_channel_bar_set_is_muted (bar, FALSE);
return TRUE;
}
value = gtk_adjustment_get_value (adj);
if (dy > 0) {
if (value + dy * SCROLLSTEP > ADJUSTMENT_MAX)
value = ADJUSTMENT_MAX;
else
value = value + dy * SCROLLSTEP;
} else if (dy < 0) {
if (value + dy * SCROLLSTEP < 0)
value = 0.0;
else
value = value + dy * SCROLLSTEP;
}
gvc_channel_bar_set_is_muted (bar, (value == 0.0));
adj = gtk_range_get_adjustment (GTK_RANGE (bar->priv->scale));
gtk_adjustment_set_value (adj, value);
return TRUE;
}
static gboolean
on_scale_scroll_event (GtkWidget *widget,
GdkEventScroll *event,
GvcChannelBar *bar)
{
return gvc_channel_bar_scroll (bar, event);
}
static void
on_zero_adjustment_value_changed (GtkAdjustment *adjustment,
GvcChannelBar *bar)
{
gdouble value;
if (bar->priv->click_lock != FALSE) {
return;
}
value = gtk_adjustment_get_value (bar->priv->zero_adjustment);
gtk_adjustment_set_value (bar->priv->adjustment, value);
if (bar->priv->show_mute == FALSE) {
/* this means the adjustment moved away from zero and
* therefore we should unmute and set the volume. */
gvc_channel_bar_set_is_muted (bar, value > 0.0);
}
}
static void
update_mute_switch (GvcChannelBar *bar)
{
if (bar->priv->show_mute) {
gtk_widget_show (bar->priv->mute_switch);
gtk_switch_set_active (GTK_SWITCH (bar->priv->mute_switch),
!bar->priv->is_muted);
} else {
gtk_widget_hide (bar->priv->mute_switch);
}
if (bar->priv->is_muted) {
/* If we aren't showing the mute button then
* move slider to the zero. But we don't want to
* change the adjustment. */
g_signal_handlers_block_by_func (bar->priv->zero_adjustment,
on_zero_adjustment_value_changed,
bar);
gtk_adjustment_set_value (bar->priv->zero_adjustment, 0);
g_signal_handlers_unblock_by_func (bar->priv->zero_adjustment,
on_zero_adjustment_value_changed,
bar);
gtk_range_set_adjustment (GTK_RANGE (bar->priv->scale),
bar->priv->zero_adjustment);
} else {
/* no longer muted so restore the original adjustment
* and tell the front-end that the value changed */
gtk_range_set_adjustment (GTK_RANGE (bar->priv->scale),
bar->priv->adjustment);
gtk_adjustment_value_changed (bar->priv->adjustment);
}
}
void
gvc_channel_bar_set_is_muted (GvcChannelBar *bar,
gboolean is_muted)
{
g_return_if_fail (GVC_IS_CHANNEL_BAR (bar));
if (is_muted != bar->priv->is_muted) {
/* Update our internal state before telling the
* front-end about our changes */
bar->priv->is_muted = is_muted;
update_mute_switch (bar);
g_object_notify (G_OBJECT (bar), "is-muted");
}
}
gboolean
gvc_channel_bar_get_is_muted (GvcChannelBar *bar)
{
g_return_val_if_fail (GVC_IS_CHANNEL_BAR (bar), FALSE);
return bar->priv->is_muted;
}
void
gvc_channel_bar_set_show_mute (GvcChannelBar *bar,
gboolean show_mute)
{
g_return_if_fail (GVC_IS_CHANNEL_BAR (bar));
if (show_mute != bar->priv->show_mute) {
bar->priv->show_mute = show_mute;
g_object_notify (G_OBJECT (bar), "show-mute");
update_mute_switch (bar);
}
}
gboolean
gvc_channel_bar_get_show_mute (GvcChannelBar *bar)
{
g_return_val_if_fail (GVC_IS_CHANNEL_BAR (bar), FALSE);
return bar->priv->show_mute;
}
void
gvc_channel_bar_set_is_amplified (GvcChannelBar *bar, gboolean amplified)
{
g_return_if_fail (GVC_IS_CHANNEL_BAR (bar));
bar->priv->is_amplified = amplified;
gtk_adjustment_set_upper (bar->priv->adjustment, ADJUSTMENT_MAX);
gtk_adjustment_set_upper (bar->priv->zero_adjustment, ADJUSTMENT_MAX);
gtk_scale_clear_marks (GTK_SCALE (bar->priv->scale));
if (amplified) {
char *str;
if (bar->priv->base_volume == ADJUSTMENT_MAX_NORMAL) {
str = g_strdup_printf ("<small>%s</small>", C_("volume", "100%"));
gtk_scale_add_mark (GTK_SCALE (bar->priv->scale), ADJUSTMENT_MAX_NORMAL,
GTK_POS_BOTTOM, str);
} else {
str = g_strdup_printf ("<small>%s</small>", C_("volume", "Unamplified"));
gtk_scale_add_mark (GTK_SCALE (bar->priv->scale), bar->priv->base_volume,
GTK_POS_BOTTOM, str);
/* Only show 100% if it's higher than the base volume */
if (bar->priv->base_volume < ADJUSTMENT_MAX_NORMAL) {
str = g_strdup_printf ("<small>%s</small>", C_("volume", "100%"));
gtk_scale_add_mark (GTK_SCALE (bar->priv->scale), ADJUSTMENT_MAX_NORMAL,
GTK_POS_BOTTOM, str);
}
}
g_free (str);
gtk_alignment_set (GTK_ALIGNMENT (bar->priv->mute_box), 0.5, 0, 0, 0);
gtk_misc_set_alignment (GTK_MISC (bar->priv->low_image), 0.5, 0.15);
gtk_misc_set_alignment (GTK_MISC (bar->priv->high_image), 0.5, 0.15);
gtk_misc_set_alignment (GTK_MISC (bar->priv->label), 0, 0);
} else {
gtk_alignment_set (GTK_ALIGNMENT (bar->priv->mute_box), 0.5, 0.5, 0, 0);
gtk_misc_set_alignment (GTK_MISC (bar->priv->low_image), 0.5, 0.5);
gtk_misc_set_alignment (GTK_MISC (bar->priv->high_image), 0.5, 0.5);
gtk_misc_set_alignment (GTK_MISC (bar->priv->label), 0, 0.5);
}
}
gboolean
gvc_channel_bar_get_ellipsize (GvcChannelBar *bar)
{
g_return_val_if_fail (GVC_IS_CHANNEL_BAR (bar), FALSE);
return gtk_label_get_ellipsize (GTK_LABEL (bar->priv->label)) != PANGO_ELLIPSIZE_NONE;
}
void
gvc_channel_bar_set_ellipsize (GvcChannelBar *bar,
gboolean ellipsized)
{
g_return_if_fail (GVC_IS_CHANNEL_BAR (bar));
if (ellipsized)
gtk_label_set_ellipsize (GTK_LABEL (bar->priv->label), PANGO_ELLIPSIZE_END);
else
gtk_label_set_ellipsize (GTK_LABEL (bar->priv->label), PANGO_ELLIPSIZE_NONE);
}
void
gvc_channel_bar_set_base_volume (GvcChannelBar *bar,
pa_volume_t base_volume)
{
g_return_if_fail (GVC_IS_CHANNEL_BAR (bar));
if (base_volume == 0) {
bar->priv->base_volume = ADJUSTMENT_MAX_NORMAL;
return;
}
/* Note that you need to call _is_amplified() afterwards to update the marks */
bar->priv->base_volume = base_volume;
}
static void
gvc_channel_bar_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GvcChannelBar *self = GVC_CHANNEL_BAR (object);
switch (prop_id) {
case PROP_ORIENTATION:
gvc_channel_bar_set_orientation (self, g_value_get_enum (value));
break;
case PROP_IS_MUTED:
gvc_channel_bar_set_is_muted (self, g_value_get_boolean (value));
break;
case PROP_SHOW_MUTE:
gvc_channel_bar_set_show_mute (self, g_value_get_boolean (value));
break;
case PROP_NAME:
gvc_channel_bar_set_name (self, g_value_get_string (value));
break;
case PROP_ICON_NAME:
gvc_channel_bar_set_icon_name (self, g_value_get_string (value));
break;
case PROP_LOW_ICON_NAME:
gvc_channel_bar_set_low_icon_name (self, g_value_get_string (value));
break;
case PROP_HIGH_ICON_NAME:
gvc_channel_bar_set_high_icon_name (self, g_value_get_string (value));
break;
case PROP_ADJUSTMENT:
gvc_channel_bar_set_adjustment (self, g_value_get_object (value));
break;
case PROP_IS_AMPLIFIED:
gvc_channel_bar_set_is_amplified (self, g_value_get_boolean (value));
break;
case PROP_ELLIPSIZE:
gvc_channel_bar_set_ellipsize (self, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gvc_channel_bar_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GvcChannelBar *self = GVC_CHANNEL_BAR (object);
GvcChannelBarPrivate *priv = self->priv;
switch (prop_id) {
case PROP_ORIENTATION:
g_value_set_enum (value, priv->orientation);
break;
case PROP_IS_MUTED:
g_value_set_boolean (value, priv->is_muted);
break;
case PROP_SHOW_MUTE:
g_value_set_boolean (value, priv->show_mute);
break;
case PROP_NAME:
g_value_set_string (value, priv->name);
break;
case PROP_ICON_NAME:
g_value_set_string (value, priv->icon_name);
break;
case PROP_LOW_ICON_NAME:
g_value_set_string (value, priv->low_icon_name);
break;
case PROP_HIGH_ICON_NAME:
g_value_set_string (value, priv->high_icon_name);
break;
case PROP_ADJUSTMENT:
g_value_set_object (value, gvc_channel_bar_get_adjustment (self));
break;
case PROP_IS_AMPLIFIED:
g_value_set_boolean (value, priv->is_amplified);
break;
case PROP_ELLIPSIZE:
g_value_set_boolean (value, gvc_channel_bar_get_ellipsize (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static GObject *
gvc_channel_bar_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_params)
{
GObject *object;
GvcChannelBar *self;
object = G_OBJECT_CLASS (gvc_channel_bar_parent_class)->constructor (type, n_construct_properties, construct_params);
self = GVC_CHANNEL_BAR (object);
update_mute_switch (self);
return object;
}
static void
gvc_channel_bar_class_init (GvcChannelBarClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructor = gvc_channel_bar_constructor;
object_class->finalize = gvc_channel_bar_finalize;
object_class->set_property = gvc_channel_bar_set_property;
object_class->get_property = gvc_channel_bar_get_property;
g_object_class_install_property (object_class,
PROP_ORIENTATION,
g_param_spec_enum ("orientation",
"Orientation",
"The orientation of the scale",
GTK_TYPE_ORIENTATION,
GTK_ORIENTATION_VERTICAL,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_IS_MUTED,
g_param_spec_boolean ("is-muted",
"is muted",
"Whether stream is muted",
FALSE,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_SHOW_MUTE,
g_param_spec_boolean ("show-mute",
"show mute",
"Whether stream is muted",
FALSE,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_ADJUSTMENT,
g_param_spec_object ("adjustment",
"Adjustment",
"The GtkAdjustment that contains the current value of this scale button object",
GTK_TYPE_ADJUSTMENT,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_NAME,
g_param_spec_string ("name",
"Name",
"Name to display for this stream",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_ICON_NAME,
g_param_spec_string ("icon-name",
"Icon Name",
"Name of icon to display for this stream",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_LOW_ICON_NAME,
g_param_spec_string ("low-icon-name",
"Icon Name",
"Name of icon to display for this stream",
"audio-volume-low-symbolic",
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_HIGH_ICON_NAME,
g_param_spec_string ("high-icon-name",
"Icon Name",
"Name of icon to display for this stream",
"audio-volume-high-symbolic",
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_IS_AMPLIFIED,
g_param_spec_boolean ("is-amplified",
"Is amplified",
"Whether the stream is digitally amplified",
FALSE,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_ELLIPSIZE,
g_param_spec_boolean ("ellipsize",
"Label is ellipsized",
"Whether the label is ellipsized",
FALSE,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_type_class_add_private (klass, sizeof (GvcChannelBarPrivate));
}
static void
on_mute_switch_toggled (GtkSwitch *sw,
GParamSpec *pspec,
GvcChannelBar *bar)
{
gboolean is_muted;
is_muted = gtk_switch_get_active (sw);
gvc_channel_bar_set_is_muted (bar, !is_muted);
}
static void
gvc_channel_bar_init (GvcChannelBar *bar)
{
GtkWidget *frame;
bar->priv = GVC_CHANNEL_BAR_GET_PRIVATE (bar);
bar->priv->base_volume = ADJUSTMENT_MAX_NORMAL;
bar->priv->low_icon_name = g_strdup ("audio-volume-low-symbolic");
bar->priv->high_icon_name = g_strdup ("audio-volume-high-symbolic");
bar->priv->orientation = GTK_ORIENTATION_VERTICAL;
bar->priv->adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0,
0.0,
ADJUSTMENT_MAX_NORMAL,
ADJUSTMENT_MAX_NORMAL/100.0,
ADJUSTMENT_MAX_NORMAL/10.0,
0.0));
g_object_ref_sink (bar->priv->adjustment);
bar->priv->zero_adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0,
0.0,
ADJUSTMENT_MAX_NORMAL,
ADJUSTMENT_MAX_NORMAL/100.0,
ADJUSTMENT_MAX_NORMAL/10.0,
0.0));
g_object_ref_sink (bar->priv->zero_adjustment);
g_signal_connect (bar->priv->zero_adjustment,
"value-changed",
G_CALLBACK (on_zero_adjustment_value_changed),
bar);
bar->priv->mute_switch = gtk_switch_new ();
gtk_widget_set_no_show_all (bar->priv->mute_switch, TRUE);
g_signal_connect (bar->priv->mute_switch,
"notify::active",
G_CALLBACK (on_mute_switch_toggled),
bar);
bar->priv->mute_box = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_container_add (GTK_CONTAINER (bar->priv->mute_box), bar->priv->mute_switch);
bar->priv->low_image = gtk_image_new_from_icon_name ("audio-volume-low-symbolic",
GTK_ICON_SIZE_MENU);
gtk_widget_set_no_show_all (bar->priv->low_image, TRUE);
bar->priv->high_image = gtk_image_new_from_icon_name ("audio-volume-high-symbolic",
GTK_ICON_SIZE_MENU);
gtk_widget_set_no_show_all (bar->priv->high_image, TRUE);
bar->priv->image = gtk_image_new ();
gtk_widget_set_no_show_all (bar->priv->image, TRUE);
bar->priv->label = gtk_label_new (NULL);
gtk_misc_set_alignment (GTK_MISC (bar->priv->label), 0.0, 0.5);
gtk_widget_set_no_show_all (bar->priv->label, TRUE);
/* frame */
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
gtk_container_add (GTK_CONTAINER (bar), frame);
gtk_widget_show_all (frame);
/* box with scale */
bar->priv->scale_box = _scale_box_new (bar);
gtk_container_add (GTK_CONTAINER (frame), bar->priv->scale_box);
}
static void
gvc_channel_bar_finalize (GObject *object)
{
GvcChannelBar *channel_bar;
g_return_if_fail (object != NULL);
g_return_if_fail (GVC_IS_CHANNEL_BAR (object));
channel_bar = GVC_CHANNEL_BAR (object);
g_return_if_fail (channel_bar->priv != NULL);
g_free (channel_bar->priv->name);
g_free (channel_bar->priv->icon_name);
g_free (channel_bar->priv->low_icon_name);
g_free (channel_bar->priv->high_icon_name);
G_OBJECT_CLASS (gvc_channel_bar_parent_class)->finalize (object);
}
GtkWidget *
gvc_channel_bar_new (void)
{
GObject *bar;
bar = g_object_new (GVC_TYPE_CHANNEL_BAR,
NULL);
return GTK_WIDGET (bar);
}

89
gvc-channel-bar.h Normal file
View File

@ -0,0 +1,89 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_CHANNEL_BAR_H
#define __GVC_CHANNEL_BAR_H
#include <glib-object.h>
G_BEGIN_DECLS
#define GVC_TYPE_CHANNEL_BAR (gvc_channel_bar_get_type ())
#define GVC_CHANNEL_BAR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_CHANNEL_BAR, GvcChannelBar))
#define GVC_CHANNEL_BAR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_CHANNEL_BAR, GvcChannelBarClass))
#define GVC_IS_CHANNEL_BAR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_CHANNEL_BAR))
#define GVC_IS_CHANNEL_BAR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_CHANNEL_BAR))
#define GVC_CHANNEL_BAR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_CHANNEL_BAR, GvcChannelBarClass))
typedef struct GvcChannelBarPrivate GvcChannelBarPrivate;
typedef struct
{
GtkHBox parent;
GvcChannelBarPrivate *priv;
} GvcChannelBar;
typedef struct
{
GtkHBoxClass parent_class;
} GvcChannelBarClass;
GType gvc_channel_bar_get_type (void);
GtkWidget * gvc_channel_bar_new (void);
void gvc_channel_bar_set_name (GvcChannelBar *bar,
const char *name);
void gvc_channel_bar_set_icon_name (GvcChannelBar *bar,
const char *icon_name);
void gvc_channel_bar_set_low_icon_name (GvcChannelBar *bar,
const char *icon_name);
void gvc_channel_bar_set_high_icon_name (GvcChannelBar *bar,
const char *icon_name);
void gvc_channel_bar_set_orientation (GvcChannelBar *bar,
GtkOrientation orientation);
GtkOrientation gvc_channel_bar_get_orientation (GvcChannelBar *bar);
GtkAdjustment * gvc_channel_bar_get_adjustment (GvcChannelBar *bar);
gboolean gvc_channel_bar_get_is_muted (GvcChannelBar *bar);
void gvc_channel_bar_set_is_muted (GvcChannelBar *bar,
gboolean is_muted);
gboolean gvc_channel_bar_get_show_mute (GvcChannelBar *bar);
void gvc_channel_bar_set_show_mute (GvcChannelBar *bar,
gboolean show_mute);
void gvc_channel_bar_set_size_group (GvcChannelBar *bar,
GtkSizeGroup *group,
gboolean symmetric);
void gvc_channel_bar_set_is_amplified (GvcChannelBar *bar,
gboolean amplified);
void gvc_channel_bar_set_base_volume (GvcChannelBar *bar,
guint32 base_volume);
gboolean gvc_channel_bar_get_ellipsize (GvcChannelBar *bar);
void gvc_channel_bar_set_ellipsize (GvcChannelBar *bar,
gboolean ellipsized);
gboolean gvc_channel_bar_scroll (GvcChannelBar *bar,
GdkEventScroll *event);
G_END_DECLS
#endif /* __GVC_CHANNEL_BAR_H */

39
gvc-channel-map-private.h Normal file
View File

@ -0,0 +1,39 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_CHANNEL_MAP_PRIVATE_H
#define __GVC_CHANNEL_MAP_PRIVATE_H
#include <glib-object.h>
#include <pulse/pulseaudio.h>
G_BEGIN_DECLS
GvcChannelMap * gvc_channel_map_new_from_pa_channel_map (const pa_channel_map *map);
const pa_channel_map * gvc_channel_map_get_pa_channel_map (const GvcChannelMap *map);
void gvc_channel_map_volume_changed (GvcChannelMap *map,
const pa_cvolume *cv,
gboolean set);
const pa_cvolume * gvc_channel_map_get_cvolume (const GvcChannelMap *map);
G_END_DECLS
#endif /* __GVC_CHANNEL_MAP_PRIVATE_H */

254
gvc-channel-map.c Normal file
View File

@ -0,0 +1,254 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 William Jon McCann
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <pulse/pulseaudio.h>
#include "gvc-channel-map.h"
#include "gvc-channel-map-private.h"
#define GVC_CHANNEL_MAP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_CHANNEL_MAP, GvcChannelMapPrivate))
struct GvcChannelMapPrivate
{
pa_channel_map pa_map;
gboolean pa_volume_is_set;
pa_cvolume pa_volume;
gdouble extern_volume[NUM_TYPES]; /* volume, balance, fade, lfe */
gboolean can_balance;
gboolean can_fade;
};
enum {
VOLUME_CHANGED,
LAST_SIGNAL
};
static guint signals [LAST_SIGNAL] = { 0, };
static void gvc_channel_map_class_init (GvcChannelMapClass *klass);
static void gvc_channel_map_init (GvcChannelMap *channel_map);
static void gvc_channel_map_finalize (GObject *object);
G_DEFINE_TYPE (GvcChannelMap, gvc_channel_map, G_TYPE_OBJECT)
guint
gvc_channel_map_get_num_channels (const GvcChannelMap *map)
{
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), 0);
if (!pa_channel_map_valid(&map->priv->pa_map))
return 0;
return map->priv->pa_map.channels;
}
const gdouble *
gvc_channel_map_get_volume (GvcChannelMap *map)
{
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
if (!pa_channel_map_valid(&map->priv->pa_map))
return NULL;
map->priv->extern_volume[VOLUME] = (gdouble) pa_cvolume_max (&map->priv->pa_volume);
if (gvc_channel_map_can_balance (map))
map->priv->extern_volume[BALANCE] = (gdouble) pa_cvolume_get_balance (&map->priv->pa_volume, &map->priv->pa_map);
else
map->priv->extern_volume[BALANCE] = 0;
if (gvc_channel_map_can_fade (map))
map->priv->extern_volume[FADE] = (gdouble) pa_cvolume_get_fade (&map->priv->pa_volume, &map->priv->pa_map);
else
map->priv->extern_volume[FADE] = 0;
if (gvc_channel_map_has_lfe (map))
map->priv->extern_volume[LFE] = (gdouble) pa_cvolume_get_position (&map->priv->pa_volume, &map->priv->pa_map, PA_CHANNEL_POSITION_LFE);
else
map->priv->extern_volume[LFE] = 0;
return map->priv->extern_volume;
}
gboolean
gvc_channel_map_can_balance (const GvcChannelMap *map)
{
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
return map->priv->can_balance;
}
gboolean
gvc_channel_map_can_fade (const GvcChannelMap *map)
{
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
return map->priv->can_fade;
}
const char *
gvc_channel_map_get_mapping (const GvcChannelMap *map)
{
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
if (!pa_channel_map_valid(&map->priv->pa_map))
return NULL;
return pa_channel_map_to_pretty_name (&map->priv->pa_map);
}
/**
* gvc_channel_map_has_position: (skip)
*
* @map:
* @position:
*
* Returns:
*/
gboolean
gvc_channel_map_has_position (const GvcChannelMap *map,
pa_channel_position_t position)
{
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
return pa_channel_map_has_position (&(map->priv->pa_map), position);
}
const pa_channel_map *
gvc_channel_map_get_pa_channel_map (const GvcChannelMap *map)
{
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
if (!pa_channel_map_valid(&map->priv->pa_map))
return NULL;
return &map->priv->pa_map;
}
const pa_cvolume *
gvc_channel_map_get_cvolume (const GvcChannelMap *map)
{
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
if (!pa_channel_map_valid(&map->priv->pa_map))
return NULL;
return &map->priv->pa_volume;
}
static void
gvc_channel_map_class_init (GvcChannelMapClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = gvc_channel_map_finalize;
signals [VOLUME_CHANGED] =
g_signal_new ("volume-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GvcChannelMapClass, volume_changed),
NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
g_type_class_add_private (klass, sizeof (GvcChannelMapPrivate));
}
void
gvc_channel_map_volume_changed (GvcChannelMap *map,
const pa_cvolume *cv,
gboolean set)
{
g_return_if_fail (GVC_IS_CHANNEL_MAP (map));
g_return_if_fail (cv != NULL);
g_return_if_fail (pa_cvolume_compatible_with_channel_map(cv, &map->priv->pa_map));
if (pa_cvolume_equal(cv, &map->priv->pa_volume))
return;
map->priv->pa_volume = *cv;
if (map->priv->pa_volume_is_set == FALSE) {
map->priv->pa_volume_is_set = TRUE;
return;
}
g_signal_emit (map, signals[VOLUME_CHANGED], 0, set);
}
static void
gvc_channel_map_init (GvcChannelMap *map)
{
map->priv = GVC_CHANNEL_MAP_GET_PRIVATE (map);
map->priv->pa_volume_is_set = FALSE;
}
static void
gvc_channel_map_finalize (GObject *object)
{
GvcChannelMap *channel_map;
g_return_if_fail (object != NULL);
g_return_if_fail (GVC_IS_CHANNEL_MAP (object));
channel_map = GVC_CHANNEL_MAP (object);
g_return_if_fail (channel_map->priv != NULL);
G_OBJECT_CLASS (gvc_channel_map_parent_class)->finalize (object);
}
GvcChannelMap *
gvc_channel_map_new (void)
{
GObject *map;
map = g_object_new (GVC_TYPE_CHANNEL_MAP, NULL);
return GVC_CHANNEL_MAP (map);
}
static void
set_from_pa_map (GvcChannelMap *map,
const pa_channel_map *pa_map)
{
g_assert (pa_channel_map_valid(pa_map));
map->priv->can_balance = pa_channel_map_can_balance (pa_map);
map->priv->can_fade = pa_channel_map_can_fade (pa_map);
map->priv->pa_map = *pa_map;
pa_cvolume_set(&map->priv->pa_volume, pa_map->channels, PA_VOLUME_NORM);
}
GvcChannelMap *
gvc_channel_map_new_from_pa_channel_map (const pa_channel_map *pa_map)
{
GObject *map;
map = g_object_new (GVC_TYPE_CHANNEL_MAP, NULL);
set_from_pa_map (GVC_CHANNEL_MAP (map), pa_map);
return GVC_CHANNEL_MAP (map);
}

73
gvc-channel-map.h Normal file
View File

@ -0,0 +1,73 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_CHANNEL_MAP_H
#define __GVC_CHANNEL_MAP_H
#include <glib-object.h>
#include <gvc-pulseaudio-fake.h>
G_BEGIN_DECLS
#define GVC_TYPE_CHANNEL_MAP (gvc_channel_map_get_type ())
#define GVC_CHANNEL_MAP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_CHANNEL_MAP, GvcChannelMap))
#define GVC_CHANNEL_MAP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_CHANNEL_MAP, GvcChannelMapClass))
#define GVC_IS_CHANNEL_MAP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_CHANNEL_MAP))
#define GVC_IS_CHANNEL_MAP_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_CHANNEL_MAP))
#define GVC_CHANNEL_MAP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_CHANNEL_MAP, GvcChannelMapClass))
typedef struct GvcChannelMapPrivate GvcChannelMapPrivate;
typedef struct
{
GObject parent;
GvcChannelMapPrivate *priv;
} GvcChannelMap;
typedef struct
{
GObjectClass parent_class;
void (*volume_changed) (GvcChannelMap *channel_map, gboolean set);
} GvcChannelMapClass;
enum {
VOLUME,
BALANCE,
FADE,
LFE,
NUM_TYPES
};
GType gvc_channel_map_get_type (void);
GvcChannelMap * gvc_channel_map_new (void);
guint gvc_channel_map_get_num_channels (const GvcChannelMap *map);
const gdouble * gvc_channel_map_get_volume (GvcChannelMap *map);
gboolean gvc_channel_map_can_balance (const GvcChannelMap *map);
gboolean gvc_channel_map_can_fade (const GvcChannelMap *map);
gboolean gvc_channel_map_has_position (const GvcChannelMap *map,
pa_channel_position_t position);
#define gvc_channel_map_has_lfe(x) gvc_channel_map_has_position (x, PA_CHANNEL_POSITION_LFE)
const char * gvc_channel_map_get_mapping (const GvcChannelMap *map);
G_END_DECLS
#endif /* __GVC_CHANNEL_MAP_H */

35
gvc-mixer-card-private.h Normal file
View File

@ -0,0 +1,35 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008-2009 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_MIXER_CARD_PRIVATE_H
#define __GVC_MIXER_CARD_PRIVATE_H
#include <pulse/pulseaudio.h>
#include "gvc-mixer-card.h"
G_BEGIN_DECLS
GvcMixerCard * gvc_mixer_card_new (pa_context *context,
guint index);
pa_context * gvc_mixer_card_get_pa_context (GvcMixerCard *card);
G_END_DECLS
#endif /* __GVC_MIXER_CARD_PRIVATE_H */

570
gvc-mixer-card.c Normal file
View File

@ -0,0 +1,570 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 William Jon McCann
* Copyright (C) 2009 Bastien Nocera
* Copyright (C) Conor Curran 2011 <conor.curran@canonical.com>
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <pulse/pulseaudio.h>
#include "gvc-mixer-card.h"
#include "gvc-mixer-card-private.h"
#define GVC_MIXER_CARD_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_CARD, GvcMixerCardPrivate))
static guint32 card_serial = 1;
struct GvcMixerCardPrivate
{
pa_context *pa_context;
guint id;
guint index;
char *name;
char *icon_name;
char *profile;
char *target_profile;
char *human_profile;
GList *profiles;
pa_operation *profile_op;
GList *ports;
};
enum
{
PROP_0,
PROP_ID,
PROP_PA_CONTEXT,
PROP_INDEX,
PROP_NAME,
PROP_ICON_NAME,
PROP_PROFILE,
PROP_HUMAN_PROFILE,
};
static void gvc_mixer_card_class_init (GvcMixerCardClass *klass);
static void gvc_mixer_card_init (GvcMixerCard *mixer_card);
static void gvc_mixer_card_finalize (GObject *object);
G_DEFINE_TYPE (GvcMixerCard, gvc_mixer_card, G_TYPE_OBJECT)
static guint32
get_next_card_serial (void)
{
guint32 serial;
serial = card_serial++;
if ((gint32)card_serial < 0) {
card_serial = 1;
}
return serial;
}
pa_context *
gvc_mixer_card_get_pa_context (GvcMixerCard *card)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), 0);
return card->priv->pa_context;
}
guint
gvc_mixer_card_get_index (GvcMixerCard *card)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), 0);
return card->priv->index;
}
guint
gvc_mixer_card_get_id (GvcMixerCard *card)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), 0);
return card->priv->id;
}
const char *
gvc_mixer_card_get_name (GvcMixerCard *card)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL);
return card->priv->name;
}
gboolean
gvc_mixer_card_set_name (GvcMixerCard *card,
const char *name)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE);
g_free (card->priv->name);
card->priv->name = g_strdup (name);
g_object_notify (G_OBJECT (card), "name");
return TRUE;
}
const char *
gvc_mixer_card_get_icon_name (GvcMixerCard *card)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL);
return card->priv->icon_name;
}
gboolean
gvc_mixer_card_set_icon_name (GvcMixerCard *card,
const char *icon_name)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE);
g_free (card->priv->icon_name);
card->priv->icon_name = g_strdup (icon_name);
g_object_notify (G_OBJECT (card), "icon-name");
return TRUE;
}
/**
* gvc_mixer_card_get_profile: (skip)
*
* @card:
*
* Returns:
*/
GvcMixerCardProfile *
gvc_mixer_card_get_profile (GvcMixerCard *card)
{
GList *l;
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL);
g_return_val_if_fail (card->priv->profiles != NULL, NULL);
for (l = card->priv->profiles; l != NULL; l = l->next) {
GvcMixerCardProfile *p = l->data;
if (g_str_equal (card->priv->profile, p->profile)) {
return p;
}
}
g_assert_not_reached ();
return NULL;
}
gboolean
gvc_mixer_card_set_profile (GvcMixerCard *card,
const char *profile)
{
GList *l;
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE);
g_return_val_if_fail (card->priv->profiles != NULL, FALSE);
g_free (card->priv->profile);
card->priv->profile = g_strdup (profile);
g_free (card->priv->human_profile);
card->priv->human_profile = NULL;
for (l = card->priv->profiles; l != NULL; l = l->next) {
GvcMixerCardProfile *p = l->data;
if (g_str_equal (card->priv->profile, p->profile)) {
card->priv->human_profile = g_strdup (p->human_profile);
break;
}
}
g_object_notify (G_OBJECT (card), "profile");
return TRUE;
}
static void
_pa_context_set_card_profile_by_index_cb (pa_context *context,
int success,
void *userdata)
{
GvcMixerCard *card = GVC_MIXER_CARD (userdata);
g_assert (card->priv->target_profile);
if (success > 0) {
gvc_mixer_card_set_profile (card, card->priv->target_profile);
} else {
g_debug ("Failed to switch profile on '%s' from '%s' to '%s'",
card->priv->name,
card->priv->profile,
card->priv->target_profile);
}
g_free (card->priv->target_profile);
card->priv->target_profile = NULL;
pa_operation_unref (card->priv->profile_op);
card->priv->profile_op = NULL;
}
gboolean
gvc_mixer_card_change_profile (GvcMixerCard *card,
const char *profile)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE);
g_return_val_if_fail (card->priv->profiles != NULL, FALSE);
/* Same profile, or already requested? */
if (g_strcmp0 (card->priv->profile, profile) == 0)
return TRUE;
if (g_strcmp0 (profile, card->priv->target_profile) == 0)
return TRUE;
if (card->priv->profile_op != NULL) {
pa_operation_cancel (card->priv->profile_op);
pa_operation_unref (card->priv->profile_op);
card->priv->profile_op = NULL;
}
if (card->priv->profile != NULL) {
g_free (card->priv->target_profile);
card->priv->target_profile = g_strdup (profile);
card->priv->profile_op = pa_context_set_card_profile_by_index (card->priv->pa_context,
card->priv->index,
card->priv->target_profile,
_pa_context_set_card_profile_by_index_cb,
card);
if (card->priv->profile_op == NULL) {
g_warning ("pa_context_set_card_profile_by_index() failed");
return FALSE;
}
} else {
g_assert (card->priv->human_profile == NULL);
card->priv->profile = g_strdup (profile);
}
return TRUE;
}
/**
* gvc_mixer_card_get_profiles:
*
* Return value: (transfer none) (element-type GvcMixerCardProfile):
*/
const GList *
gvc_mixer_card_get_profiles (GvcMixerCard *card)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL);
return card->priv->profiles;
}
/**
* gvc_mixer_card_get_ports:
*
* Return value: (transfer none) (element-type GvcMixerCardPort):
*/
const GList *
gvc_mixer_card_get_ports (GvcMixerCard *card)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL);
return card->priv->ports;
}
/**
* gvc_mixer_card_profile_compare:
*
* Return value: 1 if @a has a higher priority, -1 if @b has a higher
* priority, 0 if @a and @b have the same priority.
*/
int
gvc_mixer_card_profile_compare (GvcMixerCardProfile *a,
GvcMixerCardProfile *b)
{
if (a->priority == b->priority)
return 0;
if (a->priority > b->priority)
return 1;
return -1;
}
/**
* gvc_mixer_card_set_profiles:
* @profiles: (transfer full) (element-type GvcMixerCardProfile):
*/
gboolean
gvc_mixer_card_set_profiles (GvcMixerCard *card,
GList *profiles)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE);
g_return_val_if_fail (card->priv->profiles == NULL, FALSE);
card->priv->profiles = g_list_sort (profiles, (GCompareFunc) gvc_mixer_card_profile_compare);
return TRUE;
}
/**
* gvc_mixer_card_get_gicon:
*
* @card:
*
* Return value: (transfer full) (element-type GIcon):
*/
GIcon *
gvc_mixer_card_get_gicon (GvcMixerCard *card)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL);
if (card->priv->icon_name == NULL)
return NULL;
return g_themed_icon_new_with_default_fallbacks (card->priv->icon_name);
}
/**
* gvc_mixer_card_set_ports:
* @profiles: (transfer full) (element-type GvcMixerCardPort):
*/
gboolean
gvc_mixer_card_set_ports (GvcMixerCard *card,
GList *ports)
{
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE);
g_return_val_if_fail (card->priv->ports == NULL, FALSE);
card->priv->ports = ports;
return TRUE;
}
static void
gvc_mixer_card_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GvcMixerCard *self = GVC_MIXER_CARD (object);
switch (prop_id) {
case PROP_PA_CONTEXT:
self->priv->pa_context = g_value_get_pointer (value);
break;
case PROP_INDEX:
self->priv->index = g_value_get_ulong (value);
break;
case PROP_ID:
self->priv->id = g_value_get_ulong (value);
break;
case PROP_NAME:
gvc_mixer_card_set_name (self, g_value_get_string (value));
break;
case PROP_ICON_NAME:
gvc_mixer_card_set_icon_name (self, g_value_get_string (value));
break;
case PROP_PROFILE:
gvc_mixer_card_set_profile (self, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gvc_mixer_card_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GvcMixerCard *self = GVC_MIXER_CARD (object);
switch (prop_id) {
case PROP_PA_CONTEXT:
g_value_set_pointer (value, self->priv->pa_context);
break;
case PROP_INDEX:
g_value_set_ulong (value, self->priv->index);
break;
case PROP_ID:
g_value_set_ulong (value, self->priv->id);
break;
case PROP_NAME:
g_value_set_string (value, self->priv->name);
break;
case PROP_ICON_NAME:
g_value_set_string (value, self->priv->icon_name);
break;
case PROP_PROFILE:
g_value_set_string (value, self->priv->profile);
break;
case PROP_HUMAN_PROFILE:
g_value_set_string (value, self->priv->human_profile);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static GObject *
gvc_mixer_card_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_params)
{
GObject *object;
GvcMixerCard *self;
object = G_OBJECT_CLASS (gvc_mixer_card_parent_class)->constructor (type, n_construct_properties, construct_params);
self = GVC_MIXER_CARD (object);
self->priv->id = get_next_card_serial ();
return object;
}
static void
gvc_mixer_card_class_init (GvcMixerCardClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->constructor = gvc_mixer_card_constructor;
gobject_class->finalize = gvc_mixer_card_finalize;
gobject_class->set_property = gvc_mixer_card_set_property;
gobject_class->get_property = gvc_mixer_card_get_property;
g_object_class_install_property (gobject_class,
PROP_INDEX,
g_param_spec_ulong ("index",
"Index",
"The index for this card",
0, G_MAXULONG, 0,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class,
PROP_ID,
g_param_spec_ulong ("id",
"id",
"The id for this card",
0, G_MAXULONG, 0,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class,
PROP_PA_CONTEXT,
g_param_spec_pointer ("pa-context",
"PulseAudio context",
"The PulseAudio context for this card",
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class,
PROP_NAME,
g_param_spec_string ("name",
"Name",
"Name to display for this card",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class,
PROP_ICON_NAME,
g_param_spec_string ("icon-name",
"Icon Name",
"Name of icon to display for this card",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class,
PROP_PROFILE,
g_param_spec_string ("profile",
"Profile",
"Name of current profile for this card",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_HUMAN_PROFILE,
g_param_spec_string ("human-profile",
"Profile (Human readable)",
"Name of current profile for this card in human readable form",
NULL,
G_PARAM_READABLE));
g_type_class_add_private (klass, sizeof (GvcMixerCardPrivate));
}
static void
gvc_mixer_card_init (GvcMixerCard *card)
{
card->priv = GVC_MIXER_CARD_GET_PRIVATE (card);
}
GvcMixerCard *
gvc_mixer_card_new (pa_context *context,
guint index)
{
GObject *object;
object = g_object_new (GVC_TYPE_MIXER_CARD,
"index", index,
"pa-context", context,
NULL);
return GVC_MIXER_CARD (object);
}
static void
free_profile (GvcMixerCardProfile *p)
{
g_free (p->profile);
g_free (p->human_profile);
g_free (p->status);
g_free (p);
}
static void
gvc_mixer_card_finalize (GObject *object)
{
GvcMixerCard *mixer_card;
g_return_if_fail (object != NULL);
g_return_if_fail (GVC_IS_MIXER_CARD (object));
mixer_card = GVC_MIXER_CARD (object);
g_return_if_fail (mixer_card->priv != NULL);
g_free (mixer_card->priv->name);
mixer_card->priv->name = NULL;
g_free (mixer_card->priv->icon_name);
mixer_card->priv->icon_name = NULL;
g_free (mixer_card->priv->target_profile);
mixer_card->priv->target_profile = NULL;
g_free (mixer_card->priv->profile);
mixer_card->priv->profile = NULL;
g_free (mixer_card->priv->human_profile);
mixer_card->priv->human_profile = NULL;
g_list_foreach (mixer_card->priv->profiles, (GFunc) free_profile, NULL);
g_list_free (mixer_card->priv->profiles);
mixer_card->priv->profiles = NULL;
G_OBJECT_CLASS (gvc_mixer_card_parent_class)->finalize (object);
}

101
gvc-mixer-card.h Normal file
View File

@ -0,0 +1,101 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008-2009 Red Hat, Inc.
* Copyright (C) Conor Curran 2011 <conor.curran@canonical.com>
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_MIXER_CARD_H
#define __GVC_MIXER_CARD_H
#include <glib-object.h>
#include <gio/gio.h>
G_BEGIN_DECLS
#define GVC_TYPE_MIXER_CARD (gvc_mixer_card_get_type ())
#define GVC_MIXER_CARD(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_CARD, GvcMixerCard))
#define GVC_MIXER_CARD_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_CARD, GvcMixerCardClass))
#define GVC_IS_MIXER_CARD(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_CARD))
#define GVC_IS_MIXER_CARD_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_CARD))
#define GVC_MIXER_CARD_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_CARD, GvcMixerCardClass))
typedef struct GvcMixerCardPrivate GvcMixerCardPrivate;
typedef struct
{
GObject parent;
GvcMixerCardPrivate *priv;
} GvcMixerCard;
typedef struct
{
GObjectClass parent_class;
/* vtable */
} GvcMixerCardClass;
typedef struct
{
char *profile;
char *human_profile;
char *status;
guint priority;
guint n_sinks, n_sources;
} GvcMixerCardProfile;
typedef struct
{
char *port;
char *human_port;
guint priority;
gint available;
gint direction;
GList *profiles;
} GvcMixerCardPort;
GType gvc_mixer_card_get_type (void);
guint gvc_mixer_card_get_id (GvcMixerCard *card);
guint gvc_mixer_card_get_index (GvcMixerCard *card);
const char * gvc_mixer_card_get_name (GvcMixerCard *card);
const char * gvc_mixer_card_get_icon_name (GvcMixerCard *card);
GvcMixerCardProfile * gvc_mixer_card_get_profile (GvcMixerCard *card);
const GList * gvc_mixer_card_get_profiles (GvcMixerCard *card);
const GList * gvc_mixer_card_get_ports (GvcMixerCard *card);
gboolean gvc_mixer_card_change_profile (GvcMixerCard *card,
const char *profile);
GIcon * gvc_mixer_card_get_gicon (GvcMixerCard *card);
int gvc_mixer_card_profile_compare (GvcMixerCardProfile *a,
GvcMixerCardProfile *b);
/* private */
gboolean gvc_mixer_card_set_name (GvcMixerCard *card,
const char *name);
gboolean gvc_mixer_card_set_icon_name (GvcMixerCard *card,
const char *name);
gboolean gvc_mixer_card_set_profile (GvcMixerCard *card,
const char *profile);
gboolean gvc_mixer_card_set_profiles (GvcMixerCard *card,
GList *profiles);
gboolean gvc_mixer_card_set_ports (GvcMixerCard *stream,
GList *ports);
G_END_DECLS
#endif /* __GVC_MIXER_CARD_H */

View File

@ -0,0 +1,35 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_MIXER_CONTROL_PRIVATE_H
#define __GVC_MIXER_CONTROL_PRIVATE_H
#include <glib-object.h>
#include <pulse/pulseaudio.h>
#include "gvc-mixer-stream.h"
#include "gvc-mixer-card.h"
G_BEGIN_DECLS
pa_context * gvc_mixer_control_get_pa_context (GvcMixerControl *control);
G_END_DECLS
#endif /* __GVC_MIXER_CONTROL_PRIVATE_H */

3358
gvc-mixer-control.c Normal file

File diff suppressed because it is too large Load Diff

136
gvc-mixer-control.h Normal file
View File

@ -0,0 +1,136 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_MIXER_CONTROL_H
#define __GVC_MIXER_CONTROL_H
#include <glib-object.h>
#include "gvc-mixer-stream.h"
#include "gvc-mixer-card.h"
#include "gvc-mixer-ui-device.h"
G_BEGIN_DECLS
typedef enum
{
GVC_STATE_CLOSED,
GVC_STATE_READY,
GVC_STATE_CONNECTING,
GVC_STATE_FAILED
} GvcMixerControlState;
#define GVC_TYPE_MIXER_CONTROL (gvc_mixer_control_get_type ())
#define GVC_MIXER_CONTROL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_CONTROL, GvcMixerControl))
#define GVC_MIXER_CONTROL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_CONTROL, GvcMixerControlClass))
#define GVC_IS_MIXER_CONTROL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_CONTROL))
#define GVC_IS_MIXER_CONTROL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_CONTROL))
#define GVC_MIXER_CONTROL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_CONTROL, GvcMixerControlClass))
typedef struct GvcMixerControlPrivate GvcMixerControlPrivate;
typedef struct
{
GObject parent;
GvcMixerControlPrivate *priv;
} GvcMixerControl;
typedef struct
{
GObjectClass parent_class;
void (*state_changed) (GvcMixerControl *control,
GvcMixerControlState new_state);
void (*stream_added) (GvcMixerControl *control,
guint id);
void (*stream_removed) (GvcMixerControl *control,
guint id);
void (*card_added) (GvcMixerControl *control,
guint id);
void (*card_removed) (GvcMixerControl *control,
guint id);
void (*default_sink_changed) (GvcMixerControl *control,
guint id);
void (*default_source_changed) (GvcMixerControl *control,
guint id);
void (*active_output_update) (GvcMixerControl *control,
guint id);
void (*active_input_update) (GvcMixerControl *control,
guint id);
void (*output_added) (GvcMixerControl *control,
guint id);
void (*input_added) (GvcMixerControl *control,
guint id);
void (*output_removed) (GvcMixerControl *control,
guint id);
void (*input_removed) (GvcMixerControl *control,
guint id);
} GvcMixerControlClass;
GType gvc_mixer_control_get_type (void);
GvcMixerControl * gvc_mixer_control_new (const char *name);
gboolean gvc_mixer_control_open (GvcMixerControl *control);
gboolean gvc_mixer_control_close (GvcMixerControl *control);
GSList * gvc_mixer_control_get_cards (GvcMixerControl *control);
GSList * gvc_mixer_control_get_streams (GvcMixerControl *control);
GSList * gvc_mixer_control_get_sinks (GvcMixerControl *control);
GSList * gvc_mixer_control_get_sources (GvcMixerControl *control);
GSList * gvc_mixer_control_get_sink_inputs (GvcMixerControl *control);
GSList * gvc_mixer_control_get_source_outputs (GvcMixerControl *control);
GvcMixerStream * gvc_mixer_control_lookup_stream_id (GvcMixerControl *control,
guint id);
GvcMixerCard * gvc_mixer_control_lookup_card_id (GvcMixerControl *control,
guint id);
GvcMixerUIDevice * gvc_mixer_control_lookup_output_id (GvcMixerControl *control,
guint id);
GvcMixerUIDevice * gvc_mixer_control_lookup_input_id (GvcMixerControl *control,
guint id);
GvcMixerUIDevice * gvc_mixer_control_lookup_device_from_stream (GvcMixerControl *control,
GvcMixerStream *stream);
GvcMixerStream * gvc_mixer_control_get_default_sink (GvcMixerControl *control);
GvcMixerStream * gvc_mixer_control_get_default_source (GvcMixerControl *control);
GvcMixerStream * gvc_mixer_control_get_event_sink_input (GvcMixerControl *control);
gboolean gvc_mixer_control_set_default_sink (GvcMixerControl *control,
GvcMixerStream *stream);
gboolean gvc_mixer_control_set_default_source (GvcMixerControl *control,
GvcMixerStream *stream);
gdouble gvc_mixer_control_get_vol_max_norm (GvcMixerControl *control);
gdouble gvc_mixer_control_get_vol_max_amplified (GvcMixerControl *control);
void gvc_mixer_control_change_output (GvcMixerControl *control,
GvcMixerUIDevice* output);
void gvc_mixer_control_change_input (GvcMixerControl *control,
GvcMixerUIDevice* input);
GvcMixerStream* gvc_mixer_control_get_stream_from_device (GvcMixerControl *control,
GvcMixerUIDevice *dev);
gboolean gvc_mixer_control_change_profile_on_selected_device (GvcMixerControl *control,
GvcMixerUIDevice *device,
const gchar* profile);
GvcMixerControlState gvc_mixer_control_get_state (GvcMixerControl *control);
G_END_DECLS
#endif /* __GVC_MIXER_CONTROL_H */

1977
gvc-mixer-dialog.c Normal file

File diff suppressed because it is too large Load Diff

56
gvc-mixer-dialog.h Normal file
View File

@ -0,0 +1,56 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_MIXER_DIALOG_H
#define __GVC_MIXER_DIALOG_H
#include <glib-object.h>
#include "gvc-mixer-control.h"
G_BEGIN_DECLS
#define GVC_TYPE_MIXER_DIALOG (gvc_mixer_dialog_get_type ())
#define GVC_MIXER_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_DIALOG, GvcMixerDialog))
#define GVC_MIXER_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_DIALOG, GvcMixerDialogClass))
#define GVC_IS_MIXER_DIALOG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_DIALOG))
#define GVC_IS_MIXER_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_DIALOG))
#define GVC_MIXER_DIALOG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_DIALOG, GvcMixerDialogClass))
typedef struct GvcMixerDialogPrivate GvcMixerDialogPrivate;
typedef struct
{
GtkVBox parent;
GvcMixerDialogPrivate *priv;
} GvcMixerDialog;
typedef struct
{
GtkVBoxClass parent_class;
} GvcMixerDialogClass;
GType gvc_mixer_dialog_get_type (void);
GvcMixerDialog * gvc_mixer_dialog_new (GvcMixerControl *control);
gboolean gvc_mixer_dialog_set_page (GvcMixerDialog *dialog, const gchar* page);
G_END_DECLS
#endif /* __GVC_MIXER_DIALOG_H */

235
gvc-mixer-event-role.c Normal file
View File

@ -0,0 +1,235 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 William Jon McCann
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <pulse/pulseaudio.h>
#include <pulse/ext-stream-restore.h>
#include "gvc-mixer-event-role.h"
#include "gvc-mixer-stream-private.h"
#include "gvc-channel-map-private.h"
#define GVC_MIXER_EVENT_ROLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_EVENT_ROLE, GvcMixerEventRolePrivate))
struct GvcMixerEventRolePrivate
{
char *device;
};
enum
{
PROP_0,
PROP_DEVICE
};
static void gvc_mixer_event_role_class_init (GvcMixerEventRoleClass *klass);
static void gvc_mixer_event_role_init (GvcMixerEventRole *mixer_event_role);
static void gvc_mixer_event_role_finalize (GObject *object);
G_DEFINE_TYPE (GvcMixerEventRole, gvc_mixer_event_role, GVC_TYPE_MIXER_STREAM)
static gboolean
update_settings (GvcMixerEventRole *role,
gboolean is_muted,
gpointer *op)
{
pa_operation *o;
const GvcChannelMap *map;
pa_context *context;
pa_ext_stream_restore_info info;
map = gvc_mixer_stream_get_channel_map (GVC_MIXER_STREAM(role));
info.volume = *gvc_channel_map_get_cvolume(map);
info.name = "sink-input-by-media-role:event";
info.channel_map = *gvc_channel_map_get_pa_channel_map(map);
info.device = role->priv->device;
info.mute = is_muted;
context = gvc_mixer_stream_get_pa_context (GVC_MIXER_STREAM (role));
o = pa_ext_stream_restore_write (context,
PA_UPDATE_REPLACE,
&info,
1,
TRUE,
NULL,
NULL);
if (o == NULL) {
g_warning ("pa_ext_stream_restore_write() failed");
return FALSE;
}
if (op != NULL)
*op = o;
return TRUE;
}
static gboolean
gvc_mixer_event_role_push_volume (GvcMixerStream *stream, gpointer *op)
{
return update_settings (GVC_MIXER_EVENT_ROLE (stream),
gvc_mixer_stream_get_is_muted (stream), op);
}
static gboolean
gvc_mixer_event_role_change_is_muted (GvcMixerStream *stream,
gboolean is_muted)
{
/* Apply change straight away so that we don't get a race with
* gvc_mixer_event_role_push_volume().
* See https://bugs.freedesktop.org/show_bug.cgi?id=51413 */
gvc_mixer_stream_set_is_muted (stream, is_muted);
return update_settings (GVC_MIXER_EVENT_ROLE (stream),
is_muted, NULL);
}
static gboolean
gvc_mixer_event_role_set_device (GvcMixerEventRole *role,
const char *device)
{
g_return_val_if_fail (GVC_IS_MIXER_EVENT_ROLE (role), FALSE);
g_free (role->priv->device);
role->priv->device = g_strdup (device);
g_object_notify (G_OBJECT (role), "device");
return TRUE;
}
static void
gvc_mixer_event_role_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GvcMixerEventRole *self = GVC_MIXER_EVENT_ROLE (object);
switch (prop_id) {
case PROP_DEVICE:
gvc_mixer_event_role_set_device (self, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gvc_mixer_event_role_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GvcMixerEventRole *self = GVC_MIXER_EVENT_ROLE (object);
switch (prop_id) {
case PROP_DEVICE:
g_value_set_string (value, self->priv->device);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gvc_mixer_event_role_class_init (GvcMixerEventRoleClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass);
object_class->finalize = gvc_mixer_event_role_finalize;
object_class->set_property = gvc_mixer_event_role_set_property;
object_class->get_property = gvc_mixer_event_role_get_property;
stream_class->push_volume = gvc_mixer_event_role_push_volume;
stream_class->change_is_muted = gvc_mixer_event_role_change_is_muted;
g_object_class_install_property (object_class,
PROP_DEVICE,
g_param_spec_string ("device",
"Device",
"Device",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_type_class_add_private (klass, sizeof (GvcMixerEventRolePrivate));
}
static void
gvc_mixer_event_role_init (GvcMixerEventRole *event_role)
{
event_role->priv = GVC_MIXER_EVENT_ROLE_GET_PRIVATE (event_role);
}
static void
gvc_mixer_event_role_finalize (GObject *object)
{
GvcMixerEventRole *mixer_event_role;
g_return_if_fail (object != NULL);
g_return_if_fail (GVC_IS_MIXER_EVENT_ROLE (object));
mixer_event_role = GVC_MIXER_EVENT_ROLE (object);
g_return_if_fail (mixer_event_role->priv != NULL);
g_free (mixer_event_role->priv->device);
G_OBJECT_CLASS (gvc_mixer_event_role_parent_class)->finalize (object);
}
/**
* gvc_mixer_event_role_new: (skip)
*
* @context:
* @index:
* @channel_map:
*
* Returns:
*/
GvcMixerStream *
gvc_mixer_event_role_new (pa_context *context,
const char *device,
GvcChannelMap *channel_map)
{
GObject *object;
object = g_object_new (GVC_TYPE_MIXER_EVENT_ROLE,
"pa-context", context,
"index", 0,
"device", device,
"channel-map", channel_map,
NULL);
return GVC_MIXER_STREAM (object);
}

57
gvc-mixer-event-role.h Normal file
View File

@ -0,0 +1,57 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_MIXER_EVENT_ROLE_H
#define __GVC_MIXER_EVENT_ROLE_H
#include <glib-object.h>
#include "gvc-mixer-stream.h"
G_BEGIN_DECLS
#define GVC_TYPE_MIXER_EVENT_ROLE (gvc_mixer_event_role_get_type ())
#define GVC_MIXER_EVENT_ROLE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_EVENT_ROLE, GvcMixerEventRole))
#define GVC_MIXER_EVENT_ROLE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_EVENT_ROLE, GvcMixerEventRoleClass))
#define GVC_IS_MIXER_EVENT_ROLE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_EVENT_ROLE))
#define GVC_IS_MIXER_EVENT_ROLE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_EVENT_ROLE))
#define GVC_MIXER_EVENT_ROLE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_EVENT_ROLE, GvcMixerEventRoleClass))
typedef struct GvcMixerEventRolePrivate GvcMixerEventRolePrivate;
typedef struct
{
GvcMixerStream parent;
GvcMixerEventRolePrivate *priv;
} GvcMixerEventRole;
typedef struct
{
GvcMixerStreamClass parent_class;
} GvcMixerEventRoleClass;
GType gvc_mixer_event_role_get_type (void);
GvcMixerStream * gvc_mixer_event_role_new (pa_context *context,
const char *device,
GvcChannelMap *channel_map);
G_END_DECLS
#endif /* __GVC_MIXER_EVENT_ROLE_H */

166
gvc-mixer-sink-input.c Normal file
View File

@ -0,0 +1,166 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 William Jon McCann
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <pulse/pulseaudio.h>
#include "gvc-mixer-sink-input.h"
#include "gvc-mixer-stream-private.h"
#include "gvc-channel-map-private.h"
#define GVC_MIXER_SINK_INPUT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_SINK_INPUT, GvcMixerSinkInputPrivate))
struct GvcMixerSinkInputPrivate
{
gpointer dummy;
};
static void gvc_mixer_sink_input_class_init (GvcMixerSinkInputClass *klass);
static void gvc_mixer_sink_input_init (GvcMixerSinkInput *mixer_sink_input);
static void gvc_mixer_sink_input_finalize (GObject *object);
G_DEFINE_TYPE (GvcMixerSinkInput, gvc_mixer_sink_input, GVC_TYPE_MIXER_STREAM)
static gboolean
gvc_mixer_sink_input_push_volume (GvcMixerStream *stream, gpointer *op)
{
pa_operation *o;
guint index;
const GvcChannelMap *map;
pa_context *context;
const pa_cvolume *cv;
index = gvc_mixer_stream_get_index (stream);
map = gvc_mixer_stream_get_channel_map (stream);
cv = gvc_channel_map_get_cvolume(map);
context = gvc_mixer_stream_get_pa_context (stream);
o = pa_context_set_sink_input_volume (context,
index,
cv,
NULL,
NULL);
if (o == NULL) {
g_warning ("pa_context_set_sink_input_volume() failed");
return FALSE;
}
*op = o;
return TRUE;
}
static gboolean
gvc_mixer_sink_input_change_is_muted (GvcMixerStream *stream,
gboolean is_muted)
{
pa_operation *o;
guint index;
pa_context *context;
index = gvc_mixer_stream_get_index (stream);
context = gvc_mixer_stream_get_pa_context (stream);
o = pa_context_set_sink_input_mute (context,
index,
is_muted,
NULL,
NULL);
if (o == NULL) {
g_warning ("pa_context_set_sink_input_mute_by_index() failed");
return FALSE;
}
pa_operation_unref(o);
return TRUE;
}
static void
gvc_mixer_sink_input_class_init (GvcMixerSinkInputClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass);
object_class->finalize = gvc_mixer_sink_input_finalize;
stream_class->push_volume = gvc_mixer_sink_input_push_volume;
stream_class->change_is_muted = gvc_mixer_sink_input_change_is_muted;
g_type_class_add_private (klass, sizeof (GvcMixerSinkInputPrivate));
}
static void
gvc_mixer_sink_input_init (GvcMixerSinkInput *sink_input)
{
sink_input->priv = GVC_MIXER_SINK_INPUT_GET_PRIVATE (sink_input);
}
static void
gvc_mixer_sink_input_finalize (GObject *object)
{
GvcMixerSinkInput *mixer_sink_input;
g_return_if_fail (object != NULL);
g_return_if_fail (GVC_IS_MIXER_SINK_INPUT (object));
mixer_sink_input = GVC_MIXER_SINK_INPUT (object);
g_return_if_fail (mixer_sink_input->priv != NULL);
G_OBJECT_CLASS (gvc_mixer_sink_input_parent_class)->finalize (object);
}
/**
* gvc_mixer_sink_input_new: (skip)
*
* @context:
* @index:
* @channel_map:
*
* Returns:
*/
GvcMixerStream *
gvc_mixer_sink_input_new (pa_context *context,
guint index,
GvcChannelMap *channel_map)
{
GObject *object;
object = g_object_new (GVC_TYPE_MIXER_SINK_INPUT,
"pa-context", context,
"index", index,
"channel-map", channel_map,
NULL);
return GVC_MIXER_STREAM (object);
}

57
gvc-mixer-sink-input.h Normal file
View File

@ -0,0 +1,57 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_MIXER_SINK_INPUT_H
#define __GVC_MIXER_SINK_INPUT_H
#include <glib-object.h>
#include "gvc-mixer-stream.h"
G_BEGIN_DECLS
#define GVC_TYPE_MIXER_SINK_INPUT (gvc_mixer_sink_input_get_type ())
#define GVC_MIXER_SINK_INPUT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_SINK_INPUT, GvcMixerSinkInput))
#define GVC_MIXER_SINK_INPUT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_SINK_INPUT, GvcMixerSinkInputClass))
#define GVC_IS_MIXER_SINK_INPUT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_SINK_INPUT))
#define GVC_IS_MIXER_SINK_INPUT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_SINK_INPUT))
#define GVC_MIXER_SINK_INPUT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_SINK_INPUT, GvcMixerSinkInputClass))
typedef struct GvcMixerSinkInputPrivate GvcMixerSinkInputPrivate;
typedef struct
{
GvcMixerStream parent;
GvcMixerSinkInputPrivate *priv;
} GvcMixerSinkInput;
typedef struct
{
GvcMixerStreamClass parent_class;
} GvcMixerSinkInputClass;
GType gvc_mixer_sink_input_get_type (void);
GvcMixerStream * gvc_mixer_sink_input_new (pa_context *context,
guint index,
GvcChannelMap *map);
G_END_DECLS
#endif /* __GVC_MIXER_SINK_INPUT_H */

196
gvc-mixer-sink.c Normal file
View File

@ -0,0 +1,196 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 William Jon McCann
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <pulse/pulseaudio.h>
#include "gvc-mixer-sink.h"
#include "gvc-mixer-stream-private.h"
#include "gvc-channel-map-private.h"
#define GVC_MIXER_SINK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_SINK, GvcMixerSinkPrivate))
struct GvcMixerSinkPrivate
{
gpointer dummy;
};
static void gvc_mixer_sink_class_init (GvcMixerSinkClass *klass);
static void gvc_mixer_sink_init (GvcMixerSink *mixer_sink);
static void gvc_mixer_sink_finalize (GObject *object);
G_DEFINE_TYPE (GvcMixerSink, gvc_mixer_sink, GVC_TYPE_MIXER_STREAM)
static gboolean
gvc_mixer_sink_push_volume (GvcMixerStream *stream, gpointer *op)
{
pa_operation *o;
guint index;
const GvcChannelMap *map;
pa_context *context;
const pa_cvolume *cv;
index = gvc_mixer_stream_get_index (stream);
map = gvc_mixer_stream_get_channel_map (stream);
/* set the volume */
cv = gvc_channel_map_get_cvolume(map);
context = gvc_mixer_stream_get_pa_context (stream);
o = pa_context_set_sink_volume_by_index (context,
index,
cv,
NULL,
NULL);
if (o == NULL) {
g_warning ("pa_context_set_sink_volume_by_index() failed: %s", pa_strerror(pa_context_errno(context)));
return FALSE;
}
*op = o;
return TRUE;
}
static gboolean
gvc_mixer_sink_change_is_muted (GvcMixerStream *stream,
gboolean is_muted)
{
pa_operation *o;
guint index;
pa_context *context;
index = gvc_mixer_stream_get_index (stream);
context = gvc_mixer_stream_get_pa_context (stream);
o = pa_context_set_sink_mute_by_index (context,
index,
is_muted,
NULL,
NULL);
if (o == NULL) {
g_warning ("pa_context_set_sink_mute_by_index() failed: %s", pa_strerror(pa_context_errno(context)));
return FALSE;
}
pa_operation_unref(o);
return TRUE;
}
static gboolean
gvc_mixer_sink_change_port (GvcMixerStream *stream,
const char *port)
{
pa_operation *o;
guint index;
pa_context *context;
index = gvc_mixer_stream_get_index (stream);
context = gvc_mixer_stream_get_pa_context (stream);
o = pa_context_set_sink_port_by_index (context,
index,
port,
NULL,
NULL);
if (o == NULL) {
g_warning ("pa_context_set_sink_port_by_index() failed: %s", pa_strerror(pa_context_errno(context)));
return FALSE;
}
pa_operation_unref(o);
return TRUE;
}
static void
gvc_mixer_sink_class_init (GvcMixerSinkClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass);
object_class->finalize = gvc_mixer_sink_finalize;
stream_class->push_volume = gvc_mixer_sink_push_volume;
stream_class->change_port = gvc_mixer_sink_change_port;
stream_class->change_is_muted = gvc_mixer_sink_change_is_muted;
g_type_class_add_private (klass, sizeof (GvcMixerSinkPrivate));
}
static void
gvc_mixer_sink_init (GvcMixerSink *sink)
{
sink->priv = GVC_MIXER_SINK_GET_PRIVATE (sink);
}
static void
gvc_mixer_sink_finalize (GObject *object)
{
GvcMixerSink *mixer_sink;
g_return_if_fail (object != NULL);
g_return_if_fail (GVC_IS_MIXER_SINK (object));
mixer_sink = GVC_MIXER_SINK (object);
g_return_if_fail (mixer_sink->priv != NULL);
G_OBJECT_CLASS (gvc_mixer_sink_parent_class)->finalize (object);
}
/**
* gvc_mixer_sink_new: (skip)
*
* @context:
* @index:
* @channel_map:
*
* Returns:
*/
GvcMixerStream *
gvc_mixer_sink_new (pa_context *context,
guint index,
GvcChannelMap *channel_map)
{
GObject *object;
object = g_object_new (GVC_TYPE_MIXER_SINK,
"pa-context", context,
"index", index,
"channel-map", channel_map,
NULL);
return GVC_MIXER_STREAM (object);
}

57
gvc-mixer-sink.h Normal file
View File

@ -0,0 +1,57 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_MIXER_SINK_H
#define __GVC_MIXER_SINK_H
#include <glib-object.h>
#include "gvc-mixer-stream.h"
G_BEGIN_DECLS
#define GVC_TYPE_MIXER_SINK (gvc_mixer_sink_get_type ())
#define GVC_MIXER_SINK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_SINK, GvcMixerSink))
#define GVC_MIXER_SINK_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_SINK, GvcMixerSinkClass))
#define GVC_IS_MIXER_SINK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_SINK))
#define GVC_IS_MIXER_SINK_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_SINK))
#define GVC_MIXER_SINK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_SINK, GvcMixerSinkClass))
typedef struct GvcMixerSinkPrivate GvcMixerSinkPrivate;
typedef struct
{
GvcMixerStream parent;
GvcMixerSinkPrivate *priv;
} GvcMixerSink;
typedef struct
{
GvcMixerStreamClass parent_class;
} GvcMixerSinkClass;
GType gvc_mixer_sink_get_type (void);
GvcMixerStream * gvc_mixer_sink_new (pa_context *context,
guint index,
GvcChannelMap *map);
G_END_DECLS
#endif /* __GVC_MIXER_SINK_H */

121
gvc-mixer-source-output.c Normal file
View File

@ -0,0 +1,121 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 William Jon McCann
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <pulse/pulseaudio.h>
#include "gvc-mixer-source-output.h"
#define GVC_MIXER_SOURCE_OUTPUT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_SOURCE_OUTPUT, GvcMixerSourceOutputPrivate))
struct GvcMixerSourceOutputPrivate
{
gpointer dummy;
};
static void gvc_mixer_source_output_class_init (GvcMixerSourceOutputClass *klass);
static void gvc_mixer_source_output_init (GvcMixerSourceOutput *mixer_source_output);
static void gvc_mixer_source_output_finalize (GObject *object);
G_DEFINE_TYPE (GvcMixerSourceOutput, gvc_mixer_source_output, GVC_TYPE_MIXER_STREAM)
static gboolean
gvc_mixer_source_output_push_volume (GvcMixerStream *stream, gpointer *op)
{
/* FIXME: */
*op = NULL;
return TRUE;
}
static gboolean
gvc_mixer_source_output_change_is_muted (GvcMixerStream *stream,
gboolean is_muted)
{
/* FIXME: */
return TRUE;
}
static void
gvc_mixer_source_output_class_init (GvcMixerSourceOutputClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass);
object_class->finalize = gvc_mixer_source_output_finalize;
stream_class->push_volume = gvc_mixer_source_output_push_volume;
stream_class->change_is_muted = gvc_mixer_source_output_change_is_muted;
g_type_class_add_private (klass, sizeof (GvcMixerSourceOutputPrivate));
}
static void
gvc_mixer_source_output_init (GvcMixerSourceOutput *source_output)
{
source_output->priv = GVC_MIXER_SOURCE_OUTPUT_GET_PRIVATE (source_output);
}
static void
gvc_mixer_source_output_finalize (GObject *object)
{
GvcMixerSourceOutput *mixer_source_output;
g_return_if_fail (object != NULL);
g_return_if_fail (GVC_IS_MIXER_SOURCE_OUTPUT (object));
mixer_source_output = GVC_MIXER_SOURCE_OUTPUT (object);
g_return_if_fail (mixer_source_output->priv != NULL);
G_OBJECT_CLASS (gvc_mixer_source_output_parent_class)->finalize (object);
}
/**
* gvc_mixer_source_output_new: (skip)
*
* @context:
* @index:
* @channel_map:
*
* Returns:
*/
GvcMixerStream *
gvc_mixer_source_output_new (pa_context *context,
guint index,
GvcChannelMap *channel_map)
{
GObject *object;
object = g_object_new (GVC_TYPE_MIXER_SOURCE_OUTPUT,
"pa-context", context,
"index", index,
"channel-map", channel_map,
NULL);
return GVC_MIXER_STREAM (object);
}

57
gvc-mixer-source-output.h Normal file
View File

@ -0,0 +1,57 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_MIXER_SOURCE_OUTPUT_H
#define __GVC_MIXER_SOURCE_OUTPUT_H
#include <glib-object.h>
#include "gvc-mixer-stream.h"
G_BEGIN_DECLS
#define GVC_TYPE_MIXER_SOURCE_OUTPUT (gvc_mixer_source_output_get_type ())
#define GVC_MIXER_SOURCE_OUTPUT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_SOURCE_OUTPUT, GvcMixerSourceOutput))
#define GVC_MIXER_SOURCE_OUTPUT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_SOURCE_OUTPUT, GvcMixerSourceOutputClass))
#define GVC_IS_MIXER_SOURCE_OUTPUT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_SOURCE_OUTPUT))
#define GVC_IS_MIXER_SOURCE_OUTPUT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_SOURCE_OUTPUT))
#define GVC_MIXER_SOURCE_OUTPUT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_SOURCE_OUTPUT, GvcMixerSourceOutputClass))
typedef struct GvcMixerSourceOutputPrivate GvcMixerSourceOutputPrivate;
typedef struct
{
GvcMixerStream parent;
GvcMixerSourceOutputPrivate *priv;
} GvcMixerSourceOutput;
typedef struct
{
GvcMixerStreamClass parent_class;
} GvcMixerSourceOutputClass;
GType gvc_mixer_source_output_get_type (void);
GvcMixerStream * gvc_mixer_source_output_new (pa_context *context,
guint index,
GvcChannelMap *map);
G_END_DECLS
#endif /* __GVC_MIXER_SOURCE_OUTPUT_H */

196
gvc-mixer-source.c Normal file
View File

@ -0,0 +1,196 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 William Jon McCann
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <pulse/pulseaudio.h>
#include "gvc-mixer-source.h"
#include "gvc-mixer-stream-private.h"
#include "gvc-channel-map-private.h"
#define GVC_MIXER_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_SOURCE, GvcMixerSourcePrivate))
struct GvcMixerSourcePrivate
{
gpointer dummy;
};
static void gvc_mixer_source_class_init (GvcMixerSourceClass *klass);
static void gvc_mixer_source_init (GvcMixerSource *mixer_source);
static void gvc_mixer_source_finalize (GObject *object);
G_DEFINE_TYPE (GvcMixerSource, gvc_mixer_source, GVC_TYPE_MIXER_STREAM)
static gboolean
gvc_mixer_source_push_volume (GvcMixerStream *stream, gpointer *op)
{
pa_operation *o;
guint index;
const GvcChannelMap *map;
pa_context *context;
const pa_cvolume *cv;
index = gvc_mixer_stream_get_index (stream);
map = gvc_mixer_stream_get_channel_map (stream);
/* set the volume */
cv = gvc_channel_map_get_cvolume (map);
context = gvc_mixer_stream_get_pa_context (stream);
o = pa_context_set_source_volume_by_index (context,
index,
cv,
NULL,
NULL);
if (o == NULL) {
g_warning ("pa_context_set_source_volume_by_index() failed: %s", pa_strerror(pa_context_errno(context)));
return FALSE;
}
*op = o;
return TRUE;
}
static gboolean
gvc_mixer_source_change_is_muted (GvcMixerStream *stream,
gboolean is_muted)
{
pa_operation *o;
guint index;
pa_context *context;
index = gvc_mixer_stream_get_index (stream);
context = gvc_mixer_stream_get_pa_context (stream);
o = pa_context_set_source_mute_by_index (context,
index,
is_muted,
NULL,
NULL);
if (o == NULL) {
g_warning ("pa_context_set_source_mute_by_index() failed: %s", pa_strerror(pa_context_errno(context)));
return FALSE;
}
pa_operation_unref(o);
return TRUE;
}
static gboolean
gvc_mixer_source_change_port (GvcMixerStream *stream,
const char *port)
{
pa_operation *o;
guint index;
pa_context *context;
index = gvc_mixer_stream_get_index (stream);
context = gvc_mixer_stream_get_pa_context (stream);
o = pa_context_set_source_port_by_index (context,
index,
port,
NULL,
NULL);
if (o == NULL) {
g_warning ("pa_context_set_source_port_by_index() failed: %s", pa_strerror(pa_context_errno(context)));
return FALSE;
}
pa_operation_unref(o);
return TRUE;
}
static void
gvc_mixer_source_class_init (GvcMixerSourceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass);
object_class->finalize = gvc_mixer_source_finalize;
stream_class->push_volume = gvc_mixer_source_push_volume;
stream_class->change_is_muted = gvc_mixer_source_change_is_muted;
stream_class->change_port = gvc_mixer_source_change_port;
g_type_class_add_private (klass, sizeof (GvcMixerSourcePrivate));
}
static void
gvc_mixer_source_init (GvcMixerSource *source)
{
source->priv = GVC_MIXER_SOURCE_GET_PRIVATE (source);
}
static void
gvc_mixer_source_finalize (GObject *object)
{
GvcMixerSource *mixer_source;
g_return_if_fail (object != NULL);
g_return_if_fail (GVC_IS_MIXER_SOURCE (object));
mixer_source = GVC_MIXER_SOURCE (object);
g_return_if_fail (mixer_source->priv != NULL);
G_OBJECT_CLASS (gvc_mixer_source_parent_class)->finalize (object);
}
/**
* gvc_mixer_source_new: (skip)
*
* @context:
* @index:
* @channel_map:
*
* Returns:
*/
GvcMixerStream *
gvc_mixer_source_new (pa_context *context,
guint index,
GvcChannelMap *channel_map)
{
GObject *object;
object = g_object_new (GVC_TYPE_MIXER_SOURCE,
"pa-context", context,
"index", index,
"channel-map", channel_map,
NULL);
return GVC_MIXER_STREAM (object);
}

57
gvc-mixer-source.h Normal file
View File

@ -0,0 +1,57 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_MIXER_SOURCE_H
#define __GVC_MIXER_SOURCE_H
#include <glib-object.h>
#include "gvc-mixer-stream.h"
G_BEGIN_DECLS
#define GVC_TYPE_MIXER_SOURCE (gvc_mixer_source_get_type ())
#define GVC_MIXER_SOURCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_SOURCE, GvcMixerSource))
#define GVC_MIXER_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_SOURCE, GvcMixerSourceClass))
#define GVC_IS_MIXER_SOURCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_SOURCE))
#define GVC_IS_MIXER_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_SOURCE))
#define GVC_MIXER_SOURCE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_SOURCE, GvcMixerSourceClass))
typedef struct GvcMixerSourcePrivate GvcMixerSourcePrivate;
typedef struct
{
GvcMixerStream parent;
GvcMixerSourcePrivate *priv;
} GvcMixerSource;
typedef struct
{
GvcMixerStreamClass parent_class;
} GvcMixerSourceClass;
GType gvc_mixer_source_get_type (void);
GvcMixerStream * gvc_mixer_source_new (pa_context *context,
guint index,
GvcChannelMap *map);
G_END_DECLS
#endif /* __GVC_MIXER_SOURCE_H */

View File

@ -0,0 +1,34 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_MIXER_STREAM_PRIVATE_H
#define __GVC_MIXER_STREAM_PRIVATE_H
#include <glib-object.h>
#include "gvc-channel-map.h"
G_BEGIN_DECLS
pa_context * gvc_mixer_stream_get_pa_context (GvcMixerStream *stream);
G_END_DECLS
#endif /* __GVC_MIXER_STREAM_PRIVATE_H */

1006
gvc-mixer-stream.c Normal file

File diff suppressed because it is too large Load Diff

131
gvc-mixer-stream.h Normal file
View File

@ -0,0 +1,131 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_MIXER_STREAM_H
#define __GVC_MIXER_STREAM_H
#include <glib-object.h>
#include "gvc-pulseaudio-fake.h"
#include "gvc-channel-map.h"
#include <gio/gio.h>
G_BEGIN_DECLS
#define GVC_TYPE_MIXER_STREAM (gvc_mixer_stream_get_type ())
#define GVC_MIXER_STREAM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_STREAM, GvcMixerStream))
#define GVC_MIXER_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_STREAM, GvcMixerStreamClass))
#define GVC_IS_MIXER_STREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_STREAM))
#define GVC_IS_MIXER_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_STREAM))
#define GVC_MIXER_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_STREAM, GvcMixerStreamClass))
typedef struct GvcMixerStreamPrivate GvcMixerStreamPrivate;
typedef struct
{
GObject parent;
GvcMixerStreamPrivate *priv;
} GvcMixerStream;
typedef struct
{
GObjectClass parent_class;
/* vtable */
gboolean (*push_volume) (GvcMixerStream *stream,
gpointer *operation);
gboolean (*change_is_muted) (GvcMixerStream *stream,
gboolean is_muted);
gboolean (*change_port) (GvcMixerStream *stream,
const char *port);
} GvcMixerStreamClass;
typedef struct
{
char *port;
char *human_port;
guint priority;
gboolean available;
} GvcMixerStreamPort;
GType gvc_mixer_stream_get_type (void);
guint gvc_mixer_stream_get_index (GvcMixerStream *stream);
guint gvc_mixer_stream_get_id (GvcMixerStream *stream);
const GvcChannelMap *gvc_mixer_stream_get_channel_map(GvcMixerStream *stream);
const GvcMixerStreamPort *gvc_mixer_stream_get_port (GvcMixerStream *stream);
const GList * gvc_mixer_stream_get_ports (GvcMixerStream *stream);
gboolean gvc_mixer_stream_change_port (GvcMixerStream *stream,
const char *port);
pa_volume_t gvc_mixer_stream_get_volume (GvcMixerStream *stream);
gdouble gvc_mixer_stream_get_decibel (GvcMixerStream *stream);
gboolean gvc_mixer_stream_push_volume (GvcMixerStream *stream);
pa_volume_t gvc_mixer_stream_get_base_volume (GvcMixerStream *stream);
gboolean gvc_mixer_stream_get_is_muted (GvcMixerStream *stream);
gboolean gvc_mixer_stream_get_can_decibel (GvcMixerStream *stream);
gboolean gvc_mixer_stream_change_is_muted (GvcMixerStream *stream,
gboolean is_muted);
gboolean gvc_mixer_stream_is_running (GvcMixerStream *stream);
const char * gvc_mixer_stream_get_name (GvcMixerStream *stream);
const char * gvc_mixer_stream_get_icon_name (GvcMixerStream *stream);
const char * gvc_mixer_stream_get_sysfs_path (GvcMixerStream *stream);
GIcon * gvc_mixer_stream_get_gicon (GvcMixerStream *stream);
const char * gvc_mixer_stream_get_description (GvcMixerStream *stream);
const char * gvc_mixer_stream_get_application_id (GvcMixerStream *stream);
gboolean gvc_mixer_stream_is_event_stream (GvcMixerStream *stream);
gboolean gvc_mixer_stream_is_virtual (GvcMixerStream *stream);
gint gvc_mixer_stream_get_card_index (GvcMixerStream *stream);
/* private */
gboolean gvc_mixer_stream_set_volume (GvcMixerStream *stream,
pa_volume_t volume);
gboolean gvc_mixer_stream_set_decibel (GvcMixerStream *stream,
gdouble db);
gboolean gvc_mixer_stream_set_is_muted (GvcMixerStream *stream,
gboolean is_muted);
gboolean gvc_mixer_stream_set_can_decibel (GvcMixerStream *stream,
gboolean can_decibel);
gboolean gvc_mixer_stream_set_name (GvcMixerStream *stream,
const char *name);
gboolean gvc_mixer_stream_set_description (GvcMixerStream *stream,
const char *description);
gboolean gvc_mixer_stream_set_icon_name (GvcMixerStream *stream,
const char *name);
gboolean gvc_mixer_stream_set_sysfs_path (GvcMixerStream *stream,
const char *sysfs_path);
gboolean gvc_mixer_stream_set_is_event_stream (GvcMixerStream *stream,
gboolean is_event_stream);
gboolean gvc_mixer_stream_set_is_virtual (GvcMixerStream *stream,
gboolean is_event_stream);
gboolean gvc_mixer_stream_set_application_id (GvcMixerStream *stream,
const char *application_id);
gboolean gvc_mixer_stream_set_base_volume (GvcMixerStream *stream,
pa_volume_t base_volume);
gboolean gvc_mixer_stream_set_port (GvcMixerStream *stream,
const char *port);
gboolean gvc_mixer_stream_set_ports (GvcMixerStream *stream,
GList *ports);
gboolean gvc_mixer_stream_set_card_index (GvcMixerStream *stream,
gint card_index);
G_END_DECLS
#endif /* __GVC_MIXER_STREAM_H */

656
gvc-mixer-ui-device.c Normal file
View File

@ -0,0 +1,656 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* gvc-mixer-ui-device.c
* Copyright (C) Conor Curran 2011 <conor.curran@canonical.com>
* Copyright (C) 2012 David Henningsson, Canonical Ltd. <david.henningsson@canonical.com>
*
* gvc-mixer-ui-device.c 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.
*
* gvc-mixer-ui-device.c 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "gvc-mixer-ui-device.h"
#include "gvc-mixer-card.h"
#define GVC_MIXER_UI_DEVICE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GVC_TYPE_MIXER_UI_DEVICE, GvcMixerUIDevicePrivate))
struct GvcMixerUIDevicePrivate
{
gchar *first_line_desc;
gchar *second_line_desc;
GvcMixerCard *card;
gchar *port_name;
gint stream_id;
guint id;
gboolean port_available;
/* These two lists contain pointers to GvcMixerCardProfile objects. Those objects are owned by GvcMixerCard. *
* TODO: Do we want to add a weak reference to the GvcMixerCard for this reason? */
GList *supported_profiles; /* all profiles supported by this port.*/
GList *profiles; /* profiles to be added to combobox, subset of supported_profiles. */
GvcMixerUIDeviceDirection type;
gboolean disable_profile_swapping;
gchar *user_preferred_profile;
};
enum
{
PROP_0,
PROP_DESC_LINE_1,
PROP_DESC_LINE_2,
PROP_CARD,
PROP_PORT_NAME,
PROP_STREAM_ID,
PROP_UI_DEVICE_TYPE,
PROP_PORT_AVAILABLE,
};
static void gvc_mixer_ui_device_class_init (GvcMixerUIDeviceClass *klass);
static void gvc_mixer_ui_device_init (GvcMixerUIDevice *device);
static void gvc_mixer_ui_device_finalize (GObject *object);
G_DEFINE_TYPE (GvcMixerUIDevice, gvc_mixer_ui_device, G_TYPE_OBJECT);
static guint32
get_next_output_serial (void)
{
static guint32 output_serial = 1;
guint32 serial;
serial = output_serial++;
if ((gint32)output_serial < 0)
output_serial = 1;
return serial;
}
static void
gvc_mixer_ui_device_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GvcMixerUIDevice *self = GVC_MIXER_UI_DEVICE (object);
switch (property_id) {
case PROP_DESC_LINE_1:
g_value_set_string (value, self->priv->first_line_desc);
break;
case PROP_DESC_LINE_2:
g_value_set_string (value, self->priv->second_line_desc);
break;
case PROP_CARD:
g_value_set_pointer (value, self->priv->card);
break;
case PROP_PORT_NAME:
g_value_set_string (value, self->priv->port_name);
break;
case PROP_STREAM_ID:
g_value_set_int (value, self->priv->stream_id);
break;
case PROP_UI_DEVICE_TYPE:
g_value_set_uint (value, (guint)self->priv->type);
break;
case PROP_PORT_AVAILABLE:
g_value_set_boolean (value, self->priv->port_available);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gvc_mixer_ui_device_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GvcMixerUIDevice *self = GVC_MIXER_UI_DEVICE (object);
switch (property_id) {
case PROP_DESC_LINE_1:
g_free (self->priv->first_line_desc);
self->priv->first_line_desc = g_value_dup_string (value);
g_debug ("gvc-mixer-output-set-property - 1st line: %s\n",
self->priv->first_line_desc);
break;
case PROP_DESC_LINE_2:
g_free (self->priv->second_line_desc);
self->priv->second_line_desc = g_value_dup_string (value);
g_debug ("gvc-mixer-output-set-property - 2nd line: %s\n",
self->priv->second_line_desc);
break;
case PROP_CARD:
self->priv->card = g_value_get_pointer (value);
g_debug ("gvc-mixer-output-set-property - card: %p\n",
self->priv->card);
break;
case PROP_PORT_NAME:
g_free (self->priv->port_name);
self->priv->port_name = g_value_dup_string (value);
g_debug ("gvc-mixer-output-set-property - card port name: %s\n",
self->priv->port_name);
break;
case PROP_STREAM_ID:
self->priv->stream_id = g_value_get_int (value);
g_debug ("gvc-mixer-output-set-property - sink/source id: %i\n",
self->priv->stream_id);
break;
case PROP_UI_DEVICE_TYPE:
self->priv->type = (GvcMixerUIDeviceDirection) g_value_get_uint (value);
break;
case PROP_PORT_AVAILABLE:
self->priv->port_available = g_value_get_boolean (value);
g_debug ("gvc-mixer-output-set-property - port available %i, value passed in %i \n",
self->priv->port_available, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static GObject *
gvc_mixer_ui_device_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_params)
{
GObject *object;
GvcMixerUIDevice *self;
object = G_OBJECT_CLASS (gvc_mixer_ui_device_parent_class)->constructor (type, n_construct_properties, construct_params);
self = GVC_MIXER_UI_DEVICE (object);
self->priv->id = get_next_output_serial ();
self->priv->stream_id = GVC_MIXER_UI_DEVICE_INVALID;
return object;
}
static void
gvc_mixer_ui_device_init (GvcMixerUIDevice *device)
{
device->priv = GVC_MIXER_UI_DEVICE_GET_PRIVATE (device);
}
static void
gvc_mixer_ui_device_dispose (GObject *object)
{
GvcMixerUIDevice *device;
g_return_if_fail (object != NULL);
g_return_if_fail (GVC_MIXER_UI_DEVICE (object));
device = GVC_MIXER_UI_DEVICE (object);
g_clear_pointer (&device->priv->port_name, g_free);
g_clear_pointer (&device->priv->first_line_desc, g_free);
g_clear_pointer (&device->priv->second_line_desc, g_free);
g_clear_pointer (&device->priv->profiles, g_list_free);
g_clear_pointer (&device->priv->supported_profiles, g_list_free);
g_clear_pointer (&device->priv->user_preferred_profile, g_free);
G_OBJECT_CLASS (gvc_mixer_ui_device_parent_class)->dispose (object);
}
static void
gvc_mixer_ui_device_finalize (GObject *object)
{
G_OBJECT_CLASS (gvc_mixer_ui_device_parent_class)->finalize (object);
}
static void
gvc_mixer_ui_device_class_init (GvcMixerUIDeviceClass *klass)
{
GObjectClass* object_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
object_class->constructor = gvc_mixer_ui_device_constructor;
object_class->dispose = gvc_mixer_ui_device_dispose;
object_class->finalize = gvc_mixer_ui_device_finalize;
object_class->set_property = gvc_mixer_ui_device_set_property;
object_class->get_property = gvc_mixer_ui_device_get_property;
pspec = g_param_spec_string ("description",
"Description construct prop",
"Set first line description",
"no-name-set",
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_DESC_LINE_1, pspec);
pspec = g_param_spec_string ("origin",
"origin construct prop",
"Set second line description name",
"no-name-set",
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_DESC_LINE_2, pspec);
pspec = g_param_spec_pointer ("card",
"Card from pulse",
"Set/Get card",
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_CARD, pspec);
pspec = g_param_spec_string ("port-name",
"port-name construct prop",
"Set port-name",
NULL,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_PORT_NAME, pspec);
pspec = g_param_spec_int ("stream-id",
"stream id assigned by gvc-stream",
"Set/Get stream id",
-1,
G_MAXINT,
GVC_MIXER_UI_DEVICE_INVALID,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_STREAM_ID, pspec);
pspec = g_param_spec_uint ("type",
"ui-device type",
"determine whether its an input and output",
0, 1, 0, G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_UI_DEVICE_TYPE, pspec);
pspec = g_param_spec_boolean ("port-available",
"available",
"determine whether this port is available",
FALSE,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_PORT_AVAILABLE, pspec);
g_type_class_add_private (klass, sizeof (GvcMixerUIDevicePrivate));
}
/* Removes the part of the string that starts with skip_prefix
* ie. corresponding to the other direction.
* Normally either "input:" or "output:"
*
* Example: if given the input string "output:hdmi-stereo+input:analog-stereo" and
* skip_prefix "input:", the resulting string is "output:hdmi-stereo".
*
* The returned string must be freed with g_free().
*/
static gchar *
get_profile_canonical_name (const gchar *profile_name, const gchar *skip_prefix)
{
gchar *result = NULL;
gchar **s;
int i;
/* optimisation for the simple case. */
if (strstr (profile_name, skip_prefix) == NULL)
return g_strdup (profile_name);
s = g_strsplit (profile_name, "+", 0);
for (i = 0; i < g_strv_length (s); i++) {
if (g_str_has_prefix (s[i], skip_prefix))
continue;
if (result == NULL)
result = g_strdup (s[i]);
else {
gchar *c = g_strdup_printf("%s+%s", result, s[i]);
g_free(result);
result = c;
}
}
g_strfreev(s);
if (!result)
return g_strdup("off");
return result;
}
const gchar *
gvc_mixer_ui_device_get_matching_profile (GvcMixerUIDevice *device, const gchar *profile)
{
gchar *skip_prefix = device->priv->type == UIDeviceInput ? "output:" : "input:";
gchar *target_cname = get_profile_canonical_name (profile, skip_prefix);
GList *l;
gchar *result = NULL;
for (l = device->priv->profiles; l != NULL; l = l->next) {
gchar *canonical_name;
GvcMixerCardProfile* p = l->data;
canonical_name = get_profile_canonical_name (p->profile, skip_prefix);
if (strcmp (canonical_name, target_cname) == 0)
result = p->profile;
g_free (canonical_name);
}
g_free (target_cname);
g_debug ("Matching profile for '%s' is '%s'", profile, result ? result : "(null)");
return result;
}
static void
add_canonical_names_of_profiles (GvcMixerUIDevice *device,
const GList *in_profiles,
GHashTable *added_profiles,
const gchar *skip_prefix,
gboolean only_canonical)
{
const GList *l;
for (l = in_profiles; l != NULL; l = l->next) {
gchar *canonical_name;
GvcMixerCardProfile* p = l->data;
canonical_name = get_profile_canonical_name (p->profile, skip_prefix);
g_debug ("The canonical name for '%s' is '%s'", p->profile, canonical_name);
/* Have we already added the canonical version of this profile? */
if (g_hash_table_contains (added_profiles, canonical_name)) {
g_free (canonical_name);
continue;
}
if (only_canonical && strcmp (p->profile, canonical_name) != 0) {
g_free (canonical_name);
continue;
}
g_free (canonical_name);
g_debug ("Adding profile to combobox: '%s' - '%s'", p->profile, p->human_profile);
g_hash_table_insert (added_profiles, g_strdup (p->profile), p);
device->priv->profiles = g_list_append (device->priv->profiles, p);
}
}
/**
* gvc_mixer_ui_device_set_profiles:
*
* @in_profiles: a list of GvcMixerCardProfile
*
* Assigns value to
* - device->priv->profiles (profiles to be added to combobox)
* - device->priv->supported_profiles (all profiles of this port)
* - device->priv->disable_profile_swapping (whether to show the combobox)
*
* This method attempts to reduce the list of profiles visible to the user by figuring out
* from the context of that device (whether it's an input or an output) what profiles
* actually provide an alternative.
*
* It does this by the following.
* - It ignores off profiles.
* - It takes the canonical name of the profile. That name is what you get when you
* ignore the other direction.
* - In the first iteration, it only adds the names of canonical profiles - i e
* when the other side is turned off.
* - Normally the first iteration covers all cases, but sometimes (e g bluetooth)
* it doesn't, so add other profiles whose canonical name isn't already added
* in a second iteration.
*/
void
gvc_mixer_ui_device_set_profiles (GvcMixerUIDevice *device,
const GList *in_profiles)
{
GHashTable *added_profiles;
gchar *skip_prefix = device->priv->type == UIDeviceInput ? "output:" : "input:";
g_debug ("Set profiles for '%s'", gvc_mixer_ui_device_get_description(device));
if (in_profiles == NULL)
return;
device->priv->supported_profiles = g_list_copy ((GList*) in_profiles);
added_profiles = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
/* Run two iterations: First, add profiles which are canonical themselves,
* Second, add profiles for which the canonical name is not added already. */
add_canonical_names_of_profiles(device, in_profiles, added_profiles, skip_prefix, TRUE);
add_canonical_names_of_profiles(device, in_profiles, added_profiles, skip_prefix, FALSE);
/* TODO: Consider adding the "Off" profile here */
device->priv->disable_profile_swapping = g_hash_table_size (added_profiles) <= 1;
g_hash_table_destroy (added_profiles);
}
/**
* gvc_mixer_ui_device_get_best_profile:
*
* @selected: The selected profile or its canonical name or %NULL for any profile
* @current: The currently selected profile
*
* Returns: (transfer none): a profile name, valid as long as the UI device profiles are.
*/
const gchar *
gvc_mixer_ui_device_get_best_profile (GvcMixerUIDevice *device,
const gchar *selected,
const gchar *current)
{
GList *candidates, *l;
const gchar *result;
gchar *skip_prefix;
gchar *canonical_name_selected;
if (device->priv->type == UIDeviceInput)
skip_prefix = "output:";
else
skip_prefix = "input:";
/* First make a list of profiles acceptable to switch to */
canonical_name_selected = NULL;
if (selected)
canonical_name_selected = get_profile_canonical_name (selected, skip_prefix);
candidates = NULL;
for (l = device->priv->supported_profiles; l != NULL; l = l->next) {
gchar *canonical_name;
GvcMixerCardProfile* p = l->data;
canonical_name = get_profile_canonical_name (p->profile, skip_prefix);
if (!canonical_name_selected || strcmp (canonical_name, canonical_name_selected) == 0) {
candidates = g_list_append (candidates, p);
g_debug ("Candidate for profile switching: '%s'", p->profile);
}
}
if (!candidates) {
g_warning ("No suitable profile candidates for '%s'", selected ? selected : "(null)");
g_free (canonical_name_selected);
return current;
}
/* 1) Maybe we can skip profile switching altogether? */
result = NULL;
for (l = candidates; (result == NULL) && (l != NULL); l = l->next) {
GvcMixerCardProfile* p = l->data;
if (strcmp (current, p->profile) == 0)
result = p->profile;
}
/* 2) Try to keep the other side unchanged if possible */
if (result == NULL) {
guint prio = 0;
gchar *skip_prefix_reverse = device->priv->type == UIDeviceInput ? "input:" : "output:";
gchar *current_reverse = get_profile_canonical_name (current, skip_prefix_reverse);
for (l = candidates; l != NULL; l = l->next) {
gchar *p_reverse;
GvcMixerCardProfile* p = l->data;
p_reverse = get_profile_canonical_name (p->profile, skip_prefix_reverse);
g_debug ("Comparing '%s' (from '%s') with '%s', prio %d", p_reverse, p->profile, current_reverse, p->priority);
if (strcmp (p_reverse, current_reverse) == 0 && (!result || p->priority > prio)) {
result = p->profile;
prio = p->priority;
}
g_free (p_reverse);
}
g_free (current_reverse);
}
/* 3) All right, let's just pick the profile with highest priority.
* TODO: We could consider asking a GUI question if this stops streams
* in the other direction */
if (result == NULL) {
guint prio = 0;
for (l = candidates; l != NULL; l = l->next) {
GvcMixerCardProfile* p = l->data;
if ((p->priority > prio) || !result) {
result = p->profile;
prio = p->priority;
}
}
}
g_list_free (candidates);
g_free (canonical_name_selected);
return result;
}
const gchar *
gvc_mixer_ui_device_get_active_profile (GvcMixerUIDevice* device)
{
GvcMixerCardProfile *profile;
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL);
if (device->priv->card == NULL) {
g_warning ("Device did not have an appropriate card");
return NULL;
}
profile = gvc_mixer_card_get_profile (device->priv->card);
return gvc_mixer_ui_device_get_matching_profile (device, profile->profile);
}
gboolean
gvc_mixer_ui_device_should_profiles_be_hidden (GvcMixerUIDevice *device)
{
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), FALSE);
return device->priv->disable_profile_swapping;
}
GList*
gvc_mixer_ui_device_get_profiles (GvcMixerUIDevice *device)
{
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL);
return device->priv->profiles;
}
GList*
gvc_mixer_ui_device_get_supported_profiles (GvcMixerUIDevice *device)
{
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL);
return device->priv->supported_profiles;
}
guint
gvc_mixer_ui_device_get_id (GvcMixerUIDevice *device)
{
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), 0);
return device->priv->id;
}
gint
gvc_mixer_ui_device_get_stream_id (GvcMixerUIDevice *device)
{
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), 0);
return device->priv->stream_id;
}
void
gvc_mixer_ui_device_invalidate_stream (GvcMixerUIDevice *self)
{
g_return_if_fail (GVC_IS_MIXER_UI_DEVICE (self));
self->priv->stream_id = GVC_MIXER_UI_DEVICE_INVALID;
}
const gchar *
gvc_mixer_ui_device_get_description (GvcMixerUIDevice *device)
{
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL);
return device->priv->first_line_desc;
}
const gchar *
gvc_mixer_ui_device_get_origin (GvcMixerUIDevice *device)
{
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL);
return device->priv->second_line_desc;
}
const gchar*
gvc_mixer_ui_device_get_user_preferred_profile (GvcMixerUIDevice *device)
{
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL);
return device->priv->user_preferred_profile;
}
const gchar *
gvc_mixer_ui_device_get_top_priority_profile (GvcMixerUIDevice *device)
{
GList *last;
GvcMixerCardProfile *profile;
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL);
last = g_list_last (device->priv->supported_profiles);
profile = last->data;
return profile->profile;
}
void
gvc_mixer_ui_device_set_user_preferred_profile (GvcMixerUIDevice *device,
const gchar *profile)
{
g_return_if_fail (GVC_IS_MIXER_UI_DEVICE (device));
g_free (device->priv->user_preferred_profile);
device->priv->user_preferred_profile = g_strdup (profile);
}
const gchar *
gvc_mixer_ui_device_get_port (GvcMixerUIDevice *device)
{
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL);
return device->priv->port_name;
}
gboolean
gvc_mixer_ui_device_has_ports (GvcMixerUIDevice *device)
{
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), FALSE);
return (device->priv->port_name != NULL);
}
gboolean
gvc_mixer_ui_device_is_output (GvcMixerUIDevice *device)
{
g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), FALSE);
return (device->priv->type == UIDeviceOutput);
}

82
gvc-mixer-ui-device.h Normal file
View File

@ -0,0 +1,82 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* Copyright (C) Conor Curran 2011 <conor.curran@canonical.com>
*
* This 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.
*
* gvc-mixer-ui-device.h 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _GVC_MIXER_UI_DEVICE_H_
#define _GVC_MIXER_UI_DEVICE_H_
#include <glib-object.h>
G_BEGIN_DECLS
#define GVC_TYPE_MIXER_UI_DEVICE (gvc_mixer_ui_device_get_type ())
#define GVC_MIXER_UI_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVC_TYPE_MIXER_UI_DEVICE, GvcMixerUIDevice))
#define GVC_MIXER_UI_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVC_TYPE_MIXER_UI_DEVICE, GvcMixerUIDeviceClass))
#define GVC_IS_MIXER_UI_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVC_TYPE_MIXER_UI_DEVICE))
#define GVC_IS_MIXER_UI_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVC_TYPE_MIXER_UI_DEVICE))
#define GVC_MIXER_UI_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVC_TYPE_MIXER_UI_DEVICE, GvcMixerUIDeviceClass))
#define GVC_MIXER_UI_DEVICE_INVALID -1
typedef struct GvcMixerUIDevicePrivate GvcMixerUIDevicePrivate;
typedef struct
{
GObjectClass parent_class;
} GvcMixerUIDeviceClass;
typedef struct
{
GObject parent_instance;
GvcMixerUIDevicePrivate *priv;
} GvcMixerUIDevice;
typedef enum
{
UIDeviceInput,
UIDeviceOutput,
} GvcMixerUIDeviceDirection;
GType gvc_mixer_ui_device_get_type (void) G_GNUC_CONST;
guint gvc_mixer_ui_device_get_id (GvcMixerUIDevice *dev);
gint gvc_mixer_ui_device_get_stream_id (GvcMixerUIDevice *dev);
const gchar * gvc_mixer_ui_device_get_description (GvcMixerUIDevice *dev);
const gchar * gvc_mixer_ui_device_get_origin (GvcMixerUIDevice *dev);
const gchar * gvc_mixer_ui_device_get_port (GvcMixerUIDevice *dev);
const gchar * gvc_mixer_ui_device_get_best_profile (GvcMixerUIDevice *dev,
const gchar *selected,
const gchar *current);
const gchar * gvc_mixer_ui_device_get_active_profile (GvcMixerUIDevice* device);
const gchar * gvc_mixer_ui_device_get_matching_profile (GvcMixerUIDevice *dev,
const gchar *profile);
const gchar * gvc_mixer_ui_device_get_user_preferred_profile (GvcMixerUIDevice *dev);
const gchar * gvc_mixer_ui_device_get_top_priority_profile (GvcMixerUIDevice *dev);
GList * gvc_mixer_ui_device_get_profiles (GvcMixerUIDevice *dev);
GList * gvc_mixer_ui_device_get_supported_profiles (GvcMixerUIDevice *device);
gboolean gvc_mixer_ui_device_should_profiles_be_hidden (GvcMixerUIDevice *device);
void gvc_mixer_ui_device_set_profiles (GvcMixerUIDevice *device,
const GList *profiles);
void gvc_mixer_ui_device_set_user_preferred_profile (GvcMixerUIDevice *device,
const gchar *profile);
void gvc_mixer_ui_device_invalidate_stream (GvcMixerUIDevice *dev);
gboolean gvc_mixer_ui_device_has_ports (GvcMixerUIDevice *dev);
gboolean gvc_mixer_ui_device_is_output (GvcMixerUIDevice *dev);
G_END_DECLS
#endif /* _GVC_MIXER_UI_DEVICE_H_ */

34
gvc-pulseaudio-fake.h Normal file
View File

@ -0,0 +1,34 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GVC_PULSEAUDIO_FAKE_H
#define __GVC_PULSEAUDIO_FAKE_H
#ifdef WITH_INTROSPECTION
#ifndef PA_API_VERSION
#define pa_channel_position_t int
#define pa_volume_t guint32
#define pa_context gpointer
#endif /* PA_API_VERSION */
#endif /* WITH_INTROSPECTION */
#endif /* __GVC_PULSEAUDIO_FAKE_H */