Handle streams separately in tree_add_track()
[cmus.git] / mikmod.c
blob86acaf2d4d8ebc3375e87101347f8fae4508215c
1 /*
2 * Adapted from AlsaPlayer 0.99.76
4 * mikmod_engine.c
5 * Copyright (C) 1999 Paul N. Fisher <rao@gnu.org>
6 * Copyright (C) 2002 Andy Lo A Foe <andy@alsaplayer.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "ip.h"
25 #include "xmalloc.h"
26 #include <mikmod.h>
27 #include "debug.h"
29 struct mik_private {
30 MODULE *file;
33 static int mikmod_init(void)
35 static int inited = 0;
37 if (inited)
38 return 1;
40 MikMod_RegisterAllDrivers();
41 MikMod_RegisterAllLoaders();
43 md_reverb = 0;
44 /* we should let the user decide which one is better... */
45 md_mode = DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX | DMODE_STEREO |
46 DMODE_16BITS | DMODE_INTERP;
48 if (MikMod_Init(NULL)) {
49 d_print("Could not initialize mikmod, reason: %s\n",
50 MikMod_strerror(MikMod_errno));
51 return 0;
54 inited = 1;
55 return 1;
58 static int mik_open(struct input_plugin_data *ip_data)
60 MODULE *mf = NULL;
61 struct mik_private *priv;
62 int mi = mikmod_init();
64 if (!mi)
65 return -IP_ERROR_INTERNAL;
67 mf = Player_Load(ip_data->filename, 255, 0);
69 if (!mf)
70 return -IP_ERROR_ERRNO;
72 priv = xnew(struct mik_private, 1);
73 priv->file = mf;
75 ip_data->private = priv;
76 ip_data->sf = sf_bits(16) | sf_rate(44100) | sf_channels(2) | sf_signed(1);
77 return 0;
80 static int mik_close(struct input_plugin_data *ip_data)
82 struct mik_private *priv = ip_data->private;
84 Player_Stop();
85 Player_Free(priv->file);
86 free(ip_data->private);
87 ip_data->private = NULL;
88 return 0;
91 static int mik_read(struct input_plugin_data *ip_data, char *buffer, int count)
93 int length;
94 struct mik_private *priv = ip_data->private;
96 if (!Player_Active())
97 Player_Start(priv->file);
99 if (!Player_Active())
100 return 0;
102 length = VC_WriteBytes(buffer, count);
104 return length;
107 static int mik_seek(struct input_plugin_data *ip_data, double offset)
109 /* cannot seek in modules properly */
110 return -IP_ERROR_FUNCTION_NOT_SUPPORTED;
113 static int mik_read_comments(struct input_plugin_data *ip_data, struct keyval **comments)
115 /* Player_LoadTitle segfaults when we are playing a mod file.
116 * This is a bug in libmikmod.
118 #if 0
119 struct keyval *c;
120 const char *name;
122 /* FIXME */
123 name = Player_LoadTitle(ip_data->filename);
124 c = xnew0(struct keyval, 2);
126 if (name != NULL && *name != 0) {
127 c[0].key = xstrdup("title");
128 c[0].val = xstrdup(name);
129 } else {
130 c[0].key = xstrdup("title");
131 c[0].val = xstrdup(ip_data->filename);
133 *comments = c;
134 #else
135 *comments = xnew0(struct keyval, 1);
136 #endif
137 return 0;
140 static int mik_duration(struct input_plugin_data *ip_data)
142 return -IP_ERROR_FUNCTION_NOT_SUPPORTED;
145 const struct input_plugin_ops ip_ops = {
146 .open = mik_open,
147 .close = mik_close,
148 .read = mik_read,
149 .seek = mik_seek,
150 .read_comments = mik_read_comments,
151 .duration = mik_duration
154 const char * const ip_extensions[] = {
155 "mod", "s3m", "xm", "it", "669", "amf", "dsm",
156 "far", "med", "mtm", "stm", "ult",
157 NULL
160 const char * const ip_mime_types[] = { NULL };