1 /* $Id: simplemod.c,v 1.5 2011/06/20 17:39:57 xi Exp $ */
2 
3 /******************************************************************************
4 *    simplemod - A very simple module player
5 *    Copyright (C) 2002  Christian Laursen <xi@borderworlds.dk>
6 *
7 *    This program is free software; you can redistribute it and/or modify
8 *    it under the terms of the GNU General Public License as published by
9 *    the Free Software Foundation; either version 2 of the License, or
10 *    (at your option) any later version.
11 *
12 *    This program is distributed in the hope that it will be useful,
13 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *    GNU General Public License for more details.
16 *
17 *    You should have received a copy of the GNU General Public License
18 *    along with this program; if not, write to the Free Software
19 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 ******************************************************************************/
21 
22 #include <mikmod.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27 
28 #define VERSION "1.1"
29 
30 int main (int argc, char **argv)
31 {
32   int i;
33   char *filename = (char *)0;
34   int skip = 0, esd = 0, raw = 0;
35   char *esdhost;
36   MODULE *module;
37 
38   for (i = 1; i < argc; ++i) {
39     if (!strcmp(argv[i], "-k") && (i + 1 < argc)) {
40       skip = atoi(argv[++i]);
41     } else if (!strcmp(argv[i], "-e") && (i + 1 < argc)) {
42       esd = 1;
43       esdhost = argv[++i];
44     } else if (!strcmp(argv[i], "-r")) {
45       raw = 1;
46     } else {
47       if (filename) {
48 	fprintf(stderr, "You can only play one song at a time.\n");
49 	exit(1);
50       } else {
51 	filename = argv[i];
52       }
53     }
54   }
55 
56   if (!filename) {
57     fprintf(stderr, "No filename specified.\n");
58     exit(1);
59   }
60 
61   fprintf(stderr, "simplemod %s\nCopyright 2002-2011   Christian Laursen <xi@borderworlds.dk>\n\n", VERSION);
62 
63   if (esd) {
64     setenv("ESPEAKER", esdhost, 1);
65     MikMod_RegisterDriver(&drv_esd);
66   } else if (raw) {
67     MikMod_RegisterDriver(&drv_stdout);
68   } else {
69     MikMod_RegisterDriver(&drv_oss);
70   }
71   MikMod_RegisterAllLoaders();
72 
73   md_mode |= DMODE_SOFT_MUSIC;
74   md_reverb = 0;
75   if (MikMod_Init("")) {
76     fprintf(stderr, "Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno));
77     exit(1);
78   }
79 
80   module = Player_Load(filename, 64, 0);
81 
82   if (module) {
83     fprintf(stderr, "Title: %s\n\n", module->songname);
84 
85     module->loop = 0;
86     /* start module */
87     Player_Start(module);
88     Player_SetPosition(skip);
89 
90     while (Player_Active()) {
91       /* we're playing */
92       usleep(1000);
93       MikMod_Update();
94 
95       fprintf (stderr, "P:%5d,%d             \r", (int)(module->sngtime / (1<<10)), module->sngpos);
96       fflush(stderr);
97     }
98 
99     Player_Stop();
100     Player_Free(module);
101   } else {
102     fprintf(stderr, "Could not load module, reason: %s\n", MikMod_strerror(MikMod_errno));
103     exit(1);
104   }
105 
106   MikMod_Exit();
107 
108   return 0;
109 }
110