Changeset 485281e in mainline for uspace/app/modplay/modplay.c


Ignore:
Timestamp:
2018-12-18T18:38:49Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
336b739
Parents:
c65590a
Message:

Allow specifying non-default audio target

Needed when there is more than one audio device. It would be nice
complementary functionality if we could actually configure the
default audio target.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/modplay/modplay.c

    rc65590a r485281e  
    3939#include <stdio.h>
    4040#include <stdlib.h>
     41#include <str.h>
    4142#include <str_error.h>
    4243#include <trackmod.h>
     
    6768}
    6869
     70static void print_syntax(void)
     71{
     72        printf("syntax: modplay [<options>] <filename.mod>\n");
     73        printf("options:\n");
     74        printf("\t-t <target>\tOutput to specified audio target.\n");
     75}
     76
    6977int main(int argc, char *argv[])
    7078{
     
    7886        void *buffer;
    7987        size_t buffer_size;
     88        const char *target = HOUND_DEFAULT_TARGET;
    8089        errno_t rc;
    8190
    82         if (argc != 2) {
    83                 printf("syntax: modplay <filename.mod>\n");
     91        ++argv;
     92        --argc;
     93
     94        while (argc > 0 && (*argv)[0] == '-') {
     95                if (str_cmp(*argv, "-t") == 0) {
     96                        ++argv;
     97                        --argc;
     98
     99                        if (argc < 1) {
     100                                printf("Option '-t' requires an argument.\n");
     101                                print_syntax();
     102                                return 1;
     103                        }
     104
     105                        target = *argv++;
     106                        --argc;
     107                        continue;
     108                }
     109
     110                printf("Invalid option '%s'\n", *argv);
     111                print_syntax();
     112                return 1;
     113        }
     114
     115        if (argc != 1) {
     116                print_syntax();
    84117                return 1;
    85118        }
     
    87120        con = console_init(stdin, stdout);
    88121
    89         rc = trackmod_module_load(argv[1], &mod);
     122        rc = trackmod_module_load(argv[0], &mod);
    90123        if (rc != EOK) {
    91                 printf("Error loading %s.\n", argv[1]);
     124                printf("Error loading %s.\n", argv[0]);
    92125                return 1;
    93126        }
     
    114147        }
    115148
    116         rc = hound_context_connect_target(hound, HOUND_DEFAULT_TARGET);
     149        rc = hound_context_connect_target(hound, target);
    117150        if (rc != EOK) {
    118                 printf("Error connecting default audio target: %s.\n", str_error(rc));
     151                printf("Error connecting audio target '%s': %s.\n",
     152                    target, str_error(rc));
     153
     154                char **names = NULL;
     155                size_t count = 0;
     156                rc = hound_context_get_available_targets(hound, &names, &count);
     157                if (rc == EOK) {
     158                        printf("Available targets:\n");
     159                        for (size_t i = 0; i < count; i++)
     160                                printf(" - %s\n", names[i]);
     161                }
     162
    119163                return 1;
    120164        }
Note: See TracChangeset for help on using the changeset viewer.