~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to panels/sound/gvc-channel-map.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
 
2
 *
 
3
 * Copyright (C) 2008 William Jon McCann
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 *
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <unistd.h>
 
26
 
 
27
#include <glib.h>
 
28
#include <glib/gi18n-lib.h>
 
29
 
 
30
#include <pulse/pulseaudio.h>
 
31
 
 
32
#include "gvc-channel-map.h"
 
33
#include "gvc-channel-map-private.h"
 
34
 
 
35
#define GVC_CHANNEL_MAP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_CHANNEL_MAP, GvcChannelMapPrivate))
 
36
 
 
37
struct GvcChannelMapPrivate
 
38
{
 
39
        pa_channel_map        pa_map;
 
40
        gboolean              pa_volume_is_set;
 
41
        pa_cvolume            pa_volume;
 
42
        gdouble               extern_volume[NUM_TYPES]; /* volume, balance, fade, lfe */
 
43
        gboolean              can_balance;
 
44
        gboolean              can_fade;
 
45
};
 
46
 
 
47
enum {
 
48
        VOLUME_CHANGED,
 
49
        LAST_SIGNAL
 
50
};
 
51
 
 
52
static guint signals [LAST_SIGNAL] = { 0, };
 
53
 
 
54
static void     gvc_channel_map_class_init (GvcChannelMapClass *klass);
 
55
static void     gvc_channel_map_init       (GvcChannelMap      *channel_map);
 
56
static void     gvc_channel_map_finalize   (GObject            *object);
 
57
 
 
58
G_DEFINE_TYPE (GvcChannelMap, gvc_channel_map, G_TYPE_OBJECT)
 
59
 
 
60
guint
 
61
gvc_channel_map_get_num_channels (const GvcChannelMap *map)
 
62
{
 
63
        g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), 0);
 
64
 
 
65
        if (!pa_channel_map_valid(&map->priv->pa_map))
 
66
                return 0;
 
67
 
 
68
        return map->priv->pa_map.channels;
 
69
}
 
70
 
 
71
const gdouble *
 
72
gvc_channel_map_get_volume (GvcChannelMap *map)
 
73
{
 
74
        g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
 
75
 
 
76
        if (!pa_channel_map_valid(&map->priv->pa_map))
 
77
                return NULL;
 
78
 
 
79
        map->priv->extern_volume[VOLUME] = (gdouble) pa_cvolume_max (&map->priv->pa_volume);
 
80
        if (gvc_channel_map_can_balance (map))
 
81
                map->priv->extern_volume[BALANCE] = (gdouble) pa_cvolume_get_balance (&map->priv->pa_volume, &map->priv->pa_map);
 
82
        else
 
83
                map->priv->extern_volume[BALANCE] = 0;
 
84
        if (gvc_channel_map_can_fade (map))
 
85
                map->priv->extern_volume[FADE] = (gdouble) pa_cvolume_get_fade (&map->priv->pa_volume, &map->priv->pa_map);
 
86
        else
 
87
                map->priv->extern_volume[FADE] = 0;
 
88
        if (gvc_channel_map_has_lfe (map))
 
89
                map->priv->extern_volume[LFE] = (gdouble) pa_cvolume_get_position (&map->priv->pa_volume, &map->priv->pa_map, PA_CHANNEL_POSITION_LFE);
 
90
        else
 
91
                map->priv->extern_volume[LFE] = 0;
 
92
 
 
93
        return map->priv->extern_volume;
 
94
}
 
95
 
 
96
gboolean
 
97
gvc_channel_map_can_balance (const GvcChannelMap  *map)
 
98
{
 
99
        g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
 
100
 
 
101
        return map->priv->can_balance;
 
102
}
 
103
 
 
104
gboolean
 
105
gvc_channel_map_can_fade (const GvcChannelMap  *map)
 
106
{
 
107
        g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
 
108
 
 
109
        return map->priv->can_fade;
 
110
}
 
111
 
 
112
const char *
 
113
gvc_channel_map_get_mapping (const GvcChannelMap  *map)
 
114
{
 
115
        g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
 
116
 
 
117
        if (!pa_channel_map_valid(&map->priv->pa_map))
 
118
                return NULL;
 
119
 
 
120
        return pa_channel_map_to_pretty_name (&map->priv->pa_map);
 
121
}
 
122
 
 
123
/**
 
124
 * gvc_channel_map_has_position: (skip)
 
125
 *
 
126
 * @map:
 
127
 * @position:
 
128
 *
 
129
 * Returns:
 
130
 */
 
131
gboolean
 
132
gvc_channel_map_has_position (const GvcChannelMap  *map,
 
133
                              pa_channel_position_t position)
 
134
{
 
135
        g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
 
136
 
 
137
        return pa_channel_map_has_position (&(map->priv->pa_map), position);
 
138
}
 
139
 
 
140
const pa_channel_map *
 
