Skip to content

Commit 0ddf9c5

Browse files
committed
added gvc module
1 parent 78a0da5 commit 0ddf9c5

32 files changed

+8800
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pkg/
1+
pkg/
2+
*.pkg.tar*

PKGBUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ prepare() {
2727
build() {
2828
cd $srcdir
2929
npm install
30-
arch-meson build --libdir "lib/$_pkgname" -Dbuild_types=true
30+
arch-meson build --libdir "lib/$pkgname" -Dbuild_types=true
3131
meson compile -C build
3232
}
3333

src/subprojects/gvc/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# libgnome-volume-control
2+
3+
libgnome-volume-control is a copy library that's supposed to be used as
4+
a git sub-module. If your project uses some of libgnome-volume-control's
5+
strings in a user-facing manner, don't forget to add those files to your
6+
POTFILES.in for translation.
7+
8+
## Projects using libgnome-volume-control
9+
10+
- [gnome-shell](https://gitlab.gnome.org/GNOME/gnome-shell)
11+
- [gnome-settings-daemon](https://gitlab.gnome.org/GNOME/gnome-settings-daemon)
12+
- [gnome-control-center](https://gitlab.gnome.org/GNOME/gnome-control-center)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2+
*
3+
* Copyright (C) 2008 Red Hat, Inc.
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+
#ifndef __GVC_CHANNEL_MAP_PRIVATE_H
22+
#define __GVC_CHANNEL_MAP_PRIVATE_H
23+
24+
#include <glib-object.h>
25+
#include <pulse/pulseaudio.h>
26+
27+
G_BEGIN_DECLS
28+
29+
GvcChannelMap * gvc_channel_map_new_from_pa_channel_map (const pa_channel_map *map);
30+
const pa_channel_map * gvc_channel_map_get_pa_channel_map (const GvcChannelMap *map);
31+
32+
void gvc_channel_map_volume_changed (GvcChannelMap *map,
33+
const pa_cvolume *cv,
34+
gboolean set);
35+
const pa_cvolume * gvc_channel_map_get_cvolume (const GvcChannelMap *map);
36+
37+
G_END_DECLS
38+
39+
#endif /* __GVC_CHANNEL_MAP_PRIVATE_H */
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
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+
struct GvcChannelMapPrivate
36+
{
37+
pa_channel_map pa_map;
38+
gboolean pa_volume_is_set;
39+
pa_cvolume pa_volume;
40+
gdouble extern_volume[NUM_TYPES]; /* volume, balance, fade, lfe */
41+
gboolean can_balance;
42+
gboolean can_fade;
43+
};
44+
45+
enum {
46+
VOLUME_CHANGED,
47+
LAST_SIGNAL
48+
};
49+
50+
static guint signals [LAST_SIGNAL] = { 0, };
51+
52+
static void gvc_channel_map_finalize (GObject *object);
53+
54+
G_DEFINE_TYPE_WITH_PRIVATE (GvcChannelMap, gvc_channel_map, G_TYPE_OBJECT)
55+
56+
guint
57+
gvc_channel_map_get_num_channels (const GvcChannelMap *map)
58+
{
59+
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), 0);
60+
61+
if (!pa_channel_map_valid(&map->priv->pa_map))
62+
return 0;
63+
64+
return map->priv->pa_map.channels;
65+
}
66+
67+
const gdouble *
68+
gvc_channel_map_get_volume (GvcChannelMap *map)
69+
{
70+
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
71+
72+
if (!pa_channel_map_valid(&map->priv->pa_map))
73+
return NULL;
74+
75+
map->priv->extern_volume[VOLUME] = (gdouble) pa_cvolume_max (&map->priv->pa_volume);
76+
if (gvc_channel_map_can_balance (map))
77+
map->priv->extern_volume[BALANCE] = (gdouble) pa_cvolume_get_balance (&map->priv->pa_volume, &map->priv->pa_map);
78+
else
79+
map->priv->extern_volume[BALANCE] = 0;
80+
if (gvc_channel_map_can_fade (map))
81+
map->priv->extern_volume[FADE] = (gdouble) pa_cvolume_get_fade (&map->priv->pa_volume, &map->priv->pa_map);
82+
else
83+
map->priv->extern_volume[FADE] = 0;
84+
if (gvc_channel_map_has_lfe (map))
85+
map->priv->extern_volume[LFE] = (gdouble) pa_cvolume_get_position (&map->priv->pa_volume, &map->priv->pa_map, PA_CHANNEL_POSITION_LFE);
86+
else
87+
map->priv->extern_volume[LFE] = 0;
88+
89+
return map->priv->extern_volume;
90+
}
91+
92+
gboolean
93+
gvc_channel_map_can_balance (const GvcChannelMap *map)
94+
{
95+
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
96+
97+
return map->priv->can_balance;
98+
}
99+
100+
gboolean
101+
gvc_channel_map_can_fade (const GvcChannelMap *map)
102+
{
103+
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
104+
105+
return map->priv->can_fade;
106+
}
107+
108+
const char *
109+
gvc_channel_map_get_mapping (const GvcChannelMap *map)
110+
{
111+
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
112+
113+
if (!pa_channel_map_valid(&map->priv->pa_map))
114+
return NULL;
115+
116+
return pa_channel_map_to_pretty_name (&map->priv->pa_map);
117+
}
118+
119+
/**
120+
* gvc_channel_map_has_position: (skip)
121+
* @map:
122+
* @position:
123+
*
124+
* Returns:
125+
*/
126+
gboolean
127+
gvc_channel_map_has_position (const GvcChannelMap *map,
128+
pa_channel_position_t position)
129+
{
130+
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE);
131+
132+
return pa_channel_map_has_position (&(map->priv->pa_map), position);
133+
}
134+
135+
const pa_channel_map *
136+
gvc_channel_map_get_pa_channel_map (const GvcChannelMap *map)
137+
{
138+
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
139+
140+
if (!pa_channel_map_valid(&map->priv->pa_map))
141+
return NULL;
142+
143+
return &map->priv->pa_map;
144+
}
145+
146+
const pa_cvolume *
147+
gvc_channel_map_get_cvolume (const GvcChannelMap *map)
148+
{
149+
g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL);
150+
151+
if (!pa_channel_map_valid(&map->priv->pa_map))
152+
return NULL;
153+
154+
return &map->priv->pa_volume;
155+
}
156+
157+
static void
158+
gvc_channel_map_class_init (GvcChannelMapClass *klass)
159+
{
160+
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
161+
162+
gobject_class->finalize = gvc_channel_map_finalize;
163+
164+
signals [VOLUME_CHANGED] =
165+
g_signal_new ("volume-changed",
166+
G_TYPE_FROM_CLASS (klass),
167+
G_SIGNAL_RUN_LAST,
168+
G_STRUCT_OFFSET (GvcChannelMapClass, volume_changed),
169+
NULL, NULL,
170+
g_cclosure_marshal_VOID__BOOLEAN,
171+
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
172+
}
173+
174+
void
175+
gvc_channel_map_volume_changed (GvcChannelMap *map,
176+
const pa_cvolume *cv,
177+
gboolean set)
178+
{
179+
g_return_if_fail (GVC_IS_CHANNEL_MAP (map));
180+
g_return_if_fail (cv != NULL);
181+
g_return_if_fail (pa_cvolume_compatible_with_channel_map(cv, &map->priv->pa_map));
182+
183+
if (pa_cvolume_equal(cv, &map->priv->pa_volume))
184+
return;
185+
186+
map->priv->pa_volume = *cv;
187+
188+
if (map->priv->pa_volume_is_set == FALSE) {
189+
map->priv->pa_volume_is_set = TRUE;
190+
return;
191+
}
192+
g_signal_emit (map, signals[VOLUME_CHANGED], 0, set);
193+
}
194+
195+
static void
196+
gvc_channel_map_init (GvcChannelMap *map)
197+
{
198+
map->priv = gvc_channel_map_get_instance_private (map);
199+
map->priv->pa_volume_is_set = FALSE;
200+
}
201+
202+
static void
203+
gvc_channel_map_finalize (GObject *object)
204+
{
205+
GvcChannelMap *channel_map;
206+
207+
g_return_if_fail (object != NULL);
208+
g_return_if_fail (GVC_IS_CHANNEL_MAP (object));
209+
210+
channel_map = GVC_CHANNEL_MAP (object);
211+
212+
g_return_if_fail (channel_map->priv != NULL);
213+
214+
G_OBJECT_CLASS (gvc_channel_map_parent_class)->finalize (object);
215+
}
216+
217+
GvcChannelMap *
218+
gvc_channel_map_new (void)
219+
{
220+
GObject *map;
221+
map = g_object_new (GVC_TYPE_CHANNEL_MAP, NULL);
222+
return GVC_CHANNEL_MAP (map);
223+
}
224+
225+
static void
226+
set_from_pa_map (GvcChannelMap *map,
227+
const pa_channel_map *pa_map)
228+
{
229+
g_assert (pa_channel_map_valid(pa_map));
230+
231+
map->priv->can_balance = pa_channel_map_can_balance (pa_map);
232+
map->priv->can_fade = pa_channel_map_can_fade (pa_map);
233+
234+
map->priv->pa_map = *pa_map;
235+
pa_cvolume_set(&map->priv->pa_volume, pa_map->channels, PA_VOLUME_NORM);
236+
}
237+
238+
GvcChannelMap *
239+
gvc_channel_map_new_from_pa_channel_map (const pa_channel_map *pa_map)
240+
{
241+
GObject *map;
242+
map = g_object_new (GVC_TYPE_CHANNEL_MAP, NULL);
243+
244+
set_from_pa_map (GVC_CHANNEL_MAP (map), pa_map);
245+
246+
return GVC_CHANNEL_MAP (map);
247+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2+
*
3+
* Copyright (C) 2008 Red Hat, Inc.
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+
#ifndef __GVC_CHANNEL_MAP_H
22+
#define __GVC_CHANNEL_MAP_H
23+
24+
#include <glib-object.h>
25+
#include <gvc-pulseaudio-fake.h>
26+
27+
G_BEGIN_DECLS
28+
29+
#define GVC_TYPE_CHANNEL_MAP (gvc_channel_map_get_type ())
30+
#define GVC_CHANNEL_MAP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_CHANNEL_MAP, GvcChannelMap))
31+
#define GVC_CHANNEL_MAP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_CHANNEL_MAP, GvcChannelMapClass))
32+
#define GVC_IS_CHANNEL_MAP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_CHANNEL_MAP))
33+
#define GVC_IS_CHANNEL_MAP_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_CHANNEL_MAP))
34+
#define GVC_CHANNEL_MAP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_CHANNEL_MAP, GvcChannelMapClass))
35+
36+
typedef struct GvcChannelMapPrivate GvcChannelMapPrivate;
37+
38+
typedef struct
39+
{
40+
GObject parent;
41+
GvcChannelMapPrivate *priv;
42+
} GvcChannelMap;
43+
44+
typedef struct
45+
{
46+
GObjectClass parent_class;
47+
void (*volume_changed) (GvcChannelMap *channel_map, gboolean set);
48+
} GvcChannelMapClass;
49+
50+
enum {
51+
VOLUME,
52+
BALANCE,
53+
FADE,
54+
LFE,
55+
NUM_TYPES
56+
};
57+
58+
GType gvc_channel_map_get_type (void);
59+
60+
GvcChannelMap * gvc_channel_map_new (void);
61+
guint gvc_channel_map_get_num_channels (const GvcChannelMap *map);
62+
const gdouble * gvc_channel_map_get_volume (GvcChannelMap *map);
63+
gboolean gvc_channel_map_can_balance (const GvcChannelMap *map);
64+
gboolean gvc_channel_map_can_fade (const GvcChannelMap *map);
65+
gboolean gvc_channel_map_has_position (const GvcChannelMap *map,
66+
pa_channel_position_t position);
67+
#define gvc_channel_map_has_lfe(x) gvc_channel_map_has_position (x, PA_CHANNEL_POSITION_LFE)
68+
69+
const char * gvc_channel_map_get_mapping (const GvcChannelMap *map);
70+
71+
G_END_DECLS
72+
73+
#endif /* __GVC_CHANNEL_MAP_H */

0 commit comments

Comments
 (0)