source: roaraudio/libroarsndio/libroarsndio.c @ 3811:49db840fb4f4

Last change on this file since 3811:49db840fb4f4 was 3811:49db840fb4f4, checked in by phi, 14 years ago

fixed some copyright statements

File size: 4.2 KB
RevLine 
[1555]1//libroarsndio.c:
2
3/*
[3811]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2010
[1555]5 *  The code (may) include prototypes and comments (and maybe
6 *  other code fragements) from EsounD.
7 *  They are mostly copyrighted by Eric B. Mitchell (aka 'Ricdude)
8 *  <ericmit@ix.netcom.com>. For more information see AUTHORS.esd.
9 *
10 *  This file is part of libroaresd a part of RoarAudio,
11 *  a cross-platform sound system for both, home and professional use.
12 *  See README for details.
13 *
14 *  This file is free software; you can redistribute it and/or modify
15 *  it under the terms of the GNU General Public License version 3
16 *  as published by the Free Software Foundation.
17 *
18 *  RoarAudio is distributed in the hope that it will be useful,
19 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 *  GNU General Public License for more details.
22 *
23 *  You should have received a copy of the GNU General Public License
24 *  along with this software; see the file COPYING.  If not, write to
[3517]25 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
26 *  Boston, MA 02110-1301, USA.
[1555]27 *
28 *  NOTE for everyone want's to change something and send patches:
29 *  read README and HACKING! There a addition information on
30 *  the license of this document you need to read before you send
31 *  any patches.
32 */
33
[1571]34#define ROAR_USE_OWN_SNDIO_HDL
[1555]35#include "libroarsndio.h"
36
[2372]37static char * sndio_to_roar_names (char * name) {
[2373]38 char * unitoffset = NULL;
39 char * optsoffset = NULL;
40 int    unit;
[2372]41
42 if ( name == NULL )
43  return NULL;
44
[2373]45 if ( !strncmp(name, "sun:", 4) ) {
46  unitoffset = name + 4;
47 } else if ( !strncmp(name, "aucat:", 6) ) {
48  unitoffset = name + 6;
49 } else if ( !strncmp(name, "rmidi:", 6) ) {
50  unitoffset = name + 6;
51 } else if ( !strncmp(name, "midithru:", 9) ) {
52  unitoffset = name + 9;
53 } else {
54  return name;
55 }
56
57 if ( (optsoffset = strstr(unitoffset, ".")) != NULL ) {
58  // TODO: add some code to strip the options of the end
59  return name;
60 } else {
61  unit = atoi(unitoffset);
62  switch (unit) {
63   // use defaulst
64   case 0: return NULL; break;
65   // use UNIX user sock, TODO: need some code here...
66   case 1: return NULL; break;
67   // use UNIX global sock:
68   case 2: return ROAR_DEFAULT_SOCK_GLOBAL; break;
69   // use DECnet localnode:
70   case 3: return "::"; break;
71   // use IPv4 localhost:
[2513]72   case 4: return ROAR_DEFAULT_INET4_HOST; break;
[2515]73   // reserved for DECnet Phase V:
74   case 5: return name; break;
[2373]75   // use IPv6 localhost:
[2513]76   case 6: return ROAR_DEFAULT_INET6_HOST; break;
[2373]77   // default:
78   default:
79     return name;
80  }
81 }
82
[2372]83 return name;
84}
85
[2574]86struct sio_hdl * sio_open(const char * name, unsigned mode, int nbio_flag) {
[1560]87 struct sio_hdl * hdl = NULL;
[2359]88 int is_midi = 0;
[1560]89
90 if ( (hdl = malloc(sizeof(struct sio_hdl))) == NULL )
91  return NULL;
92
93 memset(hdl, 0, sizeof(struct sio_hdl));
94
[2357]95 switch (mode) {
96  case SIO_PLAY:
97    hdl->dir = ROAR_DIR_PLAY;
98   break;
99  case MIO_OUT:
[2359]100    is_midi = 1;
101    hdl->dir = ROAR_DIR_MIDI_IN;
102   break;
[2357]103  case MIO_IN:
[2359]104    is_midi = 1;
105    hdl->dir = ROAR_DIR_MIDI_OUT;
106   break;
[2360]107
108  // unsupported:
[2357]109  case SIO_REC:
110  case SIO_PLAY|SIO_REC:
111  case MIO_OUT|MIO_IN:
[2360]112
113  // illigal:
[2357]114  default:
115    free(hdl);
116    return NULL;
117 }
118
[2371]119 if ( name == NULL ) {
120  if ( is_midi ) {
121   name = getenv("MIDIDEVICE");
122  } else {
123   name = getenv("AUDIODEVICE");
124  }
125 }
126
[2574]127 name = sndio_to_roar_names((char*) name);
[2372]128
[2574]129 if ( roar_simple_connect(&(hdl->con), (char*) name, "libroarsndio") == -1 ) {
[1573]130  free(hdl);
131  return NULL;
132 }
133
[1560]134 sio_initpar(&(hdl->para));
135
[2019]136 hdl->stream_opened = 0;
[1560]137
138 if ( name != NULL )
139  hdl->device = strdup(name);
140
[2359]141 if ( is_midi ) {
142  hdl->info.codec    = ROAR_CODEC_MIDI;
[2575]143  hdl->info.bits     = ROAR_MIDI_BITS;
144  hdl->info.channels = ROAR_MIDI_CHANNELS_DEFAULT;
145  hdl->info.rate     = ROAR_MIDI_TICKS_PER_BEAT;
[2359]146  if ( !sio_start(hdl) ) {
147   sio_close(hdl);
148   return NULL;
149  }
150 }
151
[3237]152 hdl->nonblock = nbio_flag;
153
[1560]154 return hdl;
155}
156
157void   sio_close  (struct sio_hdl * hdl) {
158 if ( hdl == NULL )
159  return;
160
[2019]161 sio_stop(hdl);
[1560]162
[1573]163 roar_disconnect(&(hdl->con));
164
[1560]165 free(hdl);
166}
167
168int    sio_eof    (struct sio_hdl * hdl) {
[3238]169 return hdl->ioerror;
[1560]170}
171
172void   sio_onmove (struct sio_hdl * hdl, void (*cb)(void * arg, int delta), void * arg) {
173 if ( hdl == NULL )
174  return;
175
176 hdl->on_move     = cb;
177 hdl->on_move_arg = arg;
178}
179
[1555]180//ll
Note: See TracBrowser for help on using the repository browser.