~ubuntu-branches/ubuntu/saucy/mpd/saucy

« back to all changes in this revision

Viewing changes to src/mixer_all.c

  • Committer: Bazaar Package Importer
  • Author(s): Angel Abad
  • Date: 2011-02-02 12:26:30 UTC
  • mfrom: (1.5.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20110202122630-bdyx8w4k94doz4fs
Tags: 0.16.1-1ubuntu1
* Merge from debian unstable. Remaining changes:
  - debian/control:
    + Don't build-depend on libmikmod2-dev (Debian bug #510675).
    + Move avahi-daemon from Suggests field to Recommends field.
  - debian/mpd.init.d:
    + Read mpd user from mpd.conf.
  - debian/control, debian/rules:
    + Add libmp3lame-dev to the build dependencies and enable lame.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2003-2009 The Music Player Daemon Project
 
2
 * Copyright (C) 2003-2010 The Music Player Daemon Project
3
3
 * http://www.musicpd.org
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or modify
17
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
18
 */
19
19
 
 
20
#include "config.h"
20
21
#include "mixer_all.h"
21
22
#include "mixer_control.h"
22
23
#include "output_all.h"
23
24
#include "output_plugin.h"
24
25
#include "output_internal.h"
 
26
#include "pcm_volume.h"
 
27
#include "mixer_api.h"
 
28
#include "mixer_list.h"
25
29
 
26
30
#include <glib.h>
27
31
 
35
39
{
36
40
        struct audio_output *output;
37
41
        struct mixer *mixer;
 
42
        int volume;
 
43
        GError *error = NULL;
38
44
 
39
45
        assert(i < audio_output_count());
40
46
 
46
52
        if (mixer == NULL)
47
53
                return -1;
48
54
 
49
 
        return mixer_get_volume(mixer);
 
55
        volume = mixer_get_volume(mixer, &error);
 
56
        if (volume < 0 && error != NULL) {
 
57
                g_warning("Failed to read mixer for '%s': %s",
 
58
                          output->name, error->message);
 
59
                g_error_free(error);
 
60
        }
 
61
 
 
62
        return volume;
50
63
}
51
64
 
52
65
int
70
83
}
71
84
 
72
85
static bool
73
 
output_mixer_set_volume(unsigned i, int volume, bool relative)
 
86
output_mixer_set_volume(unsigned i, unsigned volume)
74
87
{
75
88
        struct audio_output *output;
76
89
        struct mixer *mixer;
 
90
        bool success;
 
91
        GError *error = NULL;
77
92
 
78
93
        assert(i < audio_output_count());
 
94
        assert(volume <= 100);
79
95
 
80
96
        output = audio_output_get(i);
81
97
        if (!output->enabled)
85
101
        if (mixer == NULL)
86
102
                return false;
87
103
 
88
 
        if (relative) {
89
 
                int prev = mixer_get_volume(mixer);
90
 
                if (prev < 0)
91
 
                        return false;
92
 
 
93
 
                volume += prev;
 
104
        success = mixer_set_volume(mixer, volume, &error);
 
105
        if (!success && error != NULL) {
 
106
                g_warning("Failed to set mixer for '%s': %s",
 
107
                          output->name, error->message);
 
108
                g_error_free(error);
94
109
        }
95
110
 
96
 
        if (volume > 100)
97
 
                volume = 100;
98
 
        else if (volume < 0)
99
 
                volume = 0;
100
 
 
101
 
        return mixer_set_volume(mixer, volume);
 
111
        return success;
102
112
}
103
113
 
104
114
bool
105
 
mixer_all_set_volume(int volume, bool relative)
 
115
mixer_all_set_volume(unsigned volume)
106
116
{
107
117
        bool success = false;
108
118
        unsigned count = audio_output_count();
109
119
 
 
120
        assert(volume <= 100);
 
121
 
110
122
        for (unsigned i = 0; i < count; i++)
111
 
                success = output_mixer_set_volume(i, volume, relative)
 
123
                success = output_mixer_set_volume(i, volume)
112
124
                        || success;
113
125
 
114
126
        return success;
115
127
}
 
128
 
 
129
static int
 
130
output_mixer_get_software_volume(unsigned i)
 
131
{
 
132
        struct audio_output *output;
 
133
        struct mixer *mixer;
 
134
 
 
135
        assert(i < audio_output_count());
 
136
 
 
137
        output = audio_output_get(i);
 
138
        if (!output->enabled)
 
139
                return -1;
 
140
 
 
141
        mixer = output->mixer;
 
142
        if (mixer == NULL || mixer->plugin != &software_mixer_plugin)
 
143
                return -1;
 
144
 
 
145
        return mixer_get_volume(mixer, NULL);
 
146
}
 
147
 
 
148
int
 
149
mixer_all_get_software_volume(void)
 
150
{
 
151
        unsigned count = audio_output_count(), ok = 0;
 
152
        int volume, total = 0;
 
153
 
 
154
        for (unsigned i = 0; i < count; i++) {
 
155
                volume = output_mixer_get_software_volume(i);
 
156
                if (volume >= 0) {
 
157
                        total += volume;
 
158
                        ++ok;
 
159
                }
 
160
        }
 
161
 
 
162
        if (ok == 0)
 
163
                return -1;
 
164
 
 
165
        return total / ok;
 
166
}
 
167
 
 
168
void
 
169
mixer_all_set_software_volume(unsigned volume)
 
170
{
 
171
        unsigned count = audio_output_count();
 
172
 
 
173
        assert(volume <= PCM_VOLUME_1);
 
174
 
 
175
        for (unsigned i = 0; i < count; i++) {
 
176
                struct audio_output *output = audio_output_get(i);
 
177
                if (output->mixer != NULL &&
 
178
                    output->mixer->plugin == &software_mixer_plugin)
 
179
                        mixer_set_volume(output->mixer, volume, NULL);
 
180
        }
 
181
}