summaryrefslogtreecommitdiff
path: root/src/aiomixer.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-09-25 17:08:44 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-09-25 17:08:44 +0200
commit4f6b15ea26b5fa09f300f67e4ce1057c2b39a3aa (patch)
tree45d7bb4a9a90ef603b5a7a65a4d4d4309a7a1538 /src/aiomixer.cc
parent0602763044f0f0f9163f2a888627213347d3dbb7 (diff)
New API, new name, new version.
Diffstat (limited to 'src/aiomixer.cc')
-rw-r--r--src/aiomixer.cc231
1 files changed, 231 insertions, 0 deletions
diff --git a/src/aiomixer.cc b/src/aiomixer.cc
new file mode 100644
index 0000000..bfe37f9
--- /dev/null
+++ b/src/aiomixer.cc
@@ -0,0 +1,231 @@
+/* -*- 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"
+" -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 list_enum = false;
+ bool range = false;
+ bool num_channels = false;
+
+ std::string enum_name;
+ std::string enum_value;
+
+ std::string level_name;
+ std::string level_value;
+
+ int option_index = 0;
+ while(1) {
+ static struct option long_options[] = {
+ {"list", no_argument, 0, 'L'},
+ {"enum", required_argument, 0, 'e'},
+ {"level", required_argument, 0, 'l'},
+ {"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long (argc, argv, "hvLe:l:rc", 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 'e':
+ p = strchr(optarg, '=');
+ if(p) {
+ *p = '\0';
+ enum_value = p+1;
+ }
+ enum_name = optarg;
+ if(enum_name == "") list_enum = true;
+ break;
+
+ case 'l':
+ p = strchr(optarg, '=');
+ if(p) {
+ *p = '\0';
+ level_value = p+1;
+ }
+ level_name = 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);
+ }
+
+ /*
+ for(int i = 0; i < num; i++) {
+ printf("Channel: %d\n", i);
+ float val = mix->level(i);
+ printf(" Level %fdB\n", val);
+ mix->setLevel(i, val - 1.1);
+ printf(" Level %fdB\n", mix->level(i));
+ mix->setLevel(i, val);
+ printf(" Level %fdB\n", mix->level(i));
+ }
+ */
+
+ if(list_enum) {
+ 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_name != "" && enum_value == "") {
+ std::string ev = mix->enumValue();
+ printf("Enum value: '%s'\n", ev.c_str());
+ }
+
+ // bool capt = mix->capture();
+ // mix->setCapture(!capt);
+
+ delete mix;
+ }
+
+ return 0;
+}