1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* Copyright (C) 2008 William Jon McCann
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
#include <glib/gi18n.h>
30
#include <pulse/pulseaudio.h>
32
#include "gvc-channel-map.h"
34
#define GVC_CHANNEL_MAP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_CHANNEL_MAP, GvcChannelMapPrivate))
36
struct GvcChannelMapPrivate
39
pa_channel_position_t positions[PA_CHANNELS_MAX];
40
gdouble gains[PA_CHANNELS_MAX];
49
static guint signals [LAST_SIGNAL] = { 0, };
51
static void gvc_channel_map_class_init (GvcChannelMapClass *klass);
52
static void gvc_channel_map_init (GvcChannelMap *channel_map);
53
static void gvc_channel_map_finalize (GObject *object);
55
G_DEFINE_TYPE (GvcChannelMap, gvc_channel_map, G_TYPE_OBJECT)
58
gvc_channel_map_get_num_channels (GvcChannelMap *map)
60
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), 0);
61
return map->priv->num_channels;
65
gvc_channel_map_get_gains (GvcChannelMap *map)
67
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
68
return map->priv->gains;
71
pa_channel_position_t *
72
gvc_channel_map_get_positions (GvcChannelMap *map)
74
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
75
return map->priv->positions;
79
gvc_channel_map_can_balance (GvcChannelMap *map)
81
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
82
return map->priv->can_balance;
86
gvc_channel_map_class_init (GvcChannelMapClass *klass)
88
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
90
gobject_class->finalize = gvc_channel_map_finalize;
92
signals [GAINS_CHANGED] =
93
g_signal_new ("gains-changed",
94
G_TYPE_FROM_CLASS (klass),
96
G_STRUCT_OFFSET (GvcChannelMapClass, gains_changed),
98
g_cclosure_marshal_VOID__VOID,
101
g_type_class_add_private (klass, sizeof (GvcChannelMapPrivate));
105
gvc_channel_map_gains_changed (GvcChannelMap *map)
107
g_return_if_fail (GVC_IS_CHANNEL_MAP (map));
108
g_signal_emit (map, signals[GAINS_CHANGED], 0);
112
gvc_channel_map_init (GvcChannelMap *map)
114
map->priv = GVC_CHANNEL_MAP_GET_PRIVATE (map);
118
gvc_channel_map_finalize (GObject *object)
120
GvcChannelMap *channel_map;
122
g_return_if_fail (object != NULL);
123
g_return_if_fail (GVC_IS_CHANNEL_MAP (object));
125
channel_map = GVC_CHANNEL_MAP (object);
127
g_return_if_fail (channel_map->priv != NULL);
129
G_OBJECT_CLASS (gvc_channel_map_parent_class)->finalize (object);
133
gvc_channel_map_new (void)
136
map = g_object_new (GVC_TYPE_CHANNEL_MAP, NULL);
137
return GVC_CHANNEL_MAP (map);
141
set_from_pa_map (GvcChannelMap *map,
142
const pa_channel_map *pa_map)
146
map->priv->num_channels = pa_map->channels;
147
#ifdef HAVE_NEW_PULSE
148
map->priv->can_balance = pa_channel_map_can_balance (pa_map);
150
map->priv->can_balance = TRUE;
152
for (i = 0; i < pa_map->channels; i++) {
153
map->priv->positions[i] = pa_map->map[i];
154
map->priv->gains[i] = 1.0;
159
gvc_channel_map_new_from_pa_channel_map (const pa_channel_map *pa_map)
162
map = g_object_new (GVC_TYPE_CHANNEL_MAP, NULL);
164
set_from_pa_map (GVC_CHANNEL_MAP (map), pa_map);
166
return GVC_CHANNEL_MAP (map);