PageRenderTime 58ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/alsa-utils-1.0.25/alsamixer/cli.c

#
C | 135 lines | 104 code | 12 blank | 19 comment | 17 complexity | 14f1b96cd9a85880a872453704c368d0 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * alsamixer - curses mixer for the ALSA project
  3. * Copyright (c) 1998,1999 Tim Janik
  4. * Jaroslav Kysela <perex@perex.cz>
  5. * Copyright (c) 2009 Clemens Ladisch <clemens@ladisch.de>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "aconfig.h"
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <locale.h>
  24. #include <getopt.h>
  25. #include <alsa/asoundlib.h>
  26. #include "gettext_curses.h"
  27. #include "mixer_widget.h"
  28. #include "mainloop.h"
  29. static int use_color = 1;
  30. static struct snd_mixer_selem_regopt selem_regopt = {
  31. .ver = 1,
  32. .abstract = SND_MIXER_SABSTRACT_NONE,
  33. .device = "default",
  34. };
  35. static void show_help(void)
  36. {
  37. puts(_("Usage: alsamixer [options]"));
  38. puts(_("Useful options:\n"
  39. " -h, --help this help\n"
  40. " -c, --card=NUMBER sound card number or id\n"
  41. " -D, --device=NAME mixer device name\n"
  42. " -V, --view=MODE starting view mode: playback/capture/all"));
  43. puts(_("Debugging options:\n"
  44. " -g, --no-color toggle using of colors\n"
  45. " -a, --abstraction=NAME mixer abstraction level: none/basic"));
  46. }
  47. static void parse_options(int argc, char *argv[])
  48. {
  49. static const char short_options[] = "hc:D:V:gsa:";
  50. static const struct option long_options[] = {
  51. { .name = "help", .val = 'h' },
  52. { .name = "card", .has_arg = 1, .val = 'c' },
  53. { .name = "device", .has_arg = 1, .val = 'D' },
  54. { .name = "view", .has_arg = 1, .val = 'V' },
  55. { .name = "no-color", .val = 'g' },
  56. { .name = "abstraction", .has_arg = 1, .val = 'a' },
  57. { }
  58. };
  59. int option;
  60. int card_index;
  61. static char name_buf[16];
  62. while ((option = getopt_long(argc, argv, short_options,
  63. long_options, NULL)) != -1) {
  64. switch (option) {
  65. case '?':
  66. case 'h':
  67. show_help();
  68. exit(EXIT_SUCCESS);
  69. case 'c':
  70. card_index = snd_card_get_index(optarg);
  71. if (card_index < 0) {
  72. fprintf(stderr, _("invalid card index: %s\n"), optarg);
  73. goto fail;
  74. }
  75. sprintf(name_buf, "hw:%d", card_index);
  76. selem_regopt.device = name_buf;
  77. break;
  78. case 'D':
  79. selem_regopt.device = optarg;
  80. break;
  81. case 'V':
  82. if (*optarg == 'p' || *optarg == 'P')
  83. view_mode = VIEW_MODE_PLAYBACK;
  84. else if (*optarg == 'c' || *optarg == 'C')
  85. view_mode = VIEW_MODE_CAPTURE;
  86. else
  87. view_mode = VIEW_MODE_ALL;
  88. break;
  89. case 'g':
  90. use_color = !use_color;
  91. break;
  92. case 'a':
  93. if (!strcmp(optarg, "none"))
  94. selem_regopt.abstract = SND_MIXER_SABSTRACT_NONE;
  95. else if (!strcmp(optarg, "basic"))
  96. selem_regopt.abstract = SND_MIXER_SABSTRACT_BASIC;
  97. else {
  98. fprintf(stderr, _("unknown abstraction level: %s\n"), optarg);
  99. goto fail;
  100. }
  101. break;
  102. default:
  103. fprintf(stderr, _("unknown option: %c\n"), option);
  104. fail:
  105. fputs(_("try `alsamixer --help' for more information\n"), stderr);
  106. exit(EXIT_FAILURE);
  107. }
  108. }
  109. }
  110. int main(int argc, char *argv[])
  111. {
  112. setlocale(LC_ALL, "");
  113. #ifdef ENABLE_NLS_IN_CURSES
  114. textdomain(PACKAGE);
  115. #endif
  116. parse_options(argc, argv);
  117. create_mixer_object(&selem_regopt);
  118. initialize_curses(use_color);
  119. create_mixer_widget();
  120. mainloop();
  121. app_shutdown();
  122. return 0;
  123. }