1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set et sw=2 ts=2: */
/***************************************************************************
* aiomixer.cc
*
* Wed Sep 24 11:06:36 CEST 2014
* Copyright 2014 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
/*
* This file is part of LibAudioIO.
*
* LibAudioIO is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* LibAudioIO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with LibAudioIO; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <getopt.h>
#include <config.h>
#include "device.h"
#include "mixer.h"
static const char version_str[] =
"aiomixer v" VERSION "\n"
;
static const char copyright_str[] =
"Copyright (C) 2014 Bent Bisballe Nyeng - Aasimon.org.\n"
"This is free software. You may redistribute copies of it under the terms of\n"
"the GNU Lesser General Public License "
"<http://www.gnu.org/licenses/lgpl.html>.\n"
"There is NO WARRANTY, to the extent permitted by law.\n"
"\n"
"Written by Bent Bisballe Nyeng (deva@aasimon.org)\n"
;
static const char usage_str[] =
"Usage: %s card [-l] [mixer [options]]\n"
"Options:\n"
" -L, --list List controls on card.\n"
" -E, --list-enum List enumeration values\n"
" -e, --enum y Set value of enum to y\n"
" -e, --enum Get value of enum\n"
" -C, --channels Get number of channels in mixer\n"
" -l, --level n=m Set level of channel n to value m\n"
" -l, --level n Get level of channel n\n"
" -m, --mute Get mute state\n"
" -m, --mute m Set mute state to m. either 1 (mute) or 0 (unmute)\n"
" -r, --range Get range of mixer\n"
" -c, --capture Get capture mode.\n"
" -c, --capture n Set capture mode to n (1 or 0).\n"
" -v, --version Print version information and exit.\n"
" -h, --help Print this message and exit.\n"
;
int main(int argc, char *argv[])
{
int c;
char *p;
bool list = false;
bool show_enum = false;
bool list_enums = false;
bool range = false;
bool num_channels = false;
bool show_mute = false;
int set_mute = -1;
bool show_capture = false;
int set_capture = -1;
std::string enum_value;
int level_name = -1;
float level_value = -999999;
int option_index = 0;
while(1) {
static struct option long_options[] = {
{"list", no_argument, 0, 'L'},
{"list-enum", no_argument, 0, 'E'},
{"enum", optional_argument, 0, 'e'},
{"channels", no_argument, 0, 'C'},
{"level", required_argument, 0, 'l'},
{"mute", optional_argument, 0, 'm'},
{"range", no_argument, 0, 'r'},
{"capture", optional_argument, 0, 'c'},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "hvLe::l::rEm::Cc::",
long_options, &option_index);
if (c == -1)
break;
switch(c) {
case 'L':
list = true;
break;
case 'r':
range = true;
break;
case 'C':
num_channels = true;
break;
case 'm':
if(!optarg) show_mute = true;
else set_mute = atoi(optarg);
break;
case 'c':
if(!optarg) show_capture = true;
else set_capture = atoi(optarg);
break;
case 'E':
list_enums = true;
break;
case 'e':
show_enum = !optarg;
if(optarg) enum_value = optarg;
break;
case 'l':
p = strchr(optarg, '=');
if(p) {
*p = '\0';
level_value = atof(p+1);
}
level_name = atoi(optarg);
break;
case '?':
case 'h':
printf("%s", version_str);
printf(usage_str, argv[0]);
return 0;
case 'v':
printf("%s", version_str);
printf("%s", copyright_str);
return 0;
default:
break;
}
}
std::string device;
std::string mixer;
int arg = 0;
if(option_index < argc) {
while(optind < argc) {
switch(arg) {
case 0: device = argv[optind++]; break;
case 1: mixer = argv[optind++]; break;
default:
printf("Unknown third argument.\n");
printf(usage_str, argv[0]);
return 1;
}
arg++;
}
}
if(device == "") {
printf("Missing device argument.\n");
printf(usage_str, argv[0]);
return 1;
}
Device dev(device);
if(list) {
std::vector<std::string> mlist = dev.mixerNames();
std::vector<std::string>::iterator i = mlist.begin();
while(i != mlist.end()) {
printf("%s\n", i->c_str());
i++;
}
return 0;
}
if(mixer != "") {
Mixer *mix = dev.getMixer(mixer);
if(!mix) return 1;
if(range) {
Mixer::range_t range = mix->range();
printf("Range: [%f ; %f]dB\n", range.min, range.max);
}
if(num_channels) {
int num = mix->numberOfChannels();
printf("Number of channels: %d\n", num);
}
if(level_name != -1) {
if(level_value > -999999) {
printf("Set channel %d level to %fdB\n", level_name, level_value);
mix->setLevel(level_name, level_value);
} else {
float l = mix->level(level_name);
printf("Channel %d level: %fdB\n", level_name, l);
}
}
if(list_enums) {
std::vector<std::string> evs = mix->enumValues();
std::vector<std::string>::iterator i = evs.begin();
printf("Enum values:\n");
while(i != evs.end()) {
printf(" - '%s'\n", (*i).c_str());
i++;
}
printf("\n");
}
if(enum_value != "") {
printf("Setting enum value to '%s'\n", enum_value.c_str());
mix->setEnumValue(enum_value);
}
if(show_enum) {
std::string ev = mix->enumValue();
printf("Enum value: '%s'\n", ev.c_str());
}
if(show_mute) {
bool mute = mix->muted();
printf("Mute value: %d\n", mute?1:0);
}
if(set_mute != -1) {
printf("Set mute value: %d\n", set_mute);
mix->setMuted(set_mute==1?true:false);
}
if(show_capture) {
bool capture = mix->capture();
printf("Capture value: %d\n", capture?1:0);
}
if(set_capture != -1) {
printf("Set capture value: %d\n", set_capture);
mix->setCapture(set_capture==1?true:false);
}
delete mix;
}
return 0;
}
|