1 /*
2     TiMidity++ -- MIDI to WAVE converter and player
3     Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
4     Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20 
21 #ifndef ___WRD_H_
22 #define ___WRD_H_
23 
24 
25 #define WRD_MAXPARAM 32
26 #define WRD_MAXFADESTEP 12
27 
28 #define WRD_GSCR_WIDTH 640	/* Graphics screen width in pixel */
29 #define WRD_GSCR_HEIGHT 400	/* Graphics screen height in pixcel */
30 #define WRD_TSCR_WIDTH 80	/* Text screen width in character */
31 #define WRD_TSCR_HEIGHT 25	/* Text screen height in character */
32 
33 #define WRD_TEXT_COLOR0 "black"
34 #define WRD_TEXT_COLOR1 "red"
35 #define WRD_TEXT_COLOR2 "green"
36 #define WRD_TEXT_COLOR3 "yellow"
37 #define WRD_TEXT_COLOR4 "blue"
38 #define WRD_TEXT_COLOR5 "magenta"
39 #define WRD_TEXT_COLOR6 "cyan"
40 #define WRD_TEXT_COLOR7 "white"
41 
42 /*sherry data is little endian*/
43 #define SRY_GET_SHORT(charp)  ( (charp)[0]+((charp)[1]<<8) )
44 
45 
46 enum wrd_token_type
47 {
48     WRD_COMMAND,	/* Standart command */
49     WRD_ECOMMAND,	/* Ensyutsukun */
50     WRD_STEP,
51     WRD_LYRIC,
52     WRD_EOF,
53 
54     /* WRD Commands */
55     WRD_COLOR, WRD_END, WRD_ESC, WRD_EXEC, WRD_FADE, WRD_GCIRCLE,
56     WRD_GCLS, WRD_GINIT, WRD_GLINE, WRD_GMODE, WRD_GMOVE, WRD_GON,
57     WRD_GSCREEN, WRD_INKEY, WRD_LOCATE, WRD_LOOP, WRD_MAG, WRD_MIDI,
58     WRD_OFFSET, WRD_PAL, WRD_PALCHG, WRD_PALREV, WRD_PATH, WRD_PLOAD,
59     WRD_REM, WRD_REMARK, WRD_REST, WRD_SCREEN, WRD_SCROLL, WRD_STARTUP,
60     WRD_STOP, WRD_TCLS, WRD_TON, WRD_WAIT, WRD_WMODE,
61 
62     /* WRD Ensyutsukun Commands */
63     WRD_eFONTM, WRD_eFONTP, WRD_eFONTR, WRD_eGSC, WRD_eLINE, WRD_ePAL,
64     WRD_eREGSAVE, WRD_eSCROLL, WRD_eTEXTDOT, WRD_eTMODE, WRD_eTSCRL,
65     WRD_eVCOPY, WRD_eVSGET, WRD_eVSRES, WRD_eXCOPY,
66 
67     /* WRD Extensionals */
68     WRD_ARG,
69     WRD_FADESTEP,
70     WRD_OUTKEY,
71     WRD_NL,
72     WRD_MAGPRELOAD,
73     WRD_PHOPRELOAD,
74     WRD_START_SKIP,
75     WRD_END_SKIP,
76     WRD_SHERRY_UPDATE,		/* Update real screen of Sherry */
77 
78     WRD_NOARG = 0x7FFF
79 };
80 
81 typedef struct _WRDTracer
82 {
83     char *name;			/* Tracer name */
84     int id;			/* ID */
85     int opened;			/* 0:closed 1:opened */
86 
87     /* Initialize tracer environment
88      * open() calls at first once.
89      */
90     int (* open)(char *wrdt_opts);
91 
92     /* apply() evaluates MIMPI WRD command. */
93     /* wrd_argv[0] means WRD command, and the rests means the arguments */
94     void (* apply)(int cmd, int wrd_argc, int wrd_argv[]);
95 
96     /* sherry() evaluates Sherry WRD command. */
97     void (* sherry)(uint8 *data, int len);
98 
99     /* Update window events */
100     void (* update_events)(void);
101 
102     /* start() calls at each end of MIDI reading.
103      * If it is error, start() returns -1, otherwise return 0.
104      * If start() returns -1, TiMidity strips all WRD command.
105      */
106     int (* start)(int wrd_mode);
107 #define WRD_TRACE_NOTHING	0
108 #define WRD_TRACE_MIMPI		1
109 #define WRD_TRACE_SHERRY	2
110 
111     /* end() calls at each end of playing */
112     void (* end)(void);
113 
114     /* close() calls at last before exit */
115     void (* close)(void);
116 } WRDTracer;
117 
118 typedef struct _sry_datapacket
119 {
120     int32  len;
121     uint8 *data;
122 } sry_datapacket;
123 
124 extern WRDTracer *wrdt_list[], *wrdt;
125 extern int wrd_color_remap[/* 8 */];
126 extern int wrd_plane_remap[/* 8 */];
127 extern sry_datapacket *datapacket;
128 
129 extern int import_wrd_file(char *fn);
130 extern void wrd_init_path(void);
131 extern void wrd_add_path(char *path, int pathlen_opt);
132 extern void wrd_add_default_path(char *path);
133 extern struct timidity_file *wrd_open_file(char *filename);
134 
135 extern void wrd_midi_event(int cmd, int arg);
136 extern void wrd_sherry_event(int addr);
137 extern void *wrd_sherry_data;
138 
139 extern void sry_encode_bindata( char *code, const char *org, int len);
140 extern int sry_decode_bindata( char *data );
141 extern int wrd_read_sherry;
142 
143 extern void free_wrd(void);
144 
145 static inline void print_ecmd(char*, int*, int);
146 #ifdef HAVE_STRINGS_H
147 #include <strings.h>
148 #elif defined HAVE_STRING_H
149 #include <string.h>
150 #endif
151 #include <limits.h>
152 #include "mblock.h"
153 #include "common.h"
154 #include "controls.h"
155 
156 #ifdef __BORLANDC__
157 extern void pr_ecmd(char *cmd, int *args, int narg);
158 #define print_ecmd( a, b, c) pr_ecmd(a, b, c)
159 #else
print_ecmd(char * cmd,int * args,int narg)160 static inline void print_ecmd(char *cmd, int *args, int narg)
161 {
162     char *p;
163     size_t s = MIN_MBLOCK_SIZE;
164 
165     p = (char *)new_segment(&tmpbuffer, s);
166     snprintf(p, s, "^%s(", cmd);
167 
168     if(*args == WRD_NOARG)
169 	strncat(p, "*", s - strlen(p) - 1);
170     else {
171 	char c[CHAR_BIT*sizeof(int)];
172 	snprintf(c, sizeof(c)-1, "%d", args[0]);
173 	strncat(p, c, s - strlen(p) - 1);
174     }
175     args++;
176     narg--;
177     while(narg > 0)
178     {
179 	if(*args == WRD_NOARG)
180 	    strncat(p, ",*", s - strlen(p) - 1);
181 	else {
182 	    char c[CHAR_BIT*sizeof(int)]; /* should be enough loong */
183 	    snprintf(c, sizeof(c)-1, ",%d", args[0]);
184 	    strncat(p, c, s - strlen(p) - 1);
185 	}
186 	args++;
187 	narg--;
188     }
189     strncat(p, ")", s - strlen(p) - 1);
190     ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "%s", p);
191     reuse_mblock(&tmpbuffer);
192 }
193 #endif
194 
195 #endif /* ___WRD_H_ */
196