chiark / gitweb /
Fiddle with playing.tmpl a bit. not fully translated
[disorder] / lib / mixer.c
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder
bd8895a8 3 * Copyright (C) 2007 Richard Kettlewell
460b9539 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, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * 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
18 * USA
19 */
b25aac59 20/** @file lib/mixer.c
21 * @brief Mixer support
22 */
460b9539 23
24#include <config.h>
6d2d327c 25#include "types.h"
460b9539 26
460b9539 27#include "configuration.h"
28#include "mixer.h"
29#include "log.h"
b25aac59 30#include "mem.h"
460b9539 31
b25aac59 32/** @brief Whether lack of volume support has been reported yet */
33static int none_reported;
34
35/** @brief Get/set volume stub if volume control is not supported */
36static int none_get_set(int attribute((unused)) *left,
37 int attribute((unused)) *right) {
38 if(!none_reported) {
39 error(0, "don't know how to get/set volume with this api");
40 none_reported = 1;
41 }
42 return -1;
43}
44
45/** @brief Stub mixer control */
46static const struct mixer mixer_none = {
47 -1,
48 none_get_set,
49 none_get_set,
50 "",
51 ""
52};
53
54/** @brief Table of mixer definitions */
bd8895a8 55static const struct mixer *mixers[] = {
460b9539 56#if HAVE_SYS_SOUNDCARD_H
b25aac59 57 &mixer_oss,
58#endif
59#if HAVE_ALSA_ASOUNDLIB_H
60 &mixer_alsa,
460b9539 61#endif
b25aac59 62 &mixer_none /* make sure array is never empty */
bd8895a8 63};
460b9539 64
b25aac59 65/** @brief Number of mixer definitions */
bd8895a8 66#define NMIXERS (sizeof mixers / sizeof *mixers)
67
b25aac59 68/** @brief Find the mixer definition */
bd8895a8 69static const struct mixer *find_mixer(int api) {
70 size_t n;
71
3c499fe7
RK
72 if(api == -1)
73 api = config->api;
bd8895a8 74 for(n = 0; n < NMIXERS; ++n)
75 if(mixers[n]->api == api)
76 return mixers[n];
b25aac59 77 return &mixer_none;
460b9539 78}
79
3c499fe7
RK
80/** @brief Return true if we know how to drive the mixer
81 * @param api Sound api or -1 for default
82 * @return true if suppored, false otherwise
83 */
84int mixer_supported(int api) {
85 const struct mixer *const m = find_mixer(api);
86 return m != &mixer_none;
87}
88
b25aac59 89/** @brief Get/set volume
3c499fe7 90 * @param api Sound api or -1 for default
b25aac59 91 * @param left Left channel level, 0-100
92 * @param right Right channel level, 0-100
93 * @param set Set volume if non-0
94 * @return 0 on success, non-0 on error
95 *
96 * If getting the volume then @p left and @p right are filled in.
97 *
98 * If setting the volume then the target levels are read from @p left and
99 * @p right, and the actual level set is stored in them.
100 */
3c499fe7
RK
101int mixer_control(int api, int *left, int *right, int set) {
102 const struct mixer *const m = find_mixer(api);
bd8895a8 103
b25aac59 104 /* We impose defaults bizarrely late, but this has the advantage of
105 * not making everything depend on sound libraries */
106 if(!config->mixer)
107 config->mixer = xstrdup(m->device);
108 if(!config->channel)
109 config->channel = xstrdup(m->channel);
110 if(set)
111 return m->set(left, right);
112 else
113 return m->get(left, right);
460b9539 114}
460b9539 115
116/*
117Local Variables:
118c-basic-offset:2
119comment-column:40
120End:
121*/