1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
/*
TiMidity++ -- MIDI to WAVE converter and player
Copyright (C) 1999-2004 Masanao Izumo <iz@onicos.co.jp>
Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dumb_c.c
Minimal control mode -- no interaction, just prints out messages.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#ifndef NO_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#include "timidity.h"
#include "common.h"
#include "output.h"
#include "controls.h"
#include "instrum.h"
#include "playmidi.h"
#include "readmidi.h"
#ifdef __W32__
#include "wrd.h"
#endif /* __W32__ */
static int ctl_open(int using_stdin, int using_stdout);
static void ctl_close(void);
static int ctl_read(int32 *valp);
static int cmsg(int type, int verbosity_level, char *fmt, ...);
static void ctl_total_time(long tt);
static void ctl_file_name(char *name);
static void ctl_current_time(int ct);
static void ctl_lyric(int lyricid);
static void ctl_event(CtlEvent *e);
/**********************************/
/* export the interface functions */
#define ctl dumb_control_mode
ControlMode ctl=
{
"dumb interface", 'd',
"dumb",
1,0,0,
0,
ctl_open,
ctl_close,
dumb_pass_playing_list,
ctl_read,
NULL,
cmsg,
ctl_event
};
static FILE *outfp;
int dumb_error_count;
/*ARGSUSED*/
static int ctl_open(int using_stdin, int using_stdout)
{
if(using_stdout)
outfp=stderr;
else
outfp=stdout;
ctl.opened=1;
return 0;
}
static void ctl_close(void)
{
fflush(outfp);
ctl.opened=0;
}
/*ARGSUSED*/
static int ctl_read(int32 *valp)
{
return RC_NONE;
}
static int cmsg(int type, int verbosity_level, char *fmt, ...)
{
va_list ap;
if ((type==CMSG_TEXT || type==CMSG_INFO || type==CMSG_WARNING) &&
ctl.verbosity<verbosity_level)
return 0;
va_start(ap, fmt);
if(type == CMSG_WARNING || type == CMSG_ERROR || type == CMSG_FATAL)
dumb_error_count++;
if (!ctl.opened)
{
vfprintf(stderr, fmt, ap);
fputs(NLS, stderr);
}
else
{
vfprintf(outfp, fmt, ap);
fputs(NLS, outfp);
fflush(outfp);
}
va_end(ap);
return 0;
}
static void ctl_total_time(long tt)
{
int mins, secs;
if (ctl.trace_playing)
{
secs=(int)(tt/play_mode->rate);
mins=secs/60;
secs-=mins*60;
cmsg(CMSG_INFO, VERB_NORMAL,
"Total playing time: %3d min %02d s", mins, secs);
}
}
static void ctl_file_name(char *name)
{
if (ctl.verbosity>=0 || ctl.trace_playing)
cmsg(CMSG_INFO, VERB_NORMAL, "Playing %s", name);
}
static void ctl_current_time(int secs)
{
int mins;
static int prev_secs = -1;
#ifdef __W32__
if(wrdt->id == 'w')
return;
#endif /* __W32__ */
if (ctl.trace_playing && secs != prev_secs)
{
prev_secs = secs;
mins=secs/60;
secs-=mins*60;
fprintf(outfp, "\r%3d:%02d", mins, secs);
fflush(outfp);
}
}
static void ctl_lyric(int lyricid)
{
char *lyric;
lyric = event2string(lyricid);
if(lyric != NULL)
{
if(lyric[0] == ME_KARAOKE_LYRIC)
{
if(lyric[1] == '/' || lyric[1] == '\\')
{
fprintf(outfp, "\n%s", lyric + 2);
fflush(outfp);
}
else if(lyric[1] == '@')
{
if(lyric[2] == 'L')
fprintf(outfp, "\nLanguage: %s\n", lyric + 3);
else if(lyric[2] == 'T')
fprintf(outfp, "Title: %s\n", lyric + 3);
else
fprintf(outfp, "%s\n", lyric + 1);
}
else
{
fputs(lyric + 1, outfp);
fflush(outfp);
}
}
else
{
if(lyric[0] == ME_CHORUS_TEXT || lyric[0] == ME_INSERT_TEXT)
fprintf(outfp, "\r");
fputs(lyric + 1, outfp);
fflush(outfp);
}
}
}
static void ctl_event(CtlEvent *e)
{
switch(e->type)
{
case CTLE_NOW_LOADING:
ctl_file_name((char *)e->v1);
break;
case CTLE_PLAY_START:
ctl_total_time(e->v1);
break;
case CTLE_CURRENT_TIME:
ctl_current_time((int)e->v1);
break;
#ifndef CFG_FOR_SF
case CTLE_LYRIC:
ctl_lyric((int)e->v1);
break;
#endif
}
}
/*
* interface_<id>_loader();
*/
ControlMode *interface_d_loader(void)
{
return &ctl;
}
|