source: roaraudio/libroarsndio/libroarsndio.c @ 3517:1a3218a3fc5b

Last change on this file since 3517:1a3218a3fc5b was 3517:1a3218a3fc5b, checked in by phi, 14 years ago

updated license headers, FSF moved office

File size: 4.2 KB
Line 
1//libroarsndio.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
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
25 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
26 *  Boston, MA 02110-1301, USA.
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
34#define ROAR_USE_OWN_SNDIO_HDL
35#include "libroarsndio.h"
36
37static char * sndio_to_roar_names (char * name) {
38 char * unitoffset = NULL;
39 char * optsoffset = NULL;
40 int    unit;
41
42 if ( name == NULL )
43  return NULL;
44
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:
72   case 4: return ROAR_DEFAULT_INET4_HOST; break;
73   // reserved for DECnet Phase V:
74   case 5: return name; break;
75   // use IPv6 localhost:
76   case 6: return ROAR_DEFAULT_INET6_HOST; break;
77   // default:
78   default:
79     return name;
80  }
81 }
82
83 return name;
84}
85
86struct sio_hdl * sio_open(const char * name, unsigned mode, int nbio_flag) {
87 struct sio_hdl * hdl = NULL;
88 int is_midi = 0;
89
90 if ( (hdl = malloc(sizeof(struct sio_hdl))) == NULL )
91  return NULL;
92
93 memset(hdl, 0, sizeof(struct sio_hdl));
94
95 switch (mode) {
96  case SIO_PLAY:
97    hdl->dir = ROAR_DIR_PLAY;
98   break;
99  case MIO_OUT:
100    is_midi = 1;
101    hdl->dir = ROAR_DIR_MIDI_IN;
102   break;
103  case MIO_IN:
104    is_midi = 1;
105    hdl->dir = ROAR_DIR_MIDI_OUT;
106   break;
107
108  // unsupported:
109  case SIO_REC:
110  case SIO_PLAY|SIO_REC:
111  case MIO_OUT|MIO_IN:
112
113  // illigal:
114  default:
115    free(hdl);
116    return NULL;
117 }
118
119 if ( name == NULL ) {
120  if ( is_midi ) {
121   name = getenv("MIDIDEVICE");
122  } else {
123   name = getenv("AUDIODEVICE");
124  }
125 }
126
127 name = sndio_to_roar_names((char*) name);
128
129 if ( roar_simple_connect(&(hdl->con), (char*) name, "libroarsndio") == -1 ) {
130  free(hdl);
131  return NULL;
132 }
133
134 sio_initpar(&(hdl->para));
135
136 hdl->stream_opened = 0;
137
138 if ( name != NULL )
139  hdl->device = strdup(name);
140
141 if ( is_midi ) {
142  hdl->info.codec    = ROAR_CODEC_MIDI;
143  hdl->info.bits     = ROAR_MIDI_BITS;
144  hdl->info.channels = ROAR_MIDI_CHANNELS_DEFAULT;
145  hdl->info.rate     = ROAR_MIDI_TICKS_PER_BEAT;
146  if ( !sio_start(hdl) ) {
147   sio_close(hdl);
148   return NULL;
149  }
150 }
151
152 hdl->nonblock = nbio_flag;
153
154 return hdl;
155}
156
157void   sio_close  (struct sio_hdl * hdl) {
158 if ( hdl == NULL )
159  return;
160
161 sio_stop(hdl);
162
163 roar_disconnect(&(hdl->con));
164
165 free(hdl);
166}
167
168int    sio_eof    (struct sio_hdl * hdl) {
169 return hdl->ioerror;
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
180//ll
Note: See TracBrowser for help on using the repository browser.