source: roaraudio/roarclients/roarcat.c @ 2407:47ec453a0fb2

Last change on this file since 2407:47ec453a0fb2 was 2407:47ec453a0fb2, checked in by phi, 15 years ago

set better defaults

File size: 5.0 KB
RevLine 
[0]1//roarcat.c:
2
[669]3/*
[2044]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008, 2009
[669]5 *
6 *  This file is part of roarclients a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
[0]25#include <roaraudio.h>
26
27#define BUFSIZE 1024
28
29void usage (void) {
[290]30 printf("roarcat [OPTIONS]... [FILE]\n");
[0]31
32 printf("\nOptions:\n\n");
33
[1507]34 printf("  --server    SERVER    - Set server hostname\n"
35        "  --rate  -R  RATE      - Set sample rate\n"
36        "  --bits  -B  BITS      - Set bits per sample\n"
37        "  --chans -C  CHANNELS  - Set number of channels\n"
38        "  --codec     CODEC     - Set the codec\n"
[1808]39        "  --wave                - Use Wave Audio (PCM) as input\n"
40        "  --midi                - Use MIDI Audio as input\n"
41        "  --light               - Use light control input\n"
[2241]42        "  --raw                 - Use raw input\n"
[2242]43        "  --rel-id ID          - Set ID of relative stream\n"
[1507]44        "  --help                - Show this help\n"
[0]45       );
46
47}
48
49int main (int argc, char * argv[]) {
[1194]50 int    rate     = ROAR_RATE_DEFAULT;
51 int    bits     = ROAR_BITS_DEFAULT;
52 int    channels = ROAR_CHANNELS_DEFAULT;
[0]53 int    codec    = ROAR_CODEC_DEFAULT;
[1808]54 int    dir      = ROAR_DIR_PLAY;
[2242]55 int    rel_id   = -1;
[0]56 char * server   = NULL;
57 char * k;
58 int    i;
[1194]59 char * name = "roarcat";
[2242]60 struct roar_connection    con;
61 struct roar_stream        s;
62 struct roar_vio_calls     file, stream;
63 struct roar_vio_defaults  def;
64 int file_opened = 0;
[0]65
[2247]66 if ( roar_vio_open_fh(&file, ROAR_STDIN) == -1 )
[2243]67  return 1;
68
[2246]69 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 )
[2243]70  return 1;
71
[0]72 for (i = 1; i < argc; i++) {
73  k = argv[i];
74
[1194]75  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
[58]76   server = argv[++i];
[1194]77  } else if ( !strcmp(k, "-n") ) {
78   name = argv[++i];
[1507]79  } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) {
[0]80   rate = atoi(argv[++i]);
[1507]81  } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) {
[0]82   bits = atoi(argv[++i]);
[1194]83  } else if ( !strcmp(k, "-b") ) {
84   bits = 8;
[1507]85  } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) {
[0]86   channels = atoi(argv[++i]);
[1194]87  } else if ( !strcmp(k, "-m") ) {
88   channels = 1;
89  } else if ( !strcmp(k, "--codec") ) {
[1897]90   if ( (codec = roar_str2codec(argv[++i])) == -1 ) {
91    fprintf(stderr, "Error: Unknown codec: %s\n", argv[i]);
92    return 1;
93   }
[1808]94
95  } else if ( !strcmp(k, "--wave") ) {
96   dir   = ROAR_DIR_PLAY;
97  } else if ( !strcmp(k, "--midi") ) {
[2407]98   dir      = ROAR_DIR_MIDI_IN;
99   bits     = ROAR_MIDI_BITS;
100   channels = ROAR_MIDI_CHANNELS_DEFAULT;
[1897]101   if ( codec == ROAR_CODEC_DEFAULT )
102    codec = ROAR_CODEC_MIDI;
[1808]103  } else if ( !strcmp(k, "--light") ) {
104   dir   = ROAR_DIR_LIGHT_IN;
[1897]105   if ( codec == ROAR_CODEC_DEFAULT )
106    codec = ROAR_CODEC_DMX512;
[2241]107  } else if ( !strcmp(k, "--raw") ) {
108   dir   = ROAR_DIR_RAW_IN;
[1808]109
[2242]110  } else if ( !strcmp(k, "--rel-id") ) {
111   rel_id = atoi(argv[++i]);
112
[1635]113  } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) {
[0]114   usage();
115   return 0;
[2242]116  } else if ( !file_opened ) {
117   file_opened = 1;
118   if ( roar_vio_open_dstr(&file, k, &def, 1) == -1 ) {
[289]119    fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno));
120    return 1;
121   }
[0]122  } else {
123   fprintf(stderr, "Error: unknown argument: %s\n", k);
124   usage();
125   return 1;
126  }
127 }
128
[2242]129 if ( roar_simple_connect(&con, server, "roarmon") == -1 ) {
130  fprintf(stderr, "Error: can not connect to server\n");
131  return 10;
132 }
133
134 if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) {
135  fprintf(stderr, "Error: can not create stream\n");
136  roar_disconnect(&con);
137  return 20;
138 }
139
140 if ( rel_id != -1 ) {
141  if ( roar_stream_set_rel_id(&s, rel_id) ) {
142   fprintf(stderr, "Error: can not set id or realative stream\n");
143   roar_disconnect(&con);
144   return 21;
145  }
[0]146 }
147
[2242]148 if ( roar_stream_connect(&con, &s, dir) == -1 ) {
149  fprintf(stderr, "Error: can not connect stream to server\n");
150  roar_disconnect(&con);
151  return 11;
152 }
[289]153
[2242]154 if ( roar_stream_exec(&con, &s) == -1 ) {
155  fprintf(stderr, "Error: can not exec stream\n");
156  roar_disconnect(&con);
157  return 12;
158 }
[0]159
[2242]160 if ( roar_get_connection_vio(&con, &stream) == -1 ) {
161  fprintf(stderr, "Error: can not get stream vio\n");
162  roar_disconnect(&con);
163  return 13;
164 }
[0]165
[2242]166 roar_vio_copy_data(&stream, &file);
167
168 roar_vio_close(&stream);
169 roar_vio_close(&file);
[292]170
[0]171 return 0;
172}
173
174//ll
Note: See TracBrowser for help on using the repository browser.