/* -*- 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" " -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 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); } 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 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_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; }