From 4f6b15ea26b5fa09f300f67e4ce1057c2b39a3aa Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 25 Sep 2014 17:08:44 +0200 Subject: New API, new name, new version. --- src/aiomixer.cc | 231 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 src/aiomixer.cc (limited to 'src/aiomixer.cc') 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 +#include +#include + +#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 " +".\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 mlist = dev.mixerNames(); + std::vector::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 evs = mix->enumValues(); + std::vector::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; +} -- cgit v1.2.3