Add lqueue command
[cmus.git] / mikmod.c
blob79779a24a7eff8ca9db7f116f4b779904c0a6dbd
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 | DMODE_16BITS
46 /* | DMODE_HQMIXER */
47 | DMODE_INTERP );
49 if (MikMod_Init(NULL)) {
50 d_print("Could not initialize mikmod, reason: %s\n",
51 MikMod_strerror(MikMod_errno));
52 return 0;
55 inited = 1;
56 return 1;
59 static int mik_open(struct input_plugin_data *ip_data)
61 MODULE *mf = NULL;
62 struct mik_private *priv;
63 int mi=mikmod_init();
65 if (!mi)
66 return -IP_ERROR_INTERNAL;
68 mf = Player_Load(ip_data->filename, 255, 0);
70 if (!mf)
71 return -IP_ERROR_ERRNO;
73 priv = xnew(struct mik_private, 1);
74 priv->file = mf;
76 ip_data->private = priv;
77 ip_data->sf = sf_bits(16) | sf_rate(44100) | sf_channels(2) | sf_signed(1);
78 return 0;
81 static int mik_close(struct input_plugin_data *ip_data)
83 struct mik_private *priv = ip_data->private;
85 Player_Stop();
86 Player_Free(priv->file);
87 free(ip_data->private);
88 ip_data->private = NULL;
89 return 0;
92 static int mik_read(struct input_plugin_data *ip_data, char *buffer, int count)
94 int length;
95 struct mik_private *priv = ip_data->private;
97 if (!Player_Active())
98 Player_Start(priv->file);
100 if (!Player_Active())
101 return 0;
103 length = VC_WriteBytes(buffer, count);
105 return length;
108 static int mik_seek(struct input_plugin_data *ip_data, double offset)
110 /* cannot seek in modules properly */
111 return -IP_ERROR_FUNCTION_NOT_SUPPORTED;
114 static int mik_read_comments(struct input_plugin_data *ip_data, struct keyval **comments)
116 /* Player_LoadTitle segfaults when we are playing a mod file.
117 * This is a bug in libmikmod.
119 #if 0
120 struct keyval *c;
121 const char *name;
123 /* FIXME */
124 name=Player_LoadTitle(ip_data->filename);
125 c = xnew0(struct keyval, 2);
127 if (name != NULL && *name != 0) {
128 c[0].key = xstrdup("title");
129 c[0].val = xstrdup(name);
130 } else {
131 c[0].key = xstrdup("title");
132 c[0].val = xstrdup(ip_data->filename);
134 *comments = c;
135 #else
136 *comments = xnew0(struct keyval, 1);
137 #endif
138 return 0;
141 static int mik_duration(struct input_plugin_data *ip_data)
143 return -IP_ERROR_FUNCTION_NOT_SUPPORTED;
146 const struct input_plugin_ops ip_ops = {
147 .open = mik_open,
148 .close = mik_close,
149 .read = mik_read,
150 .seek = mik_seek,
151 .read_comments = mik_read_comments,
152 .duration = mik_duration
155 const char * const ip_extensions[] = {
156 "mod", "s3m", "xm", "it", "669", "amf", "dsm",
157 "far", "med", "mtm", "stm", "ult",
158 NULL
161 const char * const ip_mime_types[] = { NULL };