141
gvc_channel_map_get_pa_channel_map (const GvcChannelMap  *map)
 
142
{
 
143
        g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
 
144
 
 
145
        if (!pa_channel_map_valid(&map->priv->pa_map))
 
146
                return NULL;
 
147
 
 
148
        return &map->priv->pa_map;
 
149
}
 
150
 
 
151
const pa_cvolume *
 
152
gvc_channel_map_get_cvolume (const GvcChannelMap  *map)
 
153
{
 
154
        g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
 
155
 
 
156
        if (!pa_channel_map_valid(&map->priv->pa_map))
 
157
                return NULL;
 
158
 
 
159
        return &map->priv->pa_volume;
 
160
}
 
161
 
 
162
static void
 
163
gvc_channel_map_class_init (GvcChannelMapClass *klass)
 
164
{
 
165
        GObjectClass   *gobject_class = G_OBJECT_CLASS (klass);
 
166
 
 
167
        gobject_class->finalize = gvc_channel_map_finalize;
 
168
 
 
169
        signals [VOLUME_CHANGED] =
 
170
                g_signal_new ("volume-changed",
 
171
                              G_TYPE_FROM_CLASS (klass),
 
172
                              G_SIGNAL_RUN_LAST,
 
173
                              G_STRUCT_OFFSET (GvcChannelMapClass, volume_changed),
 
174
                              NULL, NULL,
 
175
                              g_cclosure_marshal_VOID__BOOLEAN,
 
176
                              G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
 
177
 
 
178
        g_type_class_add_private (klass, sizeof (GvcChannelMapPrivate));
 
179
}
 
180
 
 
181
void
 
182
gvc_channel_map_volume_changed (GvcChannelMap     *map,
 
183
                                const pa_cvolume  *cv,
 
184
                                gboolean           set)
 
185
{
 
186
        g_return_if_fail (GVC_IS_CHANNEL_MAP (map));
 
187
        g_return_if_fail (cv != NULL);
 
188
        g_return_if_fail (pa_cvolume_compatible_with_channel_map(cv, &map->priv->pa_map));
 
189
 
 
190
        if (pa_cvolume_equal(cv, &map->priv->pa_volume))
 
191
                return;
 
192
 
 
193
        map->priv->pa_volume = *cv;
 
194
 
 
195
        if (map->priv->pa_volume_is_set == FALSE) {
 
196
                map->priv->pa_volume_is_set = TRUE;
 
197
                return;
 
198
        }
 
199
        g_signal_emit (map, signals[VOLUME_CHANGED], 0, set);
 
200
}
 
201
 
 
202
static void
 
203
gvc_channel_map_init (GvcChannelMap *map)
 
204
{
 
205
        map->priv = GVC_CHANNEL_MAP_GET_PRIVATE (map);
 
206
        map->priv->pa_volume_is_set = FALSE;
 
207
}
 
208
 
 
209
static void
 
210
gvc_channel_map_finalize (GObject *object)
 
211
{
 
212
        GvcChannelMap *channel_map;
 
213
 
 
214
        g_return_if_fail (object != NULL);
 
215
        g_return_if_fail (GVC_IS_CHANNEL_MAP (object));
 
216
 
 
217
        channel_map = GVC_CHANNEL_MAP (object);
 
218
 
 
219
        g_return_if_fail (channel_map->priv != NULL);
 
220
 
 
221
        G_OBJECT_CLASS (gvc_channel_map_parent_class)->finalize (object);
 
222
}
 
223
 
 
224
GvcChannelMap *
 
225
gvc_channel_map_new (void)
 
226
{
 
227
        GObject *map;
 
228
        map = g_object_new (GVC_TYPE_CHANNEL_MAP, NULL);
 
229
        return GVC_CHANNEL_MAP (map);
 
230
}
 
231
 
 
232
static void
 
233
set_from_pa_map (GvcChannelMap        *map,
 
234
                 const pa_channel_map *pa_map)
 
235
{
 
236
        g_assert (pa_channel_map_valid(pa_map));
 
237
 
 
238
        map->priv->can_balance = pa_channel_map_can_balance (pa_map);
 
239
        map->priv->can_fade = pa_channel_map_can_fade (pa_map);
 
240
 
 
241
        map->priv->pa_map = *pa_map;
 
242
        pa_cvolume_set(&map->priv->pa_volume, pa_map->channels, PA_VOLUME_NORM);
 
243
}
 
244
 
 
245
GvcChannelMap *
 
246
gvc_channel_map_new_from_pa_channel_map (const pa_channel_map *pa_map)
 
247
{
 
248
        GObject *map;
 
249
        map = g_object_new (GVC_TYPE_CHANNEL_MAP, NULL);
 
250
 
 
251
        set_from_pa_map (GVC_CHANNEL_MAP (map), pa_map);
 
252
 
 
253
        return GVC_CHANNEL_MAP (map);
 
254
}