annotate Plugins/Input/timidity/libtimidity/stream.c @ 285:d1762728ea4b trunk

[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
author nenolod
date Wed, 14 Dec 2005 08:51:51 -0800
parents
children c1dfb4b13be8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
1 #if HAVE_CONFIG_H
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
2 # include <config.h>
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
3 #endif
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
4
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
5 #include "string.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
6
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
7 #include "timidity.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
8 #include "timidity_internal.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
9 #include "common.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
10
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
11 struct _MidIStream
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
12 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
13 MidIStreamReadFunc read;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
14 MidIStreamCloseFunc close;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
15 void *ctx;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
16 };
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
17
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
18 typedef struct StdIOContext
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
19 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
20 FILE *fp;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
21 int autoclose;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
22 } StdIOContext;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
23
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
24 size_t
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
25 stdio_istream_read (void *ctx, void *ptr, size_t size, size_t nmemb)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
26 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
27 return fread (ptr, size, nmemb, ((StdIOContext *) ctx)->fp);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
28 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
29
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
30 int
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
31 stdio_istream_close (void *ctx)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
32 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
33 int ret = 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
34 if (((StdIOContext *) ctx)->autoclose)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
35 ret = fclose (((StdIOContext *) ctx)->fp);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
36 free (ctx);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
37 return ret;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
38 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
39
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
40 typedef struct MemContext
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
41 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
42 sint8 *base;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
43 sint8 *current;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
44 sint8 *end;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
45 int autofree;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
46 } MemContext;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
47
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
48 size_t
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
49 mem_istream_read (void *ctx, void *ptr, size_t size, size_t nmemb)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
50 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
51 MemContext *c;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
52 size_t count;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
53
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
54 c = (MemContext *) ctx;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
55 count = nmemb;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
56
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
57 if (c->current + count * size > c->end)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
58 count = (c->end - c->current) / size;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
59
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
60 memcpy (ptr, c->current, count * size);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
61 c->current += count * size;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
62
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
63 return count;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
64 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
65
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
66 int
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
67 mem_istream_close (void *ctx)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
68 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
69 if (((MemContext *) ctx)->autofree)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
70 free (((MemContext *) ctx)->base);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
71 free (ctx);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
72 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
73 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
74
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
75 MidIStream *
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
76 mid_istream_open_fp (FILE * fp, int autoclose)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
77 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
78 StdIOContext *ctx;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
79 MidIStream *stream;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
80
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
81 stream = safe_malloc (sizeof (MidIStream));
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
82 if (stream == NULL)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
83 return NULL;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
84
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
85 ctx = safe_malloc (sizeof (StdIOContext));
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
86 if (ctx == NULL)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
87 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
88 free (stream);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
89 return NULL;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
90 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
91 ctx->fp = fp;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
92 ctx->autoclose = autoclose;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
93
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
94 stream->ctx = ctx;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
95 stream->read = stdio_istream_read;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
96 stream->close = stdio_istream_close;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
97
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
98 return stream;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
99 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
100
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
101 MidIStream *
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
102 mid_istream_open_file (const char *file)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
103 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
104 FILE *fp;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
105
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
106 fp = fopen (file, "rb");
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
107 if (fp == NULL)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
108 return NULL;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
109
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
110 return mid_istream_open_fp (fp, 1);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
111 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
112
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
113 MidIStream *
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
114 mid_istream_open_mem (void *mem, size_t size, int autofree)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
115 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
116 MemContext *ctx;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
117 MidIStream *stream;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
118
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
119 stream = safe_malloc (sizeof (MidIStream));
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
120 if (stream == NULL)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
121 return NULL;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
122
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
123 ctx = safe_malloc (sizeof (MemContext));
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
124 if (ctx == NULL)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
125 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
126 free (stream);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
127 return NULL;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
128 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
129 ctx->base = mem;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
130 ctx->current = mem;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
131 ctx->end = ((sint8 *) mem) + size;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
132 ctx->autofree = autofree;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
133
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
134 stream->ctx = ctx;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
135 stream->read = mem_istream_read;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
136 stream->close = mem_istream_close;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
137
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
138 return stream;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
139 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
140
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
141 MidIStream *
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
142 mid_istream_open_callbacks (MidIStreamReadFunc read,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
143 MidIStreamCloseFunc close, void *context)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
144 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
145 MidIStream *stream;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
146
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
147 stream = safe_malloc (sizeof (MidIStream));
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
148 if (stream == NULL)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
149 return NULL;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
150
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
151 stream->ctx = context;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
152 stream->read = read;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
153 stream->close = close;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
154
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
155 return stream;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
156 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
157
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
158 size_t
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
159 mid_istream_read (MidIStream * stream, void *ptr, size_t size, size_t nmemb)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
160 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
161 return stream->read (stream->ctx, ptr, size, nmemb);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
162 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
163
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
164 void
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
165 mid_istream_skip (MidIStream * stream, size_t len)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
166 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
167 size_t c;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
168 char tmp[1024];
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
169 while (len > 0)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
170 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
171 c = len;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
172 if (c > 1024)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
173 c = 1024;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
174 len -= c;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
175 if (c != mid_istream_read (stream, tmp, 1, c))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
176 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
177 DEBUG_MSG ("mid_istream_skip error\n");
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
178 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
179 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
180 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
181
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
182 int
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
183 mid_istream_close (MidIStream * stream)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
184 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
185 int ret = stream->close (stream->ctx);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
186 free (stream);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
187 return ret;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
188 